I had a scenario where we made some Active Directory changes via the Quest Get-QADUser command we wanted reversed because it didn’t act the way we thought it would. We wanted to set the passwordNeverExpires tag on a few accounts, so we kicked around the info in THIS post.
Essentially, we grabbed a bunch of users from the output screen that we needed to put back that looked like this:
ExchSVC user CN=ExchSVC,OU=Service Accounts,DC=WEBSIE,DC=LOCAL
Guest user CN=Guest,CN=Users,DC=WEBSITE,DC=LOCAL
jason user CN=jason,CN=Users,DC=WEBSITE,DC=LOCAL
So here are a few ways of making magic with the Split command in Powershell:
#The [regex] expression “,*..=” says find a pattern that #matches zero or more commas any two characters and an equal sign. #This would match any of the following: cn= ,ou= ,dc=
$dumped = gc "dumped.txt"
foreach($user in $dumped)
{
($user -split ",*..=")[1] | out-file justSamAccount.txt -append
}
ii justsamaccount.txt
#or could split on just grabbing first line (notice the double spaces on the split #as some usernames have spaces and you don’t want to split on them
$dumped = gc "dumped.txt"
foreach($user in $dumped)
{
($user -split " ")[0] | out-file justSamAccount2.txt -append
}
ii justsamaccount2.txt
#could also use split another way and split on commas and equals signs and grab the line in question:
$dumped = gc "dumped.txt"
foreach($user in $dumped)
{
$user.split(",=")[1] | out-file justSamAccount3.txt -append
}
ii justsamaccount3.txt
and I’m certain there are plenty more, but these are the ones I came up with to fix it.
@1 year ago
Yea, it’s weird - I was just messing around in a virtual environment I stood up and was going to try to move FSMO roles with Powershell. The first thing to do was to make sure ADWS was installed as the command I needed was in that module.
ipmo activedirectory
Contrary to popular belief, that just gives me:
- “WARNING: Error initializing default drive: ‘Unable to find a default server with Active Directory Services running.’.
I can’t imagine I’m the only person to ever see this, but Google apparently thinks so:

I ended up transferring them the old fashioned way, so not sure why it didn’t install, but will keep a closer eye on it next time to see if I clicked something else wrong along the way…
UPDATE: I thought i’d check if it was the HPC version and just like that, there’s my answer: http://social.microsoft.com/Forums/is/windowshpcitpros/thread/d88d6cb9-3aa6-4af5-932b-b62854e9e9de
@1 year ago
Wouldn’t mind seeing it in action somewhere. Got any examples of how you’ve used it?
powerwf:
From PowerShell MVP Don Jones
Remember my PowerShell Proverb: Every time you write a script that outputs text, God kills a puppy. It’s on your head.
WOW! At least he tells you how to avoid this fate.
@1 year ago with 1 note
henrikblog:
function Send-Email
{
param($to, $from, $subject, $body, $smtpServer)
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $from
$msg.To.Add($to)
$msg.Subject = $subject
$msg.Body = $body
$smtp.Send($msg)
}
Or use the new fancy send-mailmessage:
send-mailmessage -to "andy@AWEBSITEcom" -subject "The script took $timer3 to run" -body "
-----stats------
Script started at: $timer1
Script finished at: $timer2
It took $timer3 to finish." -smtpserver "MAILSERVERRELAYNAME" -from "AutoScripter@AWEBSITE.com"
@1 year ago with 1 note