VMware Cloud Community
niyijr
Enthusiast
Enthusiast
Jump to solution

Set-VMGuestNetworkInterface : A positional parameter cannot be found that accepts argument '$null'.

Hello guys,

I am trying to run a script that will pull off information (VM name, IP, gateway & port group) from a CSV and modify the network settings of various VMs.

I have searched everywhere and tried various modifications to get this to work but I have had no luck yet. Right now it gives this error;

Set-VMGuestNetworkInterface : A positional parameter cannot be found that accepts argument '$null'.

Attached is what I am using and the output from PowerGUI. The script is based on this link.

Any information will be helpful. I'm at my wits end.

Thanks

________________________________________________________
Please KUDO helpful posts and mark the thread as solved if answered
Tags (4)
Reply
0 Kudos
1 Solution

Accepted Solutions
deang1609
Enthusiast
Enthusiast
Jump to solution

Whilst not the resolution to your issue, it is probably worth noting that Set-VMGuestNetworkInterface is to be deprecated in the next release of PowerCLI as described here Announcement: Future Cmdlet Deprecation | VMware PowerCLI Blog - VMware Blogs.

I provided an alternative to the above to configure IPv4 address details and DNS server settings for the guest network interface on a Microsoft Windows operating system using the a combination of the New-NetIPAddress, Set-DNSClientServerAddress and the Invoke-VMScript Cmdlets- Modifying guest network interface with the Invoke-VMScript cmdlet | Deans Blog.

The above article on the deprecation of the Cmdlet, also provides other alternatives for the script text to be invoked using the Invoke-VMScript cmdlet agaisnt different guest operating systems.

Dean Grant Blog: deangrant.wordpress.com | Twitter: @dean1609 | GitHub: https://github.com/dean1609

View solution in original post

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Which OS do you have running in the guest ?

The Set-VMGuestNetworkInterface cmdlet doesn't work against all possible guest OS you can have in the VM


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

Reply
0 Kudos
niyijr
Enthusiast
Enthusiast
Jump to solution

The guest OS is Windows XP

________________________________________________________
Please KUDO helpful posts and mark the thread as solved if answered
Reply
0 Kudos
deang1609
Enthusiast
Enthusiast
Jump to solution

Whilst not the resolution to your issue, it is probably worth noting that Set-VMGuestNetworkInterface is to be deprecated in the next release of PowerCLI as described here Announcement: Future Cmdlet Deprecation | VMware PowerCLI Blog - VMware Blogs.

I provided an alternative to the above to configure IPv4 address details and DNS server settings for the guest network interface on a Microsoft Windows operating system using the a combination of the New-NetIPAddress, Set-DNSClientServerAddress and the Invoke-VMScript Cmdlets- Modifying guest network interface with the Invoke-VMScript cmdlet | Deans Blog.

The above article on the deprecation of the Cmdlet, also provides other alternatives for the script text to be invoked using the Invoke-VMScript cmdlet agaisnt different guest operating systems.

Dean Grant Blog: deangrant.wordpress.com | Twitter: @dean1609 | GitHub: https://github.com/dean1609
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It should work for XP (although you shouldn't be using XP anymore :smileycry:).

It looks as if you forgot the -VmGuestNetworkInterface parameter keyword in your code

guestnic.png


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

niyijr
Enthusiast
Enthusiast
Jump to solution

LucD wrote:

It should work for XP (although you shouldn't be using XP anymore :smileycry:).

It looks as if you forgot the -VmGuestNetworkInterface parameter keyword in your code

guestnic.png

Thanks.

Tried that too. No luck.

Was just testing out the script in my lab environment and XP is not as memory hungry as the other Windows operating systems. Smiley Happy

________________________________________________________
Please KUDO helpful posts and mark the thread as solved if answered
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you get another error message when you add in that parameter ?


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

Reply
0 Kudos
niyijr
Enthusiast
Enthusiast
Jump to solution

deang1609 wrote:

Whilst not the resolution to your issue, it is probably worth noting that Set-VMGuestNetworkInterface is to be deprecated in the next release of PowerCLI as described here Announcement: Future Cmdlet Deprecation | VMware PowerCLI Blog - VMware Blogs.

I provided an alternative to the above to configure IPv4 address details and DNS server settings for the guest network interface on a Microsoft Windows operating system using the a combination of the New-NetIPAddress, Set-DNSClientServerAddress and the Invoke-VMScript Cmdlets- Modifying guest network interface with the Invoke-VMScript cmdlet | Deans Blog.

The above article on the deprecation of the Cmdlet, also provides other alternatives for the script text to be invoked using the Invoke-VMScript cmdlet agaisnt different guest operating systems.

Finally got it to work using the Invoke-VMScript Cmdlets. (Sources are here and here)

I had initially thought the Invoke-VMScript was replaced by Set-VMGuestNetworkInterface. Apparently it was the other way around.

Here's the script that worked for me. In case anyone else is interested.

# Load PowerCLI

add-PSSnapIn  -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue;

#Connect to vcenter server

$vcenter = "192.168.52.132"

#Import list of vms

Import-csv C:\Users\MyUser\Documents\list.csv |

foreach {

    $VM = $_.computer

    $IP = $_.ip

  $SNM = "255.255.255.0"

    $GW = $_.gw

    $GuestUser = 'administrator'

  $GuestPassword = '1234'

Function Set-WinVMIP ($VM, $HC, $GC, $IP, $SNM, $GW){

$netsh = "c:\windows\system32\netsh.exe interface ip set address ""Local Area Connection"" static $IP $SNM $GW 1"

Write-Host "Setting IP address for $VM..."

#Run Invoke-VMScript

Invoke-VMScript -VM $VM -HostCredential $HC -GuestUser $GuestUser -GuestPassword $GuestPassword -ScriptType bat -ScriptText $netsh

Write-Host "Setting IP address completed."

}

$VM = $_.computer

Set-WinVMIP $VM $HostCred $GuestCred $IP $SNM $GW

    }  

#Disconnect from vcenter server

Disconnect-viserver $vcenter -Confirm:$False

Thanks deang1609 & LucD for your help on this.

________________________________________________________
Please KUDO helpful posts and mark the thread as solved if answered
Reply
0 Kudos
niyijr
Enthusiast
Enthusiast
Jump to solution

Yes I did but I can't remember the error.

Got it to work though using the Invoke-VMScript cmdlet.

Thanks a lot.

________________________________________________________
Please KUDO helpful posts and mark the thread as solved if answered
Reply
0 Kudos