This is me every single time I sit down to use Pester…
While I do enjoy using Pester for operational validation, what do you do with the ones that fail? Most of the time you’re the one doing the validation in the chain of process and everything goes right! Because you’re that good… 😉 Hehe… I’ve been recently asked to update some users where some attributes didn’t get populated during a migration… Are you thinking what I’m thinking? 😉
The first thing I did was export the attributes they needed, easy enough. Next was to change the necessary attributes to the correct value. The ones that differ will fail (Of course they will Urv, not a total retard here… get on with it… )
Here’s where having proper descriptions can go a long way.
This is what a Test ErrorRecord looks like when you capture the results:
At first I thought of using regex on the ErrorRecord. Some of the attributes aren’t set which gave me some issues, so I decided to breadcrumb the name. First do a split on the colon ‘:’ grab the last part and do a split again using ‘/’ to get the attribute name and value. Don’t forget to trim() 🙂
There were some other Attributes that weren’t part of the default parameter set of the Set-ADUser cmdlet. To change those attributes you need to use the DisplayName and the Replace Operator. For the attributes “not set” that need to be cleared, use the Clear operator. Just don’t use both the parameter and the DisplayName! I had EmailAddress and mail in the CSV file, one passed and the other failed… I got rid of mail…
Ok here’s the code to get things done:
First get failed Pester tests.
This will give me a csv file with the following Columns, SamAccountName, Property & Expected (Value).
The set failed Pester tests will either set or clear the attribute depending on it’s value. If it’s $null it will be cleared.
Here are some screenshots to give you an idea what to expect.
Ideally you’d only have a few failed tests. I wouldn’t use this to reset entire User attributes. Moving and/or renaming an object isn’t supported… yet! 😉
So there you have it, taking failed Pester tests values and setting them accordingly!
Hope it’s worth something to you,