Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Overwrite a variable with a new value

$
0
0

I have this piece of code that sits in a ForEach-Object loop ($Exists is a SamAccountName)

#Gets the User's Manager and gets the Name instead of the DistinguishedName (as it is easier to read), skips if ADUser Manager attribute is empty.

 

$LM=Get-ADUser$Exists-Properties*|Select-Object-ExpandPropertyManager

If ($LM){

$Manager=Get-ADUser$LM|Select-Object-ExpandPropertyName

 

#Confirm Output

write-host"Manager: $Manager"

}

 

The problem is that all the other variables in the loop get overwritten but because the Manager field in AD can be empty $LM doesn’t get overwritten until a new value of $LM is found.  So how do I reset $LM for each loop or force overwriting it. I tried put in $LM=$Null but that didn’t seem to work.


Viewing all articles
Browse latest Browse all 8583

Trending Articles