I'm trying to run this:
$VM = "VM1"
$IPType = 'IPv4'
$IP = '10.10.10.55'
$MaskBits = 24
$Gateway = '10.10.10.1'
$DNSPrimary = '10.10.10.1'
$DNSSecondary = '10.10.10.2'
$adapterscript = "$GetAdapter = Get-NetAdapter;
$SetAdapter = $GetAdapter | New-NetIPAddress -AddressFamily $IPType -IPAddress $IP -PrefixLength $MaskBits -DefaultGateway $Gateway;
$GetAdapter | Set-DnsClientServerAddress -ServerAddresses $DNSPrimary"
Write-Verbose -Message "Getting ready to change IP on VM $VM." -Verbose
Invoke-VMScript -ScriptText $adapterscript -ScriptType Powershell -VM $VM -GuestCredential $LocalCredential
but getting error:
ScriptOutput
---------------------------------------------------------------------------------------------------------------------------------------------------------------
| = : The term '=' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
| spelling of the name, or if a path was included, verify that the path is correct and try again.
| At line:1 char:5
| + & { = Get-NetAdapter;
| + ~
| + CategoryInfo : ObjectNotFound: (=:String) [], CommandNotFoundException
| + FullyQualifiedErrorId : CommandNotFoundException
|
I have tried to wrap the @adapterscript in singe ' and double " but same issue.