Quantcast
Channel: VMware Communities : Discussion List - vRealize Orchestrator
Viewing all articles
Browse latest Browse all 6251

How do you call Microsoft DHCP and DNS using the Powershell 1.0.4 Orchestrator Plugin?

$
0
0

Hello,

To start here are the versions of everything:

vCenter - 5.5

VCO - 5.5

PowerShell Plugin - 1.0.4

PowerShell Host - Server 2012 R2 (Powershell 4.0)

DHCP Server - Server 2012 R2

DNS Server - Server 2012 R2

 

I've been beating my head against the wall trying to figure out how to get this Powershell script to run in VCO.

I've tried a few different methods and always get the same error code:

PowerShellInvocationError: Errors found while executing script Microsoft.Management.Infrastructure.CimException: Failed to retrieve free IP address for 192.168.175.0 on server mydc01.domain.local.    at Microsoft.Management.Infrastructure.Internal.Operations.CimAsyncObserverProxyBase`1.ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext, T currentItem, Boolean moreResults, MiResult operationResult, String errorMessage, InstanceHandle errorDetailsHandle)

 

Here is my script that runs perfectly from the command line

param (    [string]$hostname = $(throw "-hostname is required."),    [string]$macaddress = $(Get-Date -format yy-MM-dd-hh-mm-ss),    [string]$dhcpserver = $(throw "-dhcpserver is required."),    [string]$scopeid = $(throw "-scopeid is required."),    [string]$dnszone = $(throw "-dnszone is required.")
)
# ^ Make sure all the needed variables are passed through^
#Grab a free IP address from the DHCP Server
$vmIP = Get-DhcpServerv4FreeIPAddress -ComputerName $dhcpserver -ScopeId $scopeid
#Create an A recored in DNS for the VM
Add-DnsServerResourceRecordA -Name $hostname -ZoneName $dnszone -CreatePtr -IPv4Address $vmIP -CimSession $dhcpserver
#Create a DHCP reservation for the VM
Add-DhcpServerv4Reservation -Name $hostname -ScopeId $scopeid -IPAddress $vmIP -ClientId $macaddress.ToString() -Description "$hostname - Generated by OnDemand" -CimSession $dhcpserver
#Get the DHCP scope options to set on the VM
$scopeOptions=Get-DhcpServerv4OptionValue -ComputerName $DHCPServer -ScopeId $scopeid
#Get the scope
$scope=Get-DhcpServerv4Scope -ComputerName $dhcpserver -ScopeId $scopeid
#Loop through the scope options and set the options to variables
foreach ($option in $scopeOptions){    #If the scope options matches the number then set the variable    switch ($option.OptionId){        #Option ID 3 is gateway        3  {$vmGateway=$option.Value[0]}        #Option ID 6 is an Array of DNS Servers        6  {$vmDnsArray=$option.Value}        #Option ID 15 is the DNS Name        15 {$vmDnsDomainName=$option.Value[0]}        #Option ID 44 is an Array of WINS Servers        44 {$vmWinsArray=$option.Value}    }
}
#Set the subnetmask
$vmSubnetMask=$Scope.SubnetMask.IPAddressToString
#Print out all of the variables
$vmIP
$vmSubnetMask
$vmGateway
$vmDnsArray
$vmDnsDomainName
$vmWinsArray

 

 

I call this script as follows:

C:\> powershell.exe -file -hostname "test1234" -dhcpserver "mydc01.domain.local" -scopeid "192.168.175.0" -dnszone "domain.local"

 

I've tried multiple different workflows in VCO (Invoke a Powershell script, Invoke an external script, & Invoke a script via API) and each an every one of them fails with the above error message.

 

I think it has something to do with the VCO plugin not being aware of the DHCP and DNS PowerShell libraries.

I see that there are "Snapins" in VCO under Administer > Powershell > HostName

Do I need to somehow add a snapin for those powershell libraries?

 

Any help would be greatly appreciated.

 

Thank you,

Cody Hill


Viewing all articles
Browse latest Browse all 6251

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>