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 don’t know what is going wrong.
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
Get-ADComputer -searchbase “OU=SC,OU=Servers,DC=WSDOT,DC=LOC” -Filter {$_.LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName
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 don’t know what is going wrong. $DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
Get-ADComputer -searchbase “OU=SC,OU=Servers,DC=WSDOT,DC=LOC” -Filter {$_.LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName Read More