get-qaduser nt | select passwordlastset

I

IT STAFF

get-qaduser ntid | foreach {

$password = $_.PasswordLastSet.TolongDateString()

}

You cannot call a method on a null-valued expression.
At C:\idm.ps1:16 char:49
+ $password = $_.PasswordLastSet.TolongDateString <<<< ()
+ CategoryInfo : InvalidOperation: (TolongDateString:String)
[], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

============================
It gives an error although i can see the actual date. How do i remove the
error?

============================
 

My Computer

J

Justin Rich

I assume whats happening is that some of the account have not changed so
there is no value (null) and thats causing the problem so you can just wrap
it in an if statement and look for null...
something like this (im not awesome at this so bear with me)

get-qaduser ntid | foreach { if ($_.PasswordLastSet -ne $null){$password =
$_.PasswordLastSet.TolongDateString()}}

think that should do it

"IT STAFF" <[email protected]> wrote in message
news:[email protected]

> get-qaduser ntid | foreach {
>
> $password = $_.PasswordLastSet.TolongDateString()
>
> }
>
> You cannot call a method on a null-valued expression.
> At C:\idm.ps1:16 char:49
> + $password = $_.PasswordLastSet.TolongDateString <<<< ()
> + CategoryInfo : InvalidOperation: (TolongDateString:String)
> [], RuntimeException
> + FullyQualifiedErrorId : InvokeMethodOnNull
>
> ============================
> It gives an error although i can see the actual date. How do i remove the
> error?
>
> ============================
>
 

My Computer

Top