VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

help with Changing IP on VMguest - unable to login

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

8 Replies
a_p_
Leadership
Leadership
Jump to solution

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é

0 Kudos
tdubb123
Expert
Expert
Jump to solution

no I got the vmguest IP wrong and need to chag it

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Invoke-VMGuest?
Do you mean Invoke-VMScript?

What Guest OS is running in that VM?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert
Jump to solution

sorry yes invoke-vmscript

 

windows 2019

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
tdubb123
Expert
Expert
Jump to solution

i have local creds but I cant sign into the console 

 

but I tested the local creds and see to take invoke-vmscript commands

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

tdubb123
Expert
Expert
Jump to solution

Thanks Luc

0 Kudos