I was playing around with the AccountExpirationDate properties and found that a failure to resolve $user.AccountExpirationDate properly can invalidate an entire string that was to be printed to the screen. This behavior somewhat surprised me and can be demonstrated using the following code. The basic issue that this teaches is all COM calls should be fed into variables and NOT concatenated into a string using a plus sign.
When you execute this code, the text "ExpDate2" is not printed at all when the account is configured NOT to expire. The call $User.AccountExpirationDate returns an error apparently nullifying the entire string.
I do not believe that this is an issue that needs any resolution. I bring it up so that everyone is aware that using a plus sign (+) in these circumstances can potentially cause them a problem.
To test:
; Setup User1 with account set to NEVER expire.
; Setup User2 with an account set to Expire on some date
; Be sure to configure a Fullname for each account to verify that the script continues to run properly.
; Execute with USER1, edit then execute for User2
$User = GetObject("WinNT://@Ldomain/User1,user")
? "Name: " + $User.name
? "ExpDate1: " $User.AccountExpirationDate
? "ExpDate2: " + $User.AccountExpirationDate
$Date = $User.AccountExpirationDate
? "ExpDate3: $Date"
? "Error:@Error@CRLF@Serror"
? "FullName: " + $User.fullname
[ 18 March 2002, 14:59: Message edited by: Howard Bullock ]