PowerShell使用Get-WSManInstance查询ESXi主机硬件信息的方法
发表于 : 2015年 5月 28日 21:00 星期四
WS-MAN is a management standard developed by the DTMF. it provides the ability to access and manipulate CIM providers via HTTP calls.
代码: 全选
$user = "root"
$password = "<plaintext_password>"
$host = "hostname.example.com"
#密码转换
$securepwd = ConvertTo-SecureString $password -AsPlainText -Force
#$creds = new-object System.Management.Automation.PSCredential ($user, $pass)
#生成cred
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$securepwd
#$report = Get-WSManInstance 'cimv2/root/dcim/CIM_SoftwareIdentity' -Enumerate -ConnectionURI https://$host/wsman -SessionOption (New-WSManSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck) -Authentication basic -Credential $cred
#使用Get-WSManInstance获取信息
$report = Get-WSManInstance 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/CIM_SoftwareIdentity' -Enumerate -ConnectionURI https://$host/wsman -SessionOption (New-WSManSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck) -Authentication basic -Credential $cred
#取得细节
$iloinfo = $report| Where {$_.Name -eq "Baseboard Management Controller"}
$biosinfo = $report| Where {$_.Name -eq "System BIOS"}
$iLOFirmwareVersion = $iloinfo.VersionString
$BIOSVersion = $biosinfo.VersionString
$BIOSReleaseDate = ($biosinfo.ReleaseDate).substring(0,8)