Using Enabled Property in if Statement

Hello Guys first post I am righting a simple ps1 script to disable, set expiration, and move an ad account. Currently this works, however for betting confimation support. I would like add “if” statements to each process confirming the prior process. <script src=“”></script>

So for instance after the account is disabled I would like to put an if the account is disabled then proceed to set expiration.

So direct question is how can i confirm that the account is disabled before I continue to the next set of instructions. Thank you for your insight I am fairly new to powershell hope this makes sense.

I’d recommend to use a little clearer or more descriptiv variable names. You use the variable name $DisabeledUser before the account is actually disabled. :wink:

Most Powershell cmdlets without any default output have a parameter -PassThru. This creates a object representing the treated input object. So for example:

$Server = ‘
$TreatedUser = Disable-ADAccount -Identity $RetailUser -Server $Server -PassThru
If (-not ($TreatedUser.enabled)) {
“$RetailUser successfully disabled”

… of course instead of the output you can put some more command there.

Additionally I’d recommend to use the parameter -Server for all the AD cmdlets. That ensures you work with the same object and not work with one AD object on one server and the next command tries to acces the same AD object but on another server.

That is great info. I will read up on passthru and give it a shot. Thanks for the information Olaf. also thank you for the reccomends as well. I am always looking for great pointers for efficiency anc consitency.