Reputation: 1
I have a working powercli script to re-register vcenter server with nsx manager. Because of my limited/poor knowledge with powercli I am not able to scale this up. I want the script to connect to multiple vcenters and nsx managers at the same time and complete this. Any help is appreciated!
$NSX_IP = "nsx1.com"
$NSX_Username = "admin"
$NSX_Password = "password"
$VC_IP = "vc1.com"
$VC_Username = "[email protected]"
$VC_Password = "password"
Write-host "Connecting to NSX Manager and registering it to vCenter..." -foreground "magenta"
# Connect to vCenter first
if(!(Connect-VIServer -Server $VC_IP -User $VC_Username -Password $VC_Password)) {
#write-host "Connect-VIServer -Server" + $VC_IP + "-User" + $VC_Username + "-Password" + $VC_Password
write-host "Not able to connect to the vCenter" -foreground "red"
Exit
}
else {
write-host "Connect to vCenter!" -foreground "Cyan"
}
#Connect to NSX Manager
if(!(Connect-NSXServer -Server $NSX_IP -UserName $NSX_Username -Password $NSX_Password)) {
write-host "Not Connected to NSX Manage,r" -foreground "red"
Exit
}
else{
write-host "Connected to NSX Manager" -foreground "Cyan"
}
# Configure vCenter connection on NSX Manager
if(!(Set-NSXManager -vCenterServer $VC_IP -vCenterUserName $VC_Username -vCenterPassword $VC_Password))
{
write-host "vCenter registered with NSXManager" -foreground "Cyan"
}
Upvotes: 0
Views: 285
Reputation: 1983
Put the whole thing in a foreach loop after importing a csv with the constants to do this sequentially. To do them simultaneously, maybe use psremoting with Invoke-Command, specifying multiple targets with -comp (auth could be tricky depending on your environment). Or check out get-help about_jobs, more robust but more to learn.
Upvotes: 0