Hello All Techies,
Is their any way to update the IP, Subnet Mask,Gateway, DNS (Primary & Secondary) & WINS (Primary & Secondary). Using invoke-script & input file (as CSV).
Any leads will be very helpful.
Thanks,
Samojit Das
Yes, you can use Invoke-VMScript to run the required netsh commands inside the guest OS.
Have for example a look at Re: P2V Windows 2000, need an IP PowerCLI script to activate the OS , more specifically the Set-WinVMIP function
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Error --- 'Get-WmiObject' is not recognized as an internal or external command,operable program or batch file. is the current IP Address
Changing IP to 'Get-WmiObject' is not recognized as an internal or external command,operable program or batch file.
Working on WIN2K_SAMOJIT
The interface name is 'Get-WmiObject' is not recognized as an internal or external command,operable program or batch file.
Changing IP Address of WIN2K_SAMOJIT interface 'Get-WmiObject' is not recognized as an internal or external command,operable program or batch file. from 'Get-WmiObject' is not recognized as a
n internal or external command,operable program or batch file. to 'Get-WmiObject' is not recognized as an internal or external command,operable program or batch file.
Script That I'm trying is
$VMs = (get-vm | where {$_.Name -match $computer -and $_.PowerState -eq "PoweredOn"}).Name
foreach ($vm in $VMs) {
if ($os -match "Microsoft Windows Server 2000" ) {
#PowerShell used by Invoke-VMScript to retrieve current IP Addres
$ipscript = '(Get-WmiObject Win32_NetworkAdapterConfiguration | where-object {$_.IPAddress -match "' + $origIp + '" -and $_.AddressFamily -eq "IPv4"})'
$currentIp = invoke-vmscript -ScriptText $ipscript -ScriptType Bat -VM $vm -GuestUser $UserName -GuestPassword $Password
$currentIp = $currentIp -replace "`t|`n|`r",""
write-host "$currentIp is the current IP Address"
#Adjust Original IP to Replacement IP
$changeIp = $currentIp.replace("$origIp", "$Ip")
$changeIp = $changeIp -replace "`t|`n|`r",""
Write-Host "Changing IP to $changeIp"
Write-Host "Working on $vm"
#Get the Interface Name (Alias)
$aliasscript = '(Get-WmiObject Win32_NetworkAdapterConfiguration| where-object {$_.IPAddress -match "' + $origIp + '" -and $_.AddressFamily -eq "IPv4"})'
$getIntAlias = invoke-vmscript -ScriptText $aliasscript -ScriptType Bat -VM $vm -GuestUser $UserName -GuestPassword $Password
$getIntAlias = $getIntAlias -replace "`t|`n|`r",""
write-host "The interface name is $getIntAlias"
#Change the IP Address
$changingIp = "c:\windows\system32\netsh.exe interface ip set address ""Local Area Connection"" static $IP $SM $GW 1"
Write-host "Changing IP Address of $vm interface $getIntAlias from $currentIp to $changeIp"
$setIp = invoke-vmscript -ScriptText $changingIp -ScriptType bat -VM $vm -GuestUser $UserName -GuestPassword $Password
}
}
}
That looks as if PowerShell is not installed on that guest OS.
You can do WMI calls from the command line with the wmic command.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference