<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>@Henning &#187; PowerShell</title>
	<atom:link href="http://www.eiben.weite-welt.com/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eiben.weite-welt.com</link>
	<description>Yet another blog - surviving the internet</description>
	<lastBuildDate>Sun, 29 Jan 2012 16:37:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mass-Updating Active Directory</title>
		<link>http://www.eiben.weite-welt.com/2011/05/mass-updating-active-directory/</link>
		<comments>http://www.eiben.weite-welt.com/2011/05/mass-updating-active-directory/#comments</comments>
		<pubDate>Tue, 03 May 2011 16:53:18 +0000</pubDate>
		<dc:creator>Henning Eiben</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://www.eiben.weite-welt.com/2011/05/mass-updating-active-directory/</guid>
		<description><![CDATA[I just love PowerShell! Although I’m not really mature in the syntax yet, I find myself moreoften doing little things in powershell. Today I figured, that in my previous task of creating 150 sample accounts I missed out on the email-address. So I just wrote a simple line of powershell. First off, I went to [...]]]></description>
			<content:encoded><![CDATA[<p>I just love PowerShell! Although I’m not really mature in the syntax yet, I find myself moreoften doing little things in powershell.</p>
<p>Today I figured, that in my previous task of <a href="https://www.eiben.weite-welt.com/2011/04/sample-domain-data/">creating 150 sample accounts</a> I missed out on the email-address. So I just wrote a simple line of powershell. First off, I went to the OU just by navigating to the AD-provider <code>cd AD:</code> and then change to <code>cd OU=Test,DC=demo,DC=local</code>. That’s already cool. Then just a simple line like</p>
<pre class="brush: ps;">dir | foreach { $x = Get-AdUser $_; $y=$x.samAccountName; Set-Aduser -identity $x -emailaddress &quot;$y@demo.local&quot;; }</pre>
<p>And since I’m on a roll, I also updated the passwords for all users </p>
<pre class="brush: ps;">Get-ADUser -Filter 'Name -like &quot;*&quot;' -SearchBase &quot;OU=Acme,DC=demo,DC=local&quot; | Set-ADAccountPassword -Reset -NewPassword (ConvertTo-SecureString -AsPlainText &quot;demo&quot; -Force)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.eiben.weite-welt.com/2011/05/mass-updating-active-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample Domain Data</title>
		<link>http://www.eiben.weite-welt.com/2011/04/sample-domain-data/</link>
		<comments>http://www.eiben.weite-welt.com/2011/04/sample-domain-data/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 13:47:00 +0000</pubDate>
		<dc:creator>Henning Eiben</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://www.eiben.weite-welt.com/2011/04/sample-domain-data/</guid>
		<description><![CDATA[Sometimes you just need to have a decent amount of sample data. Recently I created an active directory to do some development using SharePoint 2010. In order to have a realistic baseline I needed to have a decent amount of fictive users. So instead of creating a ton of users like User1 to User150 I [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you just need to have a decent amount of sample data. Recently I created an active directory to do some development using SharePoint 2010. In order to have a realistic baseline I needed to have a decent amount of fictive users.</p>
<p>So instead of creating a ton of users like User1 to User150 I thought of something more elaborate. Why not create random user-accounts?</p>
<p>After some google-research I found a <a href="http://www.quietaffiliate.com/free-first-name-and-last-name-databases-csv-and-sql">blogpost</a> with a list of first- and lastnames as CSV-files. Fantastic! This looks like a promising starting point. To spice everything up a notch I also created list of departments and functions. So this will give me quite a batch of user-data.</p>
<p>To mix everything quite good, I created a little piece of powershell:</p>
<pre class="brush: ps;"># Import list of Last names from Simple Text file
$lastname=import-csv '.\lastname.csv'
# Import list of First names Simple Text file
$firstname=import-csv '.\firstname.csv'
# Import list of roles, prefixes and departments
$roles=import-csv '.\role.csv'
$prefixs=import-csv '.\prefix.csv'
$departments=import-csv '.\department.csv'
# How many names to generate
$totalnames=150
# the Header for our new CSV file
$firstline='Firstname,Lastname,Position,Department,Phone'
# Create a file called “DomainUsers.csv”
Set-content -path 'DomainUsers.csv' -value $firstline
$firstnamecount=$firstname.Count
$lastnamecount=$lastname.Count
$rolecount=$roles.Count-1
$prefixcount=$prefixs.Count-1
$departmentcount=$departments.Count-1
# Go through and Generate some names
foreach ( $namecounter in 1..$totalnames )
{
    # Pick a random first and Last name
    $lastnamenumber=(get-random -min 0 -max ($lastnamecount-1))
    $firstnamenumber=(get-random -min 0 -max ($firstnamecount-1))
    $rolenumber=(get-random -min 0 -max ($rolecount))
    $prefixnumber=(get-random -min 0 -max ($prefixcount))
    $departmentnumber=(get-random -min 0 -max ($departmentcount))
    $FakeName=($firstname[$firstnamenumber].Firstname+','+$lastname[$lastnamenumber].Lastname)+','+
        ($prefixs[$prefixnumber].Prefix+' '+$departments[$departmentnumber].Department+' '+$roles[$rolenumber].Role).Trim()+','+
        $departments[$departmentnumber].Department+','+
        '555-'+(get-random -min 100 -max 999)+'-'+(get-random -min 1000 -max 9999)
    # Echo the New name to the Screen
    write-host $fakename
    # and write to the File
    add-content -path 'DomainUsers.csv' -value $fakename
}</pre>
<p>I think the script doesn’t need any further explanation. The result will be a CSV-file with a bunch of random user account data.</p>
<p>The Import into active directory is done in a second powershell-script (just because I had that already).</p>
<pre class="brush: ps;">param([string]$FileName, [string]$adpath)
Import-Module ActiveDirectory
function Import-Users([string]$UserFile)
{
    Import-Csv $UserFile | foreach-object {
        $accountName = $_.Lastname+$_.Firstname.Substring(0,2)
        $displayName=$_.Firstname+" "+$_.LastName
        New-AdUser $accountName -samAccountName $accountName -Company "Acme Corp." -Department $_.Department -DisplayName $displayName -GivenName $_.Firstname -Surname $_.Lastname -OfficePhone $_.Phone -Title $_.Position -CannotChangePassword $true -PasswordNeverExpires $true -Enabled $true -AccountPassword (ConvertTo-SecureString -AsPlainText "demo" -Force) -Path $spou
    }
}
$spou = "OU=Acme,$adpath"
Import-Users $FileName</pre>
<p>This is rather boring. To start the script you have to supply the name of the CSV containing the user-data and you have to supply the path to your domain in the form of “dc=acme,dc=local”. This snipplet assumes that there is an OU called Acme, where all the user accounts should be placed.</p>
<p>These are the files I used to generate the sample accounts:</p>
<ul>
<li>
<div id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:31f49ca9-aa9a-46ab-aa10-badfd9ebf3a3" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<div><a href="http://www.eiben.weite-welt.com/wp-content/uploads/2011/04/firstname.csv" target="_self">firstname.csv</a></div>
</div>
</li>
<li>
<div id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:eb7c4c1e-a0f6-47dd-94bf-f39e6e3479e8" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<div><a href="http://www.eiben.weite-welt.com/wp-content/uploads/2011/04/lastname.csv" target="_self">lastname.csv</a></div>
</div>
</li>
<li>
<div id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:d13d9f98-d5b5-4ec7-9522-5ec4faee4c44" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<div><a href="http://www.eiben.weite-welt.com/wp-content/uploads/2011/04/role.csv" target="_self">role.csv</a></div>
</div>
</li>
<li>
<div id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:19810420-3940-4682-ac50-826ed3555ccb" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<div><a href="http://www.eiben.weite-welt.com/wp-content/uploads/2011/04/prefix.csv" target="_self">prefix.csv</a></div>
</div>
</li>
<li>
<div id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:2c32fda1-9a64-40ae-a7ef-c244f34450f4" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<div><a href="http://www.eiben.weite-welt.com/wp-content/uploads/2011/04/department.csv" target="_self">department.csv</a></div>
</div>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.eiben.weite-welt.com/2011/04/sample-domain-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating local users &#8211; en mass</title>
		<link>http://www.eiben.weite-welt.com/2009/12/creating-local-users-en-mass/</link>
		<comments>http://www.eiben.weite-welt.com/2009/12/creating-local-users-en-mass/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 22:02:30 +0000</pubDate>
		<dc:creator>Henning Eiben</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">http://www.eiben.weite-welt.com/2009/12/creating-local-users-en-mass/</guid>
		<description><![CDATA[The traditional way of creating a vast amount of users would include a lot of time as well as patience. Or – maybe just a few lines of (magic) PowerShell code. So first of all, we have to connect to the local ADSI. This can be done via WinNT://[ComputerName]: $ComputerName = $env:COMPUTERNAME $Computer = [adsi]"WinNT://$ComputerName" [...]]]></description>
			<content:encoded><![CDATA[<p>The traditional way of creating a vast amount of users would include a lot of time as well as patience. Or – maybe just a few lines of (magic) PowerShell code.</p>
<p>So first of all, we have to connect to the local ADSI. This can be done via <code>WinNT://[ComputerName]</code>:</p>
<pre class="brush: powershell;">$ComputerName = $env:COMPUTERNAME
$Computer = [adsi]"WinNT://$ComputerName"</pre>
<p>This is already the most crucial part. Next we create a new user, set the username, fullname and description and the password.</p>
<pre class="brush: powershell;">function Add-User([string]$UserName, [string]$FullName, [string]$Description, [string]$Password)
{
    $User = $Computer.Create("user", $UserName)
    $User.Put("fullName", $FullName)
    $User.Put("description", $Description)
    $User.SetPassword($Password)
    $User.SetInfo()
}</pre>
<p>The SetInfo() call ensures, that the data is actually persisted.</p>
<p>Voila, that’s already all you need to get going. Well, in order to create a massive amount of users you will want to create a csv-file of users like:</p>
<pre class="brush: plain;">UserName,FullName,Description,Password
usera,User A,Desc A,passworda
userb,User B,Desc B,passwordb</pre>
<p>This can be read with just a single line of code.</p>
<pre class="brush: powershell;">function Import-Users([string]$UserFile)
{
    Import-Csv $UserFile | foreach-object { Add-User $_.UserName $_.FullName $_.Description $_.Password }
}</pre>
<p>So now all you need is to call <code>Import-Users myNewUsers.csv</code> from the PowerShell command-line and off you go!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eiben.weite-welt.com/2009/12/creating-local-users-en-mass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When &quot;save&quot; feels like lockdown</title>
		<link>http://www.eiben.weite-welt.com/2009/06/powershell_restricted/</link>
		<comments>http://www.eiben.weite-welt.com/2009/06/powershell_restricted/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 11:50:52 +0000</pubDate>
		<dc:creator>Henning Eiben</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">http://blog.eiben.weite-welt.com/2009/06/when-save-feels-like-lockdown/</guid>
		<description><![CDATA[So Microsoft really got down to business with this security thing - after installing PowerShell on my new machine I figured, th...]]></description>
			<content:encoded><![CDATA[<p>So Microsoft really got down to business with this security thing &#8211; after installing PowerShell on my new machine I figured, that it&#8217;s configured in <em>restricted</em> mode.</p>
<p>This is not some kind of limited mode of operation, but rather this denies the execution of all scripts whatsoever &#8211; the term <em>restricted</em> suggested something else, at least in my mindset.</p>
<p>The four PowerShell execution policies include the following:</p>
<ul>
<li>Restricted: No scripts can run.</li>
<li>AllSigned: Ps1 and .Ps1xml files must be digitally signed.</li>
<li>RemoteSigned: Ps1 and .Ps1xml files from the internet must be digitally signed.</li>
<li>Unrestricted: No digital signatures are required and all scripts can be executed.</li>
</ul>
<p>To find your current policy-setting just use <code>Get-ExecutionPolicy</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eiben.weite-welt.com/2009/06/powershell_restricted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

