Hi. I'm a newbie with powershell.
I use powerGUI. I connect successfully to virtual center. I have a VC 2.5 and ESX 3.5.
If I use the get-vmhost command, I have a result. But when I try to have a property with the VI API, the value of my variable is always NULL.
For example, my code :
$ConnexionVC = "d:\PS_scripts\CSV_Files\Connect_VC.txt" #
$temp_a = Get-Content $ConnexionVC
$VCServer = $temp_a[0]
$VCLogin = $temp_a[1]
$VCPassword = $temp_a[2]
$VCPort = $temp_a[3]
$VCProtocol = $temp_a[4]
Get-VIServer -Server $VCServer -Protocol $VCProtocol -Port $VCPort -User $VCLogin -Password $VCPassword
$HS = Find-EntityView -ViewType "HostSystem"
$dtsystem = $HS.ConfigManager.DateTimeSystem
$dtsystem value is NULL and I have an error in my script. I try with others objects in VI API (network, storage, etc) and I have the same problem.
Could someone help me please?
An alternative method to get what you seem to want is to use the Get-View cmdlet.
Take care that some of the properties you retrieve via the SDK are Managed Object references and you will have to do a Get-View on these to get at the actual content.
Also note that the VI Toolkit uses it's own objects (mostly with the suffix Impl at the end of the name). The object returned by the Get-VMHost cmdlet is such a VI Toolkit object.
After the Get-VIServer you can do something like this
$hsImpl = Get-VMHost -Name <name-of-your-ESX-host> $hs = Get-View $hsImpl.ID $dtsystemMoRef = $hs.ConfigManager.DateTimeSystem $dtsystem = Get-View $dtsystemMoRef
You can also do this for all your ESX hosts in one go.
The following sample lists the NTP server(s) for all your ESX hosts
Get-VMHost | %{Get-View $_.ID} | %{Get-View $_.ConfigManager.DateTimeSystem} | % {Write-Host $_.DateTimeInfo.NtpConfig.Server}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
An alternative method to get what you seem to want is to use the Get-View cmdlet.
Take care that some of the properties you retrieve via the SDK are Managed Object references and you will have to do a Get-View on these to get at the actual content.
Also note that the VI Toolkit uses it's own objects (mostly with the suffix Impl at the end of the name). The object returned by the Get-VMHost cmdlet is such a VI Toolkit object.
After the Get-VIServer you can do something like this
$hsImpl = Get-VMHost -Name <name-of-your-ESX-host> $hs = Get-View $hsImpl.ID $dtsystemMoRef = $hs.ConfigManager.DateTimeSystem $dtsystem = Get-View $dtsystemMoRef
You can also do this for all your ESX hosts in one go.
The following sample lists the NTP server(s) for all your ESX hosts
Get-VMHost | %{Get-View $_.ID} | %{Get-View $_.ConfigManager.DateTimeSystem} | % {Write-Host $_.DateTimeInfo.NtpConfig.Server}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It's works. Thanks a lot for your answer.