Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Passing parameters to Invoke-VMScript (variables) PowerCli

$
0
0

I am trying to use Invoke-VMScript to set new IP's on a list of servers.  The only access that I have to these servers is through vCenter console, so I thought this would be easier, faster, and less prone to errors. The problem is that I have to determine which nic to change the IP's on, based on the current IP, and I need to pass the new IP's into the Invoke-VMScript because they are going to be different for every server on the list. 

Invoke-VMScript -vm $vmname -guestUser 'dom\me\ -guestpassword '@ttt1234' -scripttype powershell -scripttext {

     $adapters = Get-wmiObjet win32_networkadapterconfiguration

     foreach ( $adapter in $adapters ) {

          if ($adpaters.ipaddress -match "$cIpaddress" ) {

               $adapter.EnableStatic("$nIPaddress", "$nSubnet")

               $adapter.SetGateways("$nGateway",1)

               $adapter.SetDNSSErversearchorder($aDNS)

          }#end if

}#end fe

}#end scriptblock

obviously all of these variable are populated earlier in the script, but they are not making it into the VM. 


I seem to need a way to populate the variable into a text, then put the text into the -scripttext. 

I thougth of writing it to a temp file  and then using get-content to bring it all back as a string and placing it in -scripttext. 

Any good ideas?


Viewing all articles
Browse latest Browse all 6937

Trending Articles