Friday, October 4, 2013

Scripted installation of the SCVMM Console

This actually seems like it would be pretty straightforward.  However, a documentation bug leaving out a critical switch leaves you guessing.

The following runs on a VM where the the SCVMM ISO is attached.  Nothing more needs to be done beyond attaching the ISO to the VM and executing the script.  This is essentially totally hands-off.

The thing you will probably want to pay attention to are the command line switches for the Console installer.

# CD-ROM selects anything in the DVD drive.  The size ensures that something is mounted.
$dvdDrives = Get-Volume | where {$_.DriveType -eq "CD-ROM" -and $_.Size -gt 0}
# Since a VM could have more than one DVD drive, and SCVMM might be using one for its own purposes we need to find the correct one.
foreach ($dvd in $dvdDrives){
    #test for the sample INI file in the right location to ensure this is the VMM media.
    Switch ([System.IntPtr]::Size)
    {
        4 {
            If (Test-Path -Path ($dvd.DriveLetter + ":\i386\") -PathType Container){
                $vmmMedia = Get-ChildItem -Path ($dvd.DriveLetter + ":\i386\Setup\") -recurse -Filter "VMClient.ini"
            }
        }
        8 {
            If (Test-Path -Path ($dvd.DriveLetter + ":\amd64\") -PathType Container){
                $vmmMedia = Get-ChildItem -Path ($dvd.DriveLetter + ":\amd64\Setup\") -recurse -Filter "VMClient.ini"
            }    
        }
    }
    If ($vmmMedia -ne $null){
        If (Test-Path $vmmMedia.FullName){
            $FilePath = (Get-ChildItem -Path $vmmMedia.PSDrive.Root -Filter "Setup.exe").FullName
        }
    }
}
if ($FilePath) {
    try {
        "Starting SCVMM Console installation."
        Get-Date -Format HH:mm:ss
        Start-Process -FilePath $FilePath -ArgumentList "/client /i /IACCEPTSCEULA" -Wait -NoNewWindow
        "Done waiting for the installer"
        Get-Date -Format HH:mm:ss
        Start-sleep 30
        "SCVMM Console installed."
        Get-Date -Format HH:mm:ss
    }
    catch {
        $Error |  Out-File $logFile -Append
    }
}
else{ Write-Error -Category ObjectNotFound -Message "The SCVMM Installation media was not detected." -RecommendedAction "Please manually install the SCVMM Console" }

No comments: