Answer the question
In order to leave comments, you need to log in
Why doesn't the PowerShell script work when there is no value in the attribute?
Greetings!
Somehow, I relaxed a little during self-isolation :( - I'm dumb a little.
Tell me, tell me what the problem could be:
There is a script that logs the user's login / logout to the server:
Param(
[Parameter(Position=0)]
[ValidateSet("Logon","Logoff","Unknown")]
[string]$Status="Unknown"
)
#no spaces in the filter
[adsisearcher]$searcher="samaccountname=$env:username"
#find the current user
$find = $searcher.FindOne()
#get the user object
[adsi]$user = $find.Path
#define a string to indicate status
$note= @("{0} {1} to {2}" -f (Get-Date),$status.ToUpper(),$env:computername)
[array]$NewVals = @()
$NewVals = $note + ($user.GetEx('url'))[0..10]
#DEBUG, output values in ISE
#$NewVals | out-host
#update the user property
$user.PutEx(2, 'url', $NewVals )
#commit the change
$user.SetInfo()
#DEBUG, output values in ISE
#$user.GetEx('url')
Exception calling "GetEx" with "1" argument(s): "The directory property cannot be found in the cache.
"
At \\nasta.local\SYSVOL\nasta.local\Policies\{A2FAB552-E94C-4675-9F3A-B50D0EB03516}\User\Scripts\Logon\Set-UserStatus.ps1:16 char:1
+ $NewVals = $note + ($user.GetEx('url'))[0..10]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question