Hello!
I’d like to collect information about last logon computer name from computers in out environment by logon script.
I’ve run script for testing purposes on my DC like this:
$computer = $env:COMPUTERNAME $username = $env:USERNAME $daterimestamp = date $var = $computer + ' - ' + $daterimestamp $var Set-ADUser -Identity $username -HomePage $var #Get-ADUser -Identity $username -Properties HomePage
This script set property HomePage for ADUser account for two purposes:
- I see a computer name which a user have logged on last time sucessfully while opening ADUser account property
- I can retrieve this information by runing Get-ADUser cmdlet during an inventory
I would like to run the script by GPO (user configuration - scripts - logon), but:
- The script must be run under the administrative right to write changes to ADUSer account
- The computer on which the script runs must have ActiveDirectory module to run Get-AD* cmdlets
If I use:
$computer = $env:COMPUTERNAME $username = $env:USERNAME $daterimestamp = date $var = $computer + ' - ' + $daterimestamp $var Invoke-Command -ComputerName DC -ScriptBlock { Set-ADUser -Identity $username -HomePage $var}
the script doesn’t see my variable $username and tells me that parameter Identity is null.
Could you advise me how to resolve this issue? Or maybe there is another approach to get this result!
Thank you!