I am setting up a custom command to decomission users, part of the process before the AD groups are removed I want it to export a list of the groups to a network location. I can do it easily enough in powershell when specifying the user, but trying to use the %SAMAccountName% isn't working. Below is the small script I have so far to do it, can you please advise if anything is missing?
Import-Module Adaxes
$ADusername = "%SAMAccountName%"
$filedestinaton = "*file path*"
Get-admPrincipalGroupMembership $ADusername | select name | Export-Csv $filedestinaton-$ADusername.csv
I am currently getting an error "The command can be executed via an Adaxes service only." I have a security role which is allowed to run this custom command which I have added my account to, so i believe i have permission to run it.