Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 193643

Re: Create variable inside here-string - powershell

$
0
0

Hi LucD. Thank you much for the suggestions. I indeed missed the link provided by you and only saw yezdi reply. My bad.

 

Now its working fine without any issues.

However, now i started getting access denied error for the invoke-script

 

 

$Gpassword = '123456' | ConvertTo-SecureString -asPlainText -Force

$Gusername = '.\luser'

$GS = New-Object System.Management.Automation.PSCredential($Gusername,$Gpassword)

 

 

$metadata = @'

 

`$Interface = Get-NetIPAddress | where-object IPAddress -EQ $Oip | select -ExpandProperty interfacealias

write-host [`$Interface]

Remove-NetRoute -InterfaceAlias `$interface -confirm:`$false

Remove-NetIPAddress -InterfaceAlias `$interface -confirm:`$false

New-NetIPAddress -InterfaceAlias `$interface -IPAddress $Ip -AddressFamily IPv4 -PrefixLength 24 -DefaultGateway $gataeway -confirm:`$false

'@

 

 

foreach ($data in $Boot)

 

{

 

$VM = $data.'Vm name'

$Oip = $data.OldAddress

$Ip = $data.IPAddress

$subnet = $data.SubnetMask

$gataeway = $data.Gateway

 

 

$scripttext = $ExecutionContext.InvokeCommand.ExpandString($metadata)

   

Invoke-VMScript -VM $VM -ScriptType Powershell -ScriptText $scripttext -GuestCredential $GS

 

}

 

the account which i am using is a local administrator account (part of local admin group). any suggestions ? is it due to UAC or Runas.


Viewing all articles
Browse latest Browse all 193643


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>