psPAS icon indicating copy to clipboard operation
psPAS copied to clipboard

Set-PASUser - Unix time error on ExpiryDate

Open anycard94 opened this issue 1 month ago • 10 comments

Set-PASUser in psPAS 6.4.80 using CyberArk PAM 12.6 on accounts without expiryDate shows the following error:

"ConvertTo-UnixTime : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:44 char:65

  • ... ct['ExpiryDate'] = $UserProperties['ExpiryDate'] | ConvertTo-UnixTime
  •                                                    ~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (-62135578800:Int64) [ConvertTo-UnixTime], ParameterBindingException
    • FullyQualifiedErrorId : InputObjectNotBound,ConvertTo-UnixTime"

This error doesn't prevent the PAS user changes but is thrown for parameter changed using Set-PASUser.

Environment:

  • PowerShell Version: 5.1.22621.2506
  • psPAS Version: 6.4.80
  • CyberArk Version: 12.6.12.217

The accounts in question all have expiryDate of -62135578800 which is a nullable date. If we set an account with a valid expiration date it does not throw this error.

I was able to modify Format-PASUserObject.ps1 to do a check of negative numbers to remove this error:

'ExpiryDate' { #Include date string in required format if ($UserProperties['ExpiryDate'] -le -1){ $UserObject['ExpiryDate'] = $null } else { $UserObject['ExpiryDate'] = UserProperties['ExpiryDate'] | ConvertTo-UnixTime }

		}

This removes the error and updates the account. However not sure if this is a proper fix but should be a good starting point.

I tried other fixes such as changing from piping to ConvertTo-UnixTime to specifying ConvertTo-UnixTime -Date UserProperties['ExpiryDate'] but that throws an error about DateTime.MinValue.Ticks / Max.Ticks and doesn't update PAS user.

anycard94 avatar May 07 '24 18:05 anycard94