I again check my VMs name files.txt and correct the duplicate Again I try your last scrip And see this error PowerCLI C:\> $vihosts= Get-Content "c:\hosts.txt" Power...
See more...
I again check my VMs name files.txt and correct the duplicate Again I try your last scrip And see this error PowerCLI C:\> $vihosts= Get-Content "c:\hosts.txt" PowerCLI C:\> PowerCLI C:\> PowerCLI C:\> PowerCLI C:\> foreach ($singleViserver in $vihosts){ >> >> Connect-VIServer $singleViserver -User root -Password mypass >> >> >> >> # Read order from file (<hostname>.txt) >> >> $order = 1 >> >> $vmTab = @{} >> >> Get-Content "C:\$($singleViserver).txt" | %{ >> >> Write-Host "Looking at VM $($_), will have order# $($order)" >> >> $vm = Get-VM -Name $_ -ErrorAction SilentlyContinue >> >> if($vm){ >> >> Write-Host "Found $($vm.Name)" >> >> $vmTab.Add($vm.ExtensionData.MoRef,$order) >> >> $order++ >> >> } >> >> } >> >> >> >> $esx = Get-VMHost -Name $singleViserver >> >> >> >> $autoMgr = Get-view $esx.ExtensionData.ConfigManager.AutoStartManager >> >> >> >> $spec = New-Object VMware.Vim.HostAutoStartManagerConfig >> >> $spec.Defaults = New-Object VMware.Vim.AutoStartDefaults >> >> $spec.Defaults.enabled = $true >> >> $spec.Defaults.startDelay = 30 >> >> $spec.Defaults.stopAction = 'GuestShutdown' >> >> $spec.Defaults.stopDelay = 30 >> >> $spec.Defaults.waitForHeartbeat = 'yes' >> >> >> >> $esx.ExtensionData.Vm | %{ >> >> if($vmTab.ContainsKey($_)){ >> >> $vmSpec = New-Object VMware.Vim.AutoStartPowerInfo >> >> $vmSpec.Key = $_ >> >> $vmSpec.startAction = 'powerON' >> >> $vmSpec.startDelay = -1 >> >> $vmSpec.startOrder = $vmTab[$_] >> >> $vmSpec.stopAction = 'GuestShutdown' >> >> $vmSpec.stopDelay = 30 >> >> $vmSpec.waitForHeartbeat = 'yes' >> >> >> >> $spec.powerInfo += $vmSpec >> >> } >> >> } >> >> >> >> $autoMgr.ReconfigureAutostart($spec) >> >> >> >> Disconnect-VIServer -Confirm:$False >> >> } >> Name Port User ---- ---- ---- esx1.shmalayer.org 443 root Looking at VM ShobAD2012.ShMalayer.org, will have order# 1 Found ShobAD2012.ShMalayer.org Looking at VM Shobdb.Shmalayer.org, will have order# 2 Found Shobdb.Shmalayer.org Looking at VM ShobDB2.ShMalayer.org, will have order# 3 Found ShobDB2.ShMalayer.org Looking at VM ShobAPP.ShMalayer.org, will have order# 4 Found ShobAPP.ShMalayer.org Looking at VM ShobFS.ShMalayer.org, will have order# 5 Found ShobFS.ShMalayer.org Looking at VM ShobTiba.ShMalayer.org, will have order# 6 Found ShobTiba.ShMalayer.org Looking at VM ShobWSUS.ShMalayer.org, will have order# 7 Found ShobWSUS.ShMalayer.org Looking at VM Firewall.ShMalayer.org, will have order# 8 Found Firewall.ShMalayer.org Exception calling "ReconfigureAutostart" with "1" argument(s): "A specified parameter was not correct: vim.host.AutoStartManager.AutoPowerInfo.startOrder" At line:37 char:5 + $autoMgr.ReconfigureAutostart($spec) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : VimException esx1.shlalajin.org 443 root Looking at VM ShobAD2012.ShLalajin.org, will have order# 1 Found ShobAD2012.ShLalajin.org Looking at VM ShobDB.ShLalajin.org, will have order# 2 Found ShobDB.ShLalajin.Org Looking at VM ShobDB2.ShLalajin.org, will have order# 3 Found ShobDB2.ShLalajin.org Looking at VM ShobAPP.ShLalajin.org, will have order# 4 Found ShobAPP.ShLalajin.org Looking at VM ShobTiba.ShLalajin.org, will have order# 5 Found ShobTiba.ShLalajin.org Looking at VM ShobWSUS.ShLalajin.org, will have order# 6 Found ShobWSUS.ShLalajin.org Looking at VM Firewall.ShLalajin.org, will have order# 7 Found Firewall.ShLalajin.org Exception calling "ReconfigureAutostart" with "1" argument(s): "A specified parameter was not correct: vim.host.AutoStartManager.AutoPowerInfo.startOrder" At line:37 char:5 + $autoMgr.ReconfigureAutostart($spec) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : VimException esx1.shnahavand.org 443 root Looking at VM shobAD2012.ShNahavand.org, will have order# 1 Found ShobAD2012.ShNahavand.org Looking at VM ShobDB.shNahavand.Org, will have order# 2 Found ShobDB.ShNahavand.Org Looking at VM ShobDB2.ShNahavand.Org, will have order# 3 Found ShobDB2.ShNahavand.Org Looking at VM Shobapp.ShNahavand.Org, will have order# 4 Found ShobAPP.ShNahavand.Org Looking at VM Shobtiba.ShNahavand.org, will have order# 5 Found ShobTiba.ShNahavand.org Looking at VM ShobwSuS.ShNahavand.org, will have order# 6 Found ShobWSUS.ShNahavand.org Looking at VM firewall.ShNahavand.Org, will have order# 7 Found Firewall.ShNahavand.Org Exception calling "ReconfigureAutostart" with "1" argument(s): "A specified parameter was not correct: vim.host.AutoStartManager.AutoPowerInfo.startOrder" At line:37 char:5 + $autoMgr.ReconfigureAutostart($spec) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : VimException esx1.edkolhamedan.org 443 root Looking at VM EDKolAD2012.EDHamedan.org, will have order# 1 Found EDKolAD2012.EDHamedan.org Looking at VM EDKolDb.EdHamedan.org, will have order# 2 Found EDKolDb.EdHamedan.org Looking at VM EDKolApp.EDHamedan.org, will have order# 3 Found EDKolApp.EDHamedan.org Looking at VM EDFS.EdKolHamedan.org, will have order# 4 Found EDFS.EdKolHamedan.org Looking at VM EDKolDB2.EDHamedan.org, will have order# 5 Found EDKolDB2.EDHamedan.org Looking at VM EDKolWSUS.EDHamedan.org, will have order# 6 Found EDKolWSUS.EDHamedan.org Looking at VM Firewall.EdHamedan.org, will have order# 7 Found Firewall.EdHamedan.org Looking at VM WHDB.EdKolHamedan.Org, will have order# 8 Found WHDB.EdKolHamedan.Org Exception calling "ReconfigureAutostart" with "1" argument(s): "A specified parameter was not correct: vim.host.AutoStartManager.AutoPowerInfo.startOrder" At line:37 char:5 + $autoMgr.ReconfigureAutostart($spec) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : VimException PowerCLI C:\> PowerCLI C:\>