Any ida how to change the IP, DG, on a VMguest, with invoke-vmguest ?
the IP got changed and now unable to login and need to change it back
You could try something like this.
It assumes there is only 1 network connection defined inside the Guest OS, and that the connection is named 'Local Area Connection'
$vmName = 'MyVM'
$ip = '10.1.1.1'
$user = 'domain\user'
$pswdTxt = 'password'
$vm = Get-VM -Name $vmName
$pswd = ConvertTo-SecureString -String $pswdTxt -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($user, $pswd)
$code = @'
netsh interface ip set address "Local Area Connection" static $ip
'@
$sInvoke = @{
VM = $vm
GuestCredential = $cred
ScriptText = $ExecutionContext.InvokeCommand.ExpandString($code)
ScriptType = 'bat'
}
Invoke-VMScript @sInvoke
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Just a quick thought: What about the port group to which the VM is connected? If you are going to place the VMs into another subnet, you may also need to "plug" the VM into the appropriate portgroup (VLAN).
André
no I got the vmguest IP wrong and need to chag it
Invoke-VMGuest?
Do you mean Invoke-VMScript?
What Guest OS is running in that VM?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sorry yes invoke-vmscript
windows 2019
You said "unable to login", is that with a domain account?
You will need an account (domain or local) to use with Invoke-VMScript.
An alternative might be to reboot the Guest OS in Safe Mode.
But that would be a manual procedure
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i have local creds but I cant sign into the console
but I tested the local creds and see to take invoke-vmscript commands
You could try something like this.
It assumes there is only 1 network connection defined inside the Guest OS, and that the connection is named 'Local Area Connection'
$vmName = 'MyVM'
$ip = '10.1.1.1'
$user = 'domain\user'
$pswdTxt = 'password'
$vm = Get-VM -Name $vmName
$pswd = ConvertTo-SecureString -String $pswdTxt -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($user, $pswd)
$code = @'
netsh interface ip set address "Local Area Connection" static $ip
'@
$sInvoke = @{
VM = $vm
GuestCredential = $cred
ScriptText = $ExecutionContext.InvokeCommand.ExpandString($code)
ScriptType = 'bat'
}
Invoke-VMScript @sInvoke
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc