Scenario is: Tagging multiple hosts from my flat switch. I will lose connectivity to hosts until I plug in my startech device and assign the tag to it. when the script runs it pretty much just stalls after the 1st host. I have tried removing the discconect-viserver. /Any thoughts? see script below. Looking for something that acts like nohup sleep command. Also start-sleep is not what i need.
$file_hosts = "c:\ps\ip.csv"
#Login Variables
$auth_usr = "root"
$auth_pwd = "Youwillneverknow"
#variables - Management network
$pg_ManageNet = "Management Network"
#variables - CVM network
$Host_CVM_VLAN = 3
$New_NamePortGroupCVM = "CVM_MGNT"
$pg_CVM = "VM Network"
Import-csv $file_hosts | ForEach-Object {
$host_ntnx = $_.hostntnx
Connect-VIServer -Server $host_ntnx -User $auth_usr -Password $auth_pwd -Force
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue -Confirm: $false
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -Confirm: $false
Write-Host "******************************************************************"
Write-Host "******************************************************************"
Write-Host "connected to" $host_ntnx
Write-Host "******************************************************************"
Write-Host "******************************************************************"
Write-Host "Configuring CVM Portgroup for" $host_ntnx
#Setting vSwitch0 Variable
$VSwitch0 = Get-VirtualSwitch -VMHost $host_ntnx -Name "vSwitch0"
#rename/tag CVM port group
Write-Host "rename/tagging cvm portgroup"
$VSwitch0 = Get-VirtualSwitch -VMHost $host_ntnx -Name "vSwitch0"
$CVM_PortGroup_Config = Get-VirtualPortGroup -VMHost $host_ntnx -VirtualSwitch $VSwitch0 -Name $pg_CVM | Set-VirtualPortGroup -Name $New_NamePortGroupCVM -VlanId $Host_CVM_VLAN
if($?)
{
Write-Host "******************************************************************"
Write-Host "******************************************************************"
Write-Host "command succeeded"
Write-Host "******************************************************************"
Write-Host "******************************************************************"
}
else
{
Write-Host "******************************************************************"
Write-Host "******************************************************************"
Write-Host "command failed"
Write-Host "******************************************************************"
Write-Host "******************************************************************"
}
Write-Host "******************************************************************"
Write-Host "******************************************************************"
Write-Host "Configuring Host Portgroup for" $host_ntnx
#Tag Management Network
Write-Host "Tagging mgmt network"
$TAGnetwork = Get-VirtualPortGroup -VMHost $host_ntnx -VirtualSwitch $VSwitch0 -Name $pg_ManageNet | Set-VirtualPortGroup -VlanId $Host_CVM_VLAN
Write-Host "******************************************************************"
Write-Host "******************************************************************"
Write-Host "Finished DNS Config" $host_ntnx
Write-Host "******************************************************************"
Write-Host "******************************************************************"
Write-Host "Disconnecting from" $host_ntnx
Disconnect-VIServer -Server $host_ntnx -Confirm:$false
}