Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

array elements

$
0
0

I created an array $users as follows

$users =get-aduser -filter {DEPARTMENT -like "SE*" -and Title -like "Teacher*"} -properties *| ft name,department,title,office,memberof -autosize

and when I try to access arrays elements

$users[1]

I get

out-lineoutput : Object reference not set to an instance of an object.
    + CategoryInfo          : NotSpecified: (:) [out-lineoutput], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.OutLineOutputCommand

or when I do this

foreach($object in $users)

{
            Write-Host "$i. $($object.name)"
            $i++
}

I get blanksq

 

204.
205.
206.
207.

what am I missing?

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles