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 16, 2024Copper Contributor
It works in Powershell 5
LainRobertson
Oct 16, 2024Silver Contributor
Hi, Theron.
I've copied and pasted the first two lines of your code verbatim into PowerShell and am not seeing an issue.
Cheers,
Lain
- TJCooper440Oct 16, 2024Copper ContributorI do not get an error then either. Its when it does the comparison with the lastlogindate it is generating an error. It works in Powershell 5.
- LainRobertsonOct 17, 2024Silver Contributor
The only thing I can see with line 3 (which has no bearing on the $time variable) is that you've used an underscore where there shouldn't be one. But this results in a different error to what you're reporting.
It might help if we can see the full script your testing with as "$_" would only make sense when used in a pipeline.
Cheers,
Lain
- TJCooper440Oct 21, 2024Copper ContributorI added the $_ to troubleshoot. I cant seem to edit the original post and remove it. The code is on this website. Its pretty simple. It works in 5, but not in 7.
https://learn.microsoft.com/en-us/archive/technet-wiki/52273.active-directory-how-to-find-inactive-computers-in