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...
Vern_Anderson
Oct 21, 2024Copper Contributor
Since it's hard coded in the script anyway why even set the variable to 90? Just set negative 90 right in the parenthesis!
$time = (Get-Date).Adddays(-90)
Get-ADComputer -searchbase "OU=SC,OU=Servers,DC=WSDOT,DC=LOC" -Filter {$_.LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedNameVern_Anderson
Oct 21, 2024Copper Contributor
The only other suggestion I would have if it has to be a variable, you could try adding one more dollar sign in front of the parenthesis like so. . .
$time = (Get-Date).Adddays(-$($DaysInactive))