PowerShell Script to Populate a vWorkspace Farm

Here’s a script I wrote to help setup a vWorkspace farm. I’m constantly rolling out new farms and having a script like this will probably save me a week of my live this year. I don’t have to click through the same wizards to create the same apps and assign them to the same users. The script adds my Hyper-V host and creates computer groups and syspreps for each operating system. Then it goes a head, adds the domain users group to my targets and publishes a set of three apps each computer group and target. This kind of setup would probably take me about an hour (give or take depending on my level of distraction). This gets it done in under 10 seconds.

function Create-Farm
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]    
        $HyperVHost,
        [Parameter()]
        $Credentials=(Get-Credential),
        [Parameter()]
        $LocalSysPrepCredentials=(Get-Credential),
        [Parameter()]
        $ComputerPrefix = "MDN",
        [Parameter()]
        $Windows7x64Template=$null,
        [Parameter()]
        $Windows7x86Template=$null,
        [Parameter()]
        $WindowsXPx64Template=$null,
        [Parameter()]
        $WindowsXPx86Template=$null,
        [Parameter()]
        $Windows2008R2Template=$null
        )
 
    Set-Location "AdamsFarm:"
 
    Connect-QVWFarm
 
    Add-QVWHyperVHost -Name $HyperVHost -Location Location1 -Credential $Credentials
 
    #Create the computer groups
    New-QVWComputerGroup -Name "Windows 7 x86" -AdminCredential $Credentials -SystemType HypervHost -GroupMode Traditional -Location Location1
    New-QVWComputerGroup -Name "Windows XP x86" -AdminCredential $Credentials -SystemType HypervHost -GroupMode Traditional -Location Location1
 
    New-QVWComputerGroup -Name "Windows 7 x64" -AdminCredential $Credentials -SystemType HypervHost -GroupMode Traditional -Location Location1
    New-QVWComputerGroup -Name "Windows 2008R2" -AdminCredential $Credentials -SystemType HypervHost -GroupMode Traditional -Location Location1
    New-QVWComputerGroup -Name "Windows XP x64" -AdminCredential $Credentials -SystemType HypervHost -GroupMode Traditional -Location Location1
 
    #Import all Hyper-V templates
    Import-QVWComputerTemplate -HyperVHost $HyperVHost | Add-QVWComputerTemplate -Location Location1 -ComputerGroup "Windows 7 x86"
 
    #Create all the syspreps
    New-QVWSysPrep -Name "Windows 2008R2" -AdminCredential $LocalSysPrepCredentials -Domain "mdnvdi.local" -DomainCredential $Credentials `
             -ExecutionMode Instant -OperatingSystem Server2008 -ProcessorArchitecture x86 -ProductKey "Get your own! :D" 
    New-QVWSysPrep -Name "Windows 7 x86" -LocalAccountCredential $LocalSysPrepCredentials -Domain "mdnvdi.local" -DomainCredential $Credentials `
             -ExecutionMode Instant -OperatingSystem VistaWin7 -ProcessorArchitecture x86 -ProductKey "Get your own! :D" 
    New-QVWSysPrep -Name "Windows XP x86" -AdminCredential $LocalSysPrepCredentials -Domain "mdnvdi.local" -DomainCredential $Credentials `
             -ExecutionMode Instant -OperatingSystem XPPro  -ProductKey "Get your own! :D" -ConcurrentConnections 5
 
    New-QVWSysPrep -Name "Windows 7 x64" -LocalAccountCredential $LocalSysPrepCredentials -Domain "mdnvdi.local" -DomainCredential $Credentials `
             -ExecutionMode Instant -OperatingSystem VistaWin7 -ProcessorArchitecture x64 -ProductKey "Get your own! :D" 
    New-QVWSysPrep -Name "Windows XP x64" -AdminCredential $LocalSysPrepCredentials -Domain "mdnvdi.local" -DomainCredential $Credentials `
             -ExecutionMode Instant -OperatingSystem XPPro -ProductKey "Get your own! :D" -ConcurrentConnections 5
 
    #Create a new client
    Add-QVWTarget -Group "mdnvdi\Domain Users"
 
    #Create a desktop app
    foreach($cg in (Get-QVWComputerGroup))
    {
        New-QVWManagedApplication -ComputerGroup $cg -Name "$($cg.Name) Desktop"
    }
 
    #Create a notepad app
    foreach($cg in (Get-QVWComputerGroup))
    {
        New-QVWManagedApplication -ComputerGroup $cg -Name "$($cg.Name) Notepad" -Path "C:\windows\system32\notepad.exe" `
              -SeamlessWindowMode vWorkspace
    }
 
    #Create a ie app
    foreach($cg in (Get-QVWComputerGroup))
    {
        New-QVWManagedApplication -ComputerGroup $cg -Name "$($cg.Name) IE" -Path 'C:\program files (x86)\Internet Explorer\iexplore.exe' `
              -SeamlessWindowMode vWorkspace
    }
 
    foreach($app in (Get-QVWManagedApplication))
    {
        foreach($user in (Get-QVWtarget))
        {
             Publish-QVWResource -Resource $app -Folder "My Applications" -Client $user
        }
    }
 
    $NC = New-QVWNamingConventions -BaseName ($ComputerPrefix + "764??") -StartValue 0 -Increment 1
    Set-QVWProvisioningSettings -ComputerGroup "Windows 7 x64" -CloneMethod HyperVDifferencingDisk `
         -SysPrepCustomizations "Windows 7 x64" -NamingConventions $NC
 
    $NC = New-QVWNamingConventions -BaseName ($ComputerPrefix + "XP64??") -StartValue 0 -Increment 1
    Set-QVWProvisioningSettings -ComputerGroup "Windows XP x64" -CloneMethod HyperVDifferencingDisk `
         -SysPrepCustomizations "Windows XP x64" -NamingConventions $NC
 
    $NC = New-QVWNamingConventions -BaseName ($ComputerPrefix + "2K8R2??") -StartValue 0 -Increment 1
    Set-QVWProvisioningSettings -ComputerGroup "Windows 2008R2" -CloneMethod HyperVDifferencingDisk `
         -SysPrepCustomizations "Windows 2008R2" -NamingConventions $NC
 
    $NC = New-QVWNamingConventions -BaseName ($ComputerPrefix + "786??") -StartValue 0 -Increment 1
    Set-QVWProvisioningSettings -ComputerGroup "Windows 7 x86" -CloneMethod HyperVDifferencingDisk `
         -SysPrepCustomizations "Windows 7 x86" -NamingConventions $NC
 
    $NC = New-QVWNamingConventions -BaseName ($ComputerPrefix + "XP86??") -StartValue 0 -Increment 1
    Set-QVWProvisioningSettings -ComputerGroup "Windows XP x86" -CloneMethod HyperVDifferencingDisk `
        -SysPrepCustomizations "Windows XP x86" -NamingConventions $NC
}

Easy as that!

You can leave a response, or trackback from your own site.

7 Responses to “PowerShell Script to Populate a vWorkspace Farm”

  1. Eddie says:

    You might want to mask the Product Keys in this post.

  2. [...] PowerShell Script to Populate a vWorkspace Farm by Adam Driscoll [...]

Leave a Reply


8 × two =

Subscribe to RSS Feed Follow me on Twitter!