I am working on a script that converts a text file of IPs to hostname and then uses Get-Qadcomputer to determine the DN and Path of the host in AD. When I run the below script I get the error:
Get-QADComputer : Cannot convert 'System.String[]' to the type 'Quest.ActiveRoles.ArsPowerShellSnapIn.Data.IdentityParameter' required by parameter 'Identity'. Specified method is
not supported.
Is there a way to convert the hostname variable from System.String[] to the one required by Get-Qadcomputer? Or is there a better way to make my script? Also, I would appreciate an in depth explanation of any resolutions. I just picked up powershell a few weeks ago and I am still learning the syntax, logic, and capabilities. Thanks!
Function Get-OU
{
param(
[string]$file
)
get-content $file | foreach-object{$a=([system.net.Dns]::GetHostByAddress("$_")).hostname
if($? -eq $False) {
Echo "===================================="
Echo "Cannot resolve host for $_"
}
elseif($? -eq $True){
Echo "===================================="
Echo "Hostname for IP $_"
$separator = "."
$n = $a.split($Separator)
get-qadcomputer -Identity $n[0]
}
}
}