I am trying to run a ps1 file sending one paramter. This script is to unlock account on AD.
My ps1 file is:
Param([string]$user="")
Get-ADUser -Properties * -Filter {mail -like "$user"} |
Unlock-ADAccount |
Sync-ADObject -Destination "AZUDCMO01"
And I called it using:
PS C:\Users\fornecedor.bmc01> .\bmc_unlock_ad.ps1 "andreza.perez@grupomoura.com"
No error is returned, but the account is still locked.
Anyone tried this way to unlock accounts?
For this you don't want to use the -Properties *
parameter at all. All you need is to get an ADUser object with enough properties to be able to send it through the pipeline. Get-ADUser
returns more than enough properties for that.
Having said that, You are piping from the Unlock-ADAccount
cmdlet to the Sync-ADObject
cmdlet, but...
according to the docs , the Unlock-ADAccount
cmdlet by default does not return anything. For that part you need to add the parameter -PassThru
.
Try this:
Param([string]$user="")
Get-ADUser -Filter {mail -like "$user"} |
Unlock-ADAccount -PassThru |
Sync-ADObject -Destination "AZUDCMO01"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.