VMware View Cmdlets and PowerShell Implicit Remoting

One of the differences between the VMware View cmdlets and PowerCLI is that the View cmdlets can only be run on the connection server itself. Despite the lack of a Connect-VIServer equivalent, with PowerShell Implicit Remoting it’s still possible to use these cmdlets from a workstation.

First, PowerShell Remoting needs to be enabled on the Connection Server. There are several ways to configure remoting, but in a domain environment I like to turn it on with group policy. Enabling the automatic configuration of listeners is usually all the configuration necessary to enable remoting on a domain server, but lots of information is available for different situations. The about_remote_troubleshooting help file is handy, and there are books specific to remoting on my list of free PowerShell ebooks.

Group Policy Setting for "Allow Automatic Configuration of Listeners"

$session = New-PSSession -ComputerName "NameOfConnectionServer"

With remoting enabled, a session is opened to the connection server from a workstation. A session is a persistent connection that can be referenced when using subsequent remoting commands.

Invoke-Command -Session $session -ScriptBlock {Add-PSSnapin VMware*}

The VMware cmdlets aren’t loaded by default, so Invoke-Command is used to tell the PowerShell session on the remote server to load the VMware snapin.

Import-PSSession -Session $session -Prefix VDI -Module VMware*

The cmdlets are loaded in the server’s PowerShell session, but they must be imported in order to run them on the local workstation. The module parameter specifies to only import cmdlets from the VMware module, and the prefix parameter will prefix the noun in each cmdlet with “VDI” to avoid possible conflicts with local cmdlets. A cmdlet named Get-DesktopVM will become Get-VDIDesktopVM.

With the View cmdlets imported from the remote session, those commands can now be executed as if they were installed locally. PowerShell is doing all the work behind the scenes to implicitly run the commands on the remote server and return the results to the local workstation.

Using PowerShell Implicit Remoting to use VMware View Cmdlets

Remove-PSSession $session

The session to the connection server must remain open for the View cmdlets to be available. When finished working, removing the session closes it out and will unload the commands.

Sessions from the 2012 Orlando IT Pro Camp

Thank you to everyone that attended the Orlando IT Pro Camp. It was a great opportunity to learn and network with other IT Professionals. Here are the slides and resources from my sessions.

Introduction to PowerShell Remoting

Title Slide for Introduction to PowerShell RemotingSlide deck for Introduction to PowerShell Remoting


Cover image of the Layman's Guide to PowerShell RemotingLayman’s Guide to PowerShell 2.0 Remoting
Ravikanth Chaganti


Cover image for Administrator's Guide to Windows PowerShell RemotingAdministrator’s Guide to Windows PowerShell Remoting
Dr. Tobias Weltner
Aleksandar Nikolic
Richard Giles


Cover of Windows PowerShell in Action by Bruce PayetteWindows PowerShell in Action, Second Edition
Bruce Payette


Version Control for IT Professionals

Version Control for IT ProfessionalsSlide deck for Version Control for IT Professionals


Hg Init a Mercurial TutorialHg Init: A Mercurial Tutorial
Mercurial is a modern, open source, distributed version control system, and a compelling upgrade from older systems like Subversion. In this user-friendly, six-part tutorial, Joel Spolsky teaches you the key concepts.


TortoiseHg LogoTortoiseHg
TortoiseHg is a Windows shell extension and a series of applications for the Mercurial distributed revision control system.


Mercurial LogoMercurial
Mercurial is a free, distributed source control management tool. It efficiently handles projects of any size and offers an easy and intuitive interface.


Kiln LogoKiln
Kiln is commercial Mercurial version control and code review softare from Fog Creek Software.


Switching Between PowerShell Prompts with Set-Prompt

I’m usually pretty happy with the default PowerShell prompt that displays the current path, however sometimes I just want a generic prompt for screenshots or a demonstration. With an infinite number of custom PowerShell prompts possible, it became apparent that the appropriate prompt depends on the current task. By copying the Set-Prompt function into $Env:UserProfile\Documents\WindowsPowerShell\profile.ps1, I have an easy way to quickly switch between these different prompts and I only need to edit my profile when I want to add a new prompt.

If I see a neat custom prompt like a Domain Controller PowerShell Prompt or a Christmas Prompt, I just add an additional switch block to Set-Prompt.

Screenshot of the Set-Prompt function in use

Set-Prompt.zip

Function Set-Prompt
{
    Param
    (
        [Parameter(Position=0)]
        [ValidateSet("Default","Basic","DC","Xmas")]
        $Action
    )

    switch ($Action)
    {
        "Basic"
        {
            Function global:prompt
            {
                $Null
            }
        }

        "DC"
        {
            function global:prompt {

            #check and see if logon server is the same as the computername
            if ( $env:logonserver -ne "\\$env:computername" ) {
            #strip off the \\
            $label = ($env:logonserver).Substring(2)
            $color = "Green"
            }
            else {
            $label = "Not Connected"
            $color = "gray"
            }

            Write-Host ("[$label]") -ForegroundColor $color -NoNewline
            Write (" PS " + (Get-Location) + "> ")
            }
        }

        "Xmas"
        {
            Function global:Prompt {
            $time=([datetime]'12/25/2012'-(get-date)).ToString().Substring(0,11)
            $text="[**Christmas in $($time)**]"
            $text.tocharArray() |foreach {
            if ((Get-Random -min 1 -max 10) -gt 5) {
             $color="RED"
             }
            else {
             $color="GREEN"
            }
            write-host $_ -nonewline -foregroundcolor $color
            }
            Write (" PS " + (Get-Location) + "> ")
            } #end function
        }

        default
        {
            Function global:prompt
            {
                  $(if (test-path variable:/PSDebugContext) { '[DBG]: ' }
                  else { '' }) + 'PS ' + $(Get-Location) `
                  + $(if ($nestedpromptlevel -ge 1) { '>>' }) + '> '
            }
        }
    }
}

Enable RSAT Features with PowerShell and Dism

Checking boxes gets old quickly, and I’ve installed and checked those little boxes for the Remote Server Administration Tools (RSAT) on Windows 7 enough times for it to be annoying. I just wanted a static script with the names of the features to enable, but Xenophane’s Blog has some examples of extracting the output of the /Get-Features switch to dynamically generate the command to enable everything in RSAT.

Enable-RSATFeatures.zip

dism /Online /Enable-Feature `
/FeatureName:RemoteServerAdministrationTools `
/FeatureName:RemoteServerAdministrationTools-ServerManager `
/FeatureName:RemoteServerAdministrationTools-Roles `
/FeatureName:RemoteServerAdministrationTools-Roles-CertificateServices `
/FeatureName:RemoteServerAdministrationTools-Roles-CertificateServices-CA `
/FeatureName:RemoteServerAdministrationTools-Roles-CertificateServices-OnlineResponder `
/FeatureName:RemoteServerAdministrationTools-Roles-AD `
/FeatureName:RemoteServerAdministrationTools-Roles-AD-DS `
/FeatureName:RemoteServerAdministrationTools-Roles-AD-DS-SnapIns `
/FeatureName:RemoteServerAdministrationTools-Roles-AD-DS-AdministrativeCenter `
/FeatureName:RemoteServerAdministrationTools-Roles-AD-DS-NIS `
/FeatureName:RemoteServerAdministrationTools-Roles-AD-LDS `
/FeatureName:RemoteServerAdministrationTools-Roles-AD-Powershell `
/FeatureName:RemoteServerAdministrationTools-Roles-DHCP `
/FeatureName:RemoteServerAdministrationTools-Roles-DNS `
/FeatureName:RemoteServerAdministrationTools-Roles-FileServices `
/FeatureName:RemoteServerAdministrationTools-Roles-FileServices-Dfs `
/FeatureName:RemoteServerAdministrationTools-Roles-FileServices-Fsrm `
/FeatureName:RemoteServerAdministrationTools-Roles-FileServices-StorageMgmt `
/FeatureName:RemoteServerAdministrationTools-Roles-HyperV `
/FeatureName:RemoteServerAdministrationTools-Roles-RDS `
/FeatureName:RemoteServerAdministrationTools-Features `
/FeatureName:RemoteServerAdministrationTools-Features-BitLocker `
/FeatureName:RemoteServerAdministrationTools-Features-Clustering `
/FeatureName:RemoteServerAdministrationTools-Features-GP `
/FeatureName:RemoteServerAdministrationTools-Features-LoadBalancing `
/FeatureName:RemoteServerAdministrationTools-Features-StorageExplorer `
/FeatureName:RemoteServerAdministrationTools-Features-StorageManager `
/FeatureName:RemoteServerAdministrationTools-Features-Wsrm

Orlando IT Pro Camp Sessions

I will be presenting two sessions at the Orlando IT Pro Camp on January 21st. IT Pro Camp is a free, one-day learning event for IT Professionals. There will be a wide range of topics presented by speakers of all backgrounds and experience. I highly recommend stopping by if you’re in the Orlando area that Saturday.

Orlando IT Pro Camp

Introduction to PowerShell Remoting
Session Level: Intermediate
The release of PowerShell version 2 introduced a new technology for managing Windows computers remotely. Everyone from desktop support to enterprise administrators can benefit from the capabilities available with PowerShell Remoting. Learn how it works, what it can do and why you want it enabled in your environment.

Version Control for IT Professionals
Session Level: Intermediate
Version control, revision control and source control are terms used to describe the practice of tracking and controlling changes to files. Version control is critical to software developers for keeping track of source code changes, so why is it rarely used by IT Professionals that maintain production scripts? Learn about the benefits of version control and see a demo of TortoiseHg, a Windows shell extension for the Mercurial source control management tool.