With the -RunAsync parameter, the Set-VMHost cmdlet will not pass a VMHost object to the pipeline but a TaskObject.
Leave out the RunAsync parameter
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Where do you populate the $allLines variable ?
Or should that be the $array variable ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
tried running this line manually and it works
Get-VMHost -Name hostname | Set-VMHost -State Disconnected -RunAsync | Remove-VMHost
luc,
yes thats the array variable
With the -RunAsync parameter, the Set-VMHost cmdlet will not pass a VMHost object to the pipeline but a TaskObject.
Leave out the RunAsync parameter
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes that was the problem. thanks luc
trying to change this into a function so I can reuse but not workling
hi any idea on this?
I am trying to make thi swa function but
looks like the array does not work if its not called from part of the function.
It works up to
I suspect you're hitting a scope problem here.
As a quick bypass, change $array to $script:array everywhere.
That way the scope of $array is for the complete script, also inside the function.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
luc,
it works! thanks but i just want to add one more thing. I added a second array $script:dnshosts to hold my dns names of my hosts so I can
readd them back into the cluster as actual dns names instead of ip addresses but it not working.
$VMHostProfile = Get-VMHostProfile -Entity * $Cluster = Get-Cluster -Name "cluster"
$script:array = @()
$script:dnshosts = @()
function apply-profile { Import-Csv "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\scripts\Autodeploy.csv" -UseCulture | %{ $additionalConfiguration = @{ 'network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-dvS-RW-TESTMGMT-dvPG-RW-MGMT-management"].ipConfig.IpAddressPolicy.address' = $_.mgmt_ip 'network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-dvS-RW-TESTMGMT-dvPG-RW-MGMT-management"].ipConfig.IpAddressPolicy.subnetmask' = $_.mgmt_sm 'network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-dvS-RW-TestVmotion-dvPG-RW-testvmotion-vmotion"].ipConfig.IpAddressPolicy.address' = $_.vmotion_ip 'network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-dvS-RW-TestVmotion-dvPG-RW-testvmotion-vmotion"].ipConfig.IpAddressPolicy.subnetmask' = $_.vmotion_sm 'network.dnsConfig.HostNamePolicy.hostName' = $_.Name }
Apply-VMHostProfile -ApplyOnly -Profile $VMHostProfile -Entity $_.dhcpip -Variable $additionalConfiguration -Confirm:$false -RunAsync
$script:array += $_.mgmt_ip
$script:dnshosts += $_.Name } } apply-profile Start-Sleep 60
Get-VMHost -Name $script:array | Set-VMHost -State Disconnected | Remove-VMHost -Confirm:$false
Start-Sleep 30
Add-VMHost -Name $script:dnshosts -Location $Cluster -User root -Password xxxxx -Confirm:$false -force -RunAsync
Start-Sleep 60
apply-profile
any idea why?
thank you
How does your CSV file look ?
Something like this
"Name","mgmt_ip","mgmt_sm","vmotion_ip","vmotion_sm"
"vm1","192.168.1.1","255.255.255.0","192.168.2.1","255.255.255.0"
"vm2","192.168.1.2","255.255.255.0","192.168.2.2","255.255.255.0"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes exactly. It also has a column called
dhcpip
Do you get any error messages ?
Is there anything in the array $script:dnshosts just before you call Get-VMHost ?
Btw I think the value on the Entity parameter for the Apply-VMHostProfile cmdlet might be wrong.
Shouldn't you be giving that 1 or more VMHost objects instead of the dhcpip value from the CSV ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference