VMware Cloud Community
Transplant
Enthusiast
Enthusiast
Jump to solution

Using Invoke-VMScript

I am trying to set my IP on 2012 r2 server that I just created from a template.

PS C:\> Invoke-VMScript -VM atl01osi399 -GuestUser sp1test -GuestPassword xxxxxxx -ScriptText {New-NetIPAddress -InterfaceAlias Ethernet -IPAddress 10.199.25.50 –PrefixLength 24 -DefaultGateway 10.199.25.1 -Confirm:$false}

ScriptOutput

-----------------------------------------------------------------------------------------------------------------------|  New-NetIPAddress :

Access is denied.

|  At line:1 char:4

|  + & {New-NetIPAddress -InterfaceAlias Ethernet -IPAddress 10.199.25.50

|  -PrefixLeng ...

|  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

|  ~~~

|      + CategoryInfo          : PermissionDenied: (MSFT_NetIPAddress:ROOT/Standa

|     rdCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException

|      + FullyQualifiedErrorId : Windows System Error 5,New-NetIPAddress

|

-----------------------------------------------------------------------------------------------------------------------

If this helps:

Get-PowerCLIVersion

PowerCLI Version

----------------

   VMware vSphere PowerCLI 5.5 Release 2 Patch 1 build 1931983

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Transplant
Enthusiast
Enthusiast
Jump to solution

Sorry it took me so long to respond, I decided to script out the entire process of building vm's from the input of a csv file and now that I have that going, I was able to do more testing with this problem. Yes, it turns out to be UAC, it maybe be helpful for others to know that UAC setting on a 2012 server are different than 2008.  Not only do you have to move the slider to the off position, you have to make a change in the registry.  Once I did this to my template, I was able to run this command successfully.

PS C:\> Invoke-VMScript -VM atl01test2 -GuestUser tstuser -GuestPassword password1 -ScriptText {New-NetIPAddress -InterfaceAlias Ethernet -IPAddress 172.16.20.55 –PrefixLength 24 -DefaultGateway 172.16.20.1 -Confirm:$false}

ScriptOutput

-----------------------------------------------------------------------------------------------------------------------| 

|  IPAddress         : 172.16.20.55

|  InterfaceIndex    : 12

|  InterfaceAlias    : Ethernet

|  AddressFamily     : IPv4

|  Type              : Unicast

|  PrefixLength      : 24

|  PrefixOrigin      : Manual

|  SuffixOrigin      : Manual

|  AddressState      : Tentative

|  ValidLifetime     : Infinite ([TimeSpan]::MaxValue)

|  PreferredLifetime : Infinite ([TimeSpan]::MaxValue)

|  SkipAsSource      : False

|  PolicyStore       : ActiveStore

|  IPAddress         : 172.16.20.55

|  InterfaceIndex    : 12

|  InterfaceAlias    : Ethernet

|  AddressFamily     : IPv4

|  Type              : Unicast

|  PrefixLength      : 24

|  PrefixOrigin      : Manual

|  SuffixOrigin      : Manual

|  AddressState      : Invalid

|  ValidLifetime     : Infinite ([TimeSpan]::MaxValue)

|  PreferredLifetime : Infinite ([TimeSpan]::MaxValue)

|  SkipAsSource      : False

|  PolicyStore       : PersistentStore

-----------------------------------------------------------------------------------------------------------------------

The additional step is the registry entry “EnableLUA” at “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system”. The default value is “1”. To fully disable UAC, change this value to “0” and reboot for it to take effect.

Remember when you are done to re-enable UAC both at “User Account Control Settings” and set that registry entry back to “1”.

PS C:\> Invoke-VMScript -VM atl01test2 -GuestUser tstest -GuestPassword password1 -ScriptText {ipconfig /all}

ScriptOutput

-----------------------------------------------------------------------------------------------------------------------| 

|  Windows IP Configuration

|     Host Name . . . . . . . . . . . . : WIN-PTESTG4P88

|     Primary Dns Suffix  . . . . . . . :

|     Node Type . . . . . . . . . . . . : Hybrid

|     IP Routing Enabled. . . . . . . . : No

|     WINS Proxy Enabled. . . . . . . . : No

|  Ethernet adapter Ethernet:

|     Connection-specific DNS Suffix  . :

|     Description . . . . . . . . . . . : vmxnet3 Ethernet Adapter

|     Physical Address. . . . . . . . . : 00-50-56-8E-0c-55

|     DHCP Enabled. . . . . . . . . . . : No

|     Autoconfiguration Enabled . . . . : Yes

|     IPv4 Address. . . . . . . . . . . : 172.16.20.55(Preferred)

|     Subnet Mask . . . . . . . . . . . : 255.255.255.0

|     Default Gateway . . . . . . . . . : 172.16.20.1

|     NetBIOS over Tcpip. . . . . . . . : Enabled

|   

-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

It looks as if the guest account you are using is not allowed to change the IP address.


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

0 Kudos
Transplant
Enthusiast
Enthusiast
Jump to solution

That is the low hanging fruit. I can run that command logged on as that user, and that account is in the local administer group.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Is UAC enabled on that box ?

Did you already try with the netsh command. See Alan's PowerCLI: Changing a VM IP Address with Invoke-VMScript


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

Transplant
Enthusiast
Enthusiast
Jump to solution

Sorry it took me so long to respond, I decided to script out the entire process of building vm's from the input of a csv file and now that I have that going, I was able to do more testing with this problem. Yes, it turns out to be UAC, it maybe be helpful for others to know that UAC setting on a 2012 server are different than 2008.  Not only do you have to move the slider to the off position, you have to make a change in the registry.  Once I did this to my template, I was able to run this command successfully.

PS C:\> Invoke-VMScript -VM atl01test2 -GuestUser tstuser -GuestPassword password1 -ScriptText {New-NetIPAddress -InterfaceAlias Ethernet -IPAddress 172.16.20.55 –PrefixLength 24 -DefaultGateway 172.16.20.1 -Confirm:$false}

ScriptOutput

-----------------------------------------------------------------------------------------------------------------------| 

|  IPAddress         : 172.16.20.55

|  InterfaceIndex    : 12

|  InterfaceAlias    : Ethernet

|  AddressFamily     : IPv4

|  Type              : Unicast

|  PrefixLength      : 24

|  PrefixOrigin      : Manual

|  SuffixOrigin      : Manual

|  AddressState      : Tentative

|  ValidLifetime     : Infinite ([TimeSpan]::MaxValue)

|  PreferredLifetime : Infinite ([TimeSpan]::MaxValue)

|  SkipAsSource      : False

|  PolicyStore       : ActiveStore

|  IPAddress         : 172.16.20.55

|  InterfaceIndex    : 12

|  InterfaceAlias    : Ethernet

|  AddressFamily     : IPv4

|  Type              : Unicast

|  PrefixLength      : 24

|  PrefixOrigin      : Manual

|  SuffixOrigin      : Manual

|  AddressState      : Invalid

|  ValidLifetime     : Infinite ([TimeSpan]::MaxValue)

|  PreferredLifetime : Infinite ([TimeSpan]::MaxValue)

|  SkipAsSource      : False

|  PolicyStore       : PersistentStore

-----------------------------------------------------------------------------------------------------------------------

The additional step is the registry entry “EnableLUA” at “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system”. The default value is “1”. To fully disable UAC, change this value to “0” and reboot for it to take effect.

Remember when you are done to re-enable UAC both at “User Account Control Settings” and set that registry entry back to “1”.

PS C:\> Invoke-VMScript -VM atl01test2 -GuestUser tstest -GuestPassword password1 -ScriptText {ipconfig /all}

ScriptOutput

-----------------------------------------------------------------------------------------------------------------------| 

|  Windows IP Configuration

|     Host Name . . . . . . . . . . . . : WIN-PTESTG4P88

|     Primary Dns Suffix  . . . . . . . :

|     Node Type . . . . . . . . . . . . : Hybrid

|     IP Routing Enabled. . . . . . . . : No

|     WINS Proxy Enabled. . . . . . . . : No

|  Ethernet adapter Ethernet:

|     Connection-specific DNS Suffix  . :

|     Description . . . . . . . . . . . : vmxnet3 Ethernet Adapter

|     Physical Address. . . . . . . . . : 00-50-56-8E-0c-55

|     DHCP Enabled. . . . . . . . . . . : No

|     Autoconfiguration Enabled . . . . : Yes

|     IPv4 Address. . . . . . . . . . . : 172.16.20.55(Preferred)

|     Subnet Mask . . . . . . . . . . . : 255.255.255.0

|     Default Gateway . . . . . . . . . : 172.16.20.1

|     NetBIOS over Tcpip. . . . . . . . : Enabled

|   

-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Transplant
Enthusiast
Enthusiast
Jump to solution

In an effort to finish out the usefulness of this topic, How do you build credentials into a script?  I have already made my New-VMFromTemplate command part of a Module, but lets say I want to have the credentials for the local logon for the invoke-vmscript to be part of the script, but I don't want them to be so anyone looking at it can read it, is there a way to do this?

0 Kudos