Forum Discussion
TJCooper440
Oct 16, 2024Copper Contributor
Powershell 7 - $time is not defined - Script from Microsoft
I get the error "Get-ADComputer: Variable: 'time' found in expression: $time is not defined.". The script is straight from Microsoft and $time is populated with a date/time. It seems very simple, I d...
TJCooper440
Oct 21, 2024Copper Contributor
I will try that, but I dont think that is the issue. The $time is correct. It simply wont work when doing the comparison.
Vern_Anderson
Oct 21, 2024Copper Contributor
I just now noticed that you have the $_.LastLogonTimeStamp
To my knowledge the $_ indicates an object that was "piped" in I do not see where you piped any objects in.
of course I do not use AD CMDLETs as often as some others but this syntax seems to be the issue here.
Get-ADComputer -Filter * | Where-Object {$_.LastLogonTimeStamp -lt [DateTime]$Time}You could try this but when I query my AD computers that property is NULL on every computer, or I may not have rights to see it.
If you do this command does it return any computer objects??
Get-ADComputer -Filter * | Where-Object {$_.LastLogonTimeStamp}