Script manager powerShell script samples (Change guest IP and DNS servers addresses)

Script manager powerShell script samples (Change guest IP and DNS servers addresses)

Sample workflows running powerShell scripts.

  • Change IP address
  • Change DNS servers

These were created with the help of the guest script manager package.

Disclaimer: These samples workflows are provided AS IS and are not considered production quality and are not officially supported. Use at your own risk. Feel free to modify and expand and share your contributions.

Tags (3)
Attachments
Comments

Hello Christophe,

Thanks for this great tool. Based on the samples I added a WF to change the Gataway address, but now that I want to combine all the network configurations (static IP, gateway, DNS servers and search suffix) I am encountering a weird issue. I created this resource element as a text file and imported it to vCO:

$NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index};

if (!$NetInterface) {

    throw 'No interface found for "[InterfaceAlias]"'

}

$retval = $NetInterface.EnableStatic("[IPv4Address]", "[SubnetMask]");

if ($retval.ReturnValue -ne 0) {

    throw "Command EnableStatic failed with exit code " + $retval.ReturnValue

}

$retval = $NetInterface.SetGateways("[GatewayAddress]");

if ($retval.ReturnValue -ne 0) {

    throw "Command SetGateways failed with exit code " + $retval.ReturnValue

}

$dnsArray = "[DNSServerAddresses]".split(",");

$retval = $NetInterface.SetDNSServerSearchOrder($dnsArray);

if ($retval.ReturnValue -ne 0) {

    throw "Command SetDNSServerSearchOrder failed with exit code " + $retval.ReturnValue

}

$suffixArray = "[DNSSuffix]".split(",");

$nic = [wmiclass]"\\localhost\ROOT\cimv2:Win32_NetworkAdapterConfiguration";

$retval = $nic.SetDNSSuffixSearchOrder($suffixArray);

if ($retval.ReturnValue -ne 0) {

    throw "Command SetDNSSuffixSearchOrder failed with exit code " + $retval.ReturnValue

}

Then, I cloned one of the sample workflows and added a couple of lines to support the extra parameters. When I run the workflow it always fails:

TypeError: Cannot call method "get" of null (Workflow:Run script in VM guest / Get script configuration (item28)#1)

Inside the "Run script in VM guest" workflow the attribute scriptConfigurationProperties is not assigned to anything, so the first line fails:

scriptType = scriptConfigurationProperties.get("scriptType");

And as I said, it only fails for this particular "all in one" workflow, it runs fine when changing individually the gateway, static IP or DNS. And as dar as I can see the only thing that changes is the resource element and the number of parameters passed.

Any clue what is happening here?

Thank you,

Juan.

Nevermind Christophe, after reading the tutorial I found that you provided some workflows for script management. When importing the resource elements using "Add script configuration" everything works fine.

Greetings.. I know this was long while ago.. but any chance you can tell me which versions of vRO etc.. you used for this? I am trying to do the same now with vRO7 with vCenter 6 / ESXi 6..

Version history
Revision #:
1 of 1
Last update:
‎01-06-2014 01:59 PM
Updated by: