<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tags 'Scripting Guy!', 'Active Directory', and 'string manipulation'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=Scripting+Guy!,Active+Directory,string+manipulation&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'Scripting Guy!', 'Active Directory', and 'string manipulation'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>Use PowerShell String Techniques to Create User Names for Active Directory</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/12/21/use-powershell-string-techniques-to-create-user-names-for-active-directory.aspx</link><pubDate>Wed, 21 Dec 2011 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:13710</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft PowerShell MVP, Sean Kearney, shows how to use Windows PowerShell string techniques to create user names for Active Directory.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. It is time for PowerShell in Blueville Part 3 with Honorary Scripting Guy and Windows PowerShell MVP, Sean Kearney. WooHoo&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So where we did go? What did we say? &lt;br /&gt; Oh, right! Mr. Finch was just dancing away! &lt;br /&gt; He had learned from two guys, both ending in Blue, &lt;br /&gt; Two fellows he met called Hugh and called Stu, &lt;br /&gt; Of PowerShell from that Microsoft land, &lt;br /&gt; A beautiful thing, which did gave him a hand. &lt;br /&gt; It unlocked divisions in one line of work, &lt;br /&gt; And exported data with nary a quirk. &lt;br /&gt; So off Mr. Finch did run to the site, &lt;br /&gt; And obtained his user list, not overnight! &lt;br /&gt; Now back in his office, import them he must, &lt;br /&gt; In PowerShell, he was certain this he could trust. &lt;br /&gt; Smart was Mr. Finch, he knew what to do. &lt;br /&gt; He leapt down five floors and consulted a Blue!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;With a thud he did land, with thick padded shoe, &lt;br /&gt; Thank goodness he bought them, and so bouncy too. &lt;br /&gt; Leaping down stairs was silly you see, &lt;br /&gt; Unless you had shoes as thick as a tree. &lt;br /&gt; So blinking away and trying to see, &lt;br /&gt; He saw his goal looming, the Blues of Tier three. &lt;br /&gt; He opened the door and saw one alone, &lt;br /&gt; Quickly finish a task on the unified phone. &lt;br /&gt; Smiling away at a table for two, &lt;br /&gt; Was the smartest of all, her name it was Sue. &lt;br /&gt; And before you could say, &amp;ldquo;Stop that rhyming, please&amp;rdquo; twice, &lt;br /&gt; She smacked RhymeOMatic with a large bag of rice.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Hello, Mr. Finch, I&amp;rsquo;m Sue&amp;hellip;Sue Blue.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Mr. Finch smiled. Somehow he suspected that. &amp;ldquo;I have a problem but I suspect you&amp;rsquo;re going to say, &amp;lsquo;With Windows PowerShell, that&amp;rsquo;s a breeze!&amp;rsquo;&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Yes, it probably is, but what do you need to do?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Mr. Finch showed Sue the exported CSV file from the Quest cmdlets he obtained from the client site. &amp;ldquo;I cleaned it up so I have only the First and Last names of the users, but I need to import this into an OU I created under the Boston OU called &amp;lsquo;Contoso&amp;rsquo;. I found a cmdlet called &lt;b&gt;New-QADUser&lt;/b&gt;, and most of it makes sense, but I am having problems. First off, where do I start?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;So what is in your file, Mr. Finch?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;I have a list of First Names and Last Names of all the staff brought over from Contoso. However, what I would really like to know is&amp;hellip;Is there an easy way with Windows PowerShell to build the User IDs in the system? I figured if I could get the new staff in with a simple password, I could update the additional data later. Our UserID is normally a user&amp;rsquo;s first name followed by their last initial.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Absolutely Mr. Finch. For this, we&amp;rsquo;re going to build a small script to&amp;hellip;&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Mr. Finch shuddered. &amp;ldquo;Scripts. Oh, that&amp;rsquo;s FAR too difficult for me. I never learned scripting.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;If you&amp;rsquo;ll allow me to finish. Let me show you at least how you make that user name in Windows PowerShell. Then we&amp;rsquo;ll see who can&amp;rsquo;t script.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Let&amp;rsquo;s show you some basic work with what&amp;rsquo;s called a variable in Windows PowerShell. If we put a dollar sign (&lt;b&gt;$&lt;/b&gt;) before a word in Windows PowerShell, it&amp;rsquo;s a variable. Windows PowerShell variables can have very descriptive names like &lt;b&gt;$MrFinch&lt;/b&gt; or &lt;b&gt;$BlueScreenOfLife&lt;/b&gt; or &lt;b&gt;$FriedChicken95BumbleBees&lt;/b&gt;. So let us show you how to build a user name. Let us assign a make-believe user to two Windows PowerShell variables.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$FirstName=&amp;rsquo;Gazoo&amp;rsquo;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$LastName=&amp;rsquo;Blue&amp;rsquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Let&amp;rsquo;s imagine our user name was simply the first and last names added together. Within Window PowerShell, if we type the following&amp;hellip;&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$FirstName+$Lastname&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;&amp;hellip;it will show us this as if we added them together:&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;GazooBlue&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Now if we want to have Windows PowerShell remember that, we use another variable to remember that.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$Username=$Firstname+$Lastname&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Now, you try Mr. Finch. Try your name where I used $FirstName and $LastName.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Mr. Finch tentatively walked up to the keyboard like it was going to bite him. He typed slowly, unsure of what the computer might do to him&amp;mdash;like swallow him whole&amp;mdash;or worse, work in VisiCalc.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$FirstName=&amp;rsquo;Mister&amp;rsquo;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$LastName=&amp;rsquo;Finch&amp;rsquo;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$Username=$FirstName+$LastName&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Now watch what happens when I type $Username,&amp;rdquo; coaxed Sue Blue.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;MisterFinch&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Mister Finch nearly fell out of his azure blue boxer shorts. It&amp;hellip;it just worked! &amp;ldquo;That wasn&amp;rsquo;t difficult!&amp;rdquo; he muttered to himself. &amp;ldquo;So how could we make that into our standard user name? Is there a way to tell Windows PowerShell to only use the first letter?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Sue Blue nodded. &amp;ldquo;Windows PowerShell has built-in features to pull information out exactly the way you want it. We just add &lt;b&gt;&amp;lsquo;substring()&lt;/b&gt;&amp;rsquo; to the end of the Windows Powershell variable, and we tell it how much we want out.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Here&amp;rsquo;s an example. This will show us all the letters from the word starting at position 0 (zero), which is the first position, and it will return three letters.&amp;rdquo; Sue Blue keyed into screen as the results returned.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$LastName.substring(0,3)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Fin&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Oh!&amp;rdquo; burst out Mr. Finch, taking initiative. &amp;ldquo;So if I only wanted the first character, which would be position 0 and only ONE character it would be:&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$Lastname.substring(0,1)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Which means&amp;hellip;I think it means&amp;hellip;to make my user name, I do believe this would work.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;He carefully typed in the console, no longer frightened, but interested and excited.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$Username=$Firstname+$Lastname.substring(0,1)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Mr. Finch nervously watched as he typed in $Username and saw:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;MisterF&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;WoooHoooooo!!!! Did I just script?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Sue Blue smiled. &amp;ldquo;You will if you put that into Notepad and save it with a file name and .PS1 as the extension.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Quickly Mr. Finch keyed in:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$Firstname=&amp;rsquo;Mister&amp;rsquo;&lt;br /&gt; $Lastname=&amp;rsquo;Finch&amp;rsquo;&lt;br /&gt; $Username=$Firstname+$Lastname.substring(0,1)&lt;br /&gt; $Username&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then he saved it as NEWUSER.PS1.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Now Mr. Finch, I believe I shall guide you down to tier 4, where I believe that the next Blue can help you along.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It wasn&amp;rsquo;t so hard, he couldn&amp;rsquo;t believe,&lt;br /&gt; Scripting seemed easy, oh such a reprieve.&lt;br /&gt; He just couldn&amp;rsquo;t wait to get started again&lt;br /&gt; In moments in minutes with another Blue friend.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;That is all for Part 3. Please join us tomorrow as Sean continues life in Blueville.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3472048" width="1" height="1" alt="" /&gt;</description></item></channel></rss>