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

Set-ADUser -replace question

$
0
0

Hello all,

I've been working on this for a good part of the day and I can't get it to work exactly as it is supposed to.  Perhaps I'm overlooking something.

Here is the scenario:

I am working on a new version of a user management script and I make use of one of the seldom used attributes (CarLicense) for holding information.

I was looking to keep a count of how many times a user is disabled by populating it with "DisableCount:#".

I get the current value using $prevdisablecount=(get-aduser SmithJA -property carlicense).carlicense -match "DisableCount"

This will give me a string like "DisableCount:1"

I can then say $updcount=($disablecount -split ":")[0]+1

$disablecount="DisableCount:$($updcount)"   - This should be something like "DisableCount:2".

Here is the problem:  When I use set-aduser -identity SmithJA -replace @{carlicense=$($prevdisablecount),$($disablecount)}, it adds the value instead of replacing.

It does the same whether I specify the variables in the set-aduser cmdlet either as $($__), "$___" or $___

It seems it's not able to translate the strings.    I can -remove and -add the same values, but I should be able to use -Replace.


Viewing all articles
Browse latest Browse all 6937

Trending Articles