DSCResources/POSHOrigin_vSphere_VM/Helpers/_GetGuestOS.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function _GetGuestOS{
    [cmdletbinding()]
    param(
        # [Parameter(Mandatory)]
        # [ValidateNotNull()]
        # $vm,

        # [Parameter(Mandatory)]
        # [pscredential]$Credential

        [Parameter(Mandatory)]
        [Microsoft.Management.Infrastructure.CimSession]$CimSession
    )

    #Get guest operating system version
    try {
        #$ip = _GetGuestVMIPAddress -VM $vm

        Write-Debug 'Quering system for OS version'
        #if ($ip) {
            #$opt = New-CimSessionOption -Protocol DCOM
            #$cim = New-CimSession -ComputerName $ip -Credential $Credential -SessionOption $opt -Verbose:$false
            $os = (Get-CimInstance -ClassName Win32_OperatingSystem -CimSession $CimSession -Verbose:$false).Version
            $os = $os.Split('.')
            $os = ($os[0] + $os[1]).ToInt32($Null)
            #Remove-CimSession -CimSession $cim -ErrorAction SilentlyContinue
            return $os
        #} else {
        # Write-Error -Message 'Error querying for OS version'
        #}
    } catch {
        Remove-CimSession -CimSession $cim -ErrorAction SilentlyContinue
        Write-Error -Message 'There was a problem querying for the system OS version'
        Write-Error -Message "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)"
        write-Error -Exception $_
    }
}