I'm getting IP address of vShpere VM by using this command:
$VMIPAddress = (Get-VM -Name $VMName).Guest.IPAddress | Select-Object -First 1
and I'm trying to add DHCP reservation by using this command:
Invoke-Command -ComputerName mdc1.ad.morphisec.com -ScriptBlock{
Add-DhcpServerv4Reservation -ScopeId 192.168.0.0 -IPAddress $VMIPAddress -ClientId $VMMacAddress -Description $VMname
}
But I'm getting this error all the time:
Cannot validate argument on parameter 'IPAddress'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
+ CategoryInfo : InvalidData: (:) [Add-DhcpServerv4Reservation], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Add-DhcpServerv4Reservation
+ PSComputerName : mdc1.ad.morphisec.com
I understand this is happening because the variable $VMIPAddress is string...
$VMIPAddress.GetType().name
String
But how can I convert it to Integer/IPaddress and pass it to the Add-DhcpServerv4Reservation command?