I am trying to get output from a ASDI query, but the job never ends. I have successfully gotten the script to run outside of a job but once I place it into a job my problem occurs. I have gotten simple functions to work correctly but an ADSI query. Any have an idea as to why this is happening or something I might have overlooked? My OS is Windows XP, SP3.
$scripttorun = {
param ($searchOUList)
function Get-ADComputerList ($SearchBase) {
$SearchOU = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$($SearchBase)")
$adobject = @()
$searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$searcher.Filter = "(&(objectClass=computer))"
$searcher.SearchRoot = $SearchOU
$searcher.SizeLimit = 1000
$searcher.PageSize = 1000
return $searcher.FindAll()
}
$results = @()
foreach ($ou in $searchOUList) {
$results += Get-ADComputerList $ou
}
return $results
}
[array]$searchList = @("OU=computers,OU=office1,DC=corp,DC=local", "OU=computers,OU=office2,DC=corp,DC=local")
$job = start-job -name myjob -scriptblock $scripttorun -argumentlist $searchList
$job | select *
State : Running
HasMoreData : True
StatusMessage :
Location : localhost
Command :
param ($searchOUList)
function Get-ADComputerList ($SearchBase) {
$SearchOU = New-Object System.DirectoryServices.DirectoryEntry("
LDAP://$($SearchBase)")
$adobject = @()
$searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$searcher.Filter = "(&(objectClass=computer))"
$searcher.SearchRoot = $SearchOU
$searcher.SizeLimit = 1000
$searcher.PageSize = 1000
return $searcher.FindAll()
}
$results = @()
foreach ($ou in $searchOUList) {
$results += Get-ADComputerList $ou
}
return $results
JobStateInfo : Running
Finished : System.Threading.ManualResetEvent
InstanceId : a0033110-f82c-49c3-9ee4-0879c149bdf5Id : 1
Name : myjob
ChildJobs : {Job2}
Output : {}
Error : {}
Progress : {}
Verbose : {}
Debug : {}
Warning : {}