<?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>Maartendamen&#039;s blog &#187; wsem</title>
	<atom:link href="http://www.maartendamen.com/tag/wsem/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maartendamen.com</link>
	<description>Blogging on various IT subjects</description>
	<lastBuildDate>Tue, 22 Nov 2011 21:27:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Mass creation of HP WSEM WiFi guest accounts using SSH and PowerShell</title>
		<link>http://www.maartendamen.com/2010/07/mass-creation-of-hp-wsem-wifi-guest-accounts-using-ssh-and-powershell/</link>
		<comments>http://www.maartendamen.com/2010/07/mass-creation-of-hp-wsem-wifi-guest-accounts-using-ssh-and-powershell/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 13:58:51 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[hp]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[wsem]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=348</guid>
		<description><![CDATA[I was asked to create 365 (1 year) of WiFi (daily) guest access accounts, and export them to CSV. Of course I didn&#8217;t want to create them by hand.. this is where PowerShell came in. I used the following PowerShell script to create random WiFi guest accounts: Special thanks to Joel Bennett&#8217;s SharpSSH wrapper for [...]]]></description>
			<content:encoded><![CDATA[<p>I was asked to create 365 (1 year) of WiFi (daily) guest access accounts, and export them to CSV.<br />
Of course I didn&#8217;t want to create them by hand.. this is where PowerShell came in. I used the following PowerShell script to create random WiFi guest accounts:</p>
<p><span id="more-348"></span></p>
<pre class="brush: powershell; title: ; notranslate">
# Number of days to generate, default = 365
$NumDays 		= 365
$AccessGroup 	= &quot;Gasten&quot;
$ExpiryTime 	= &quot;20:00&quot;
$StartTime 		= &quot;07:00&quot;
$OutputCSV		= &quot;C:\TEMP\wireless.csv&quot;

$SshHost 		= &quot;127.0.0.1&quot;
$SshUser		= &quot;someuser&quot;

$access_codes = @()

# Start SSH session
New-SshSession $SshUser $SshHost
Invoke-Ssh &quot;z&quot;
Invoke-Ssh &quot;conf t&quot;
Invoke-Ssh &quot;wireless F&quot;
Invoke-Ssh &quot;conf t&quot;
Invoke-Ssh &quot;radius-server local&quot;

$i = 0;
do {
	# WSEM format: mm/dd/yyyy hh:mm
	$date = (Get-Date).AddDays($i)
	$date2 = Get-Date $date -Format &quot;dd-MM-yyyy&quot;
	$date = Get-Date $date -format &quot;MM:dd:yyyy&quot;
	$pass = RandomPassword 4
	$user = RandomPassword 4
	$output = &quot;rad-user $user password 0 $pass group $AccessGroup guest expiry-time $ExpiryTime expiry-date $date start-time $StartTime start-date $date&quot;

	# add user through SSH
	Invoke-ssh $output

	$Response = New-Object PSObject
	Add-Member -InputObject $Response -MemberType NoteProperty -Name &quot;Datum&quot; -Value $date2
	Add-Member -InputObject $Response -MemberType NoteProperty -Name &quot;Gebruikersnaam&quot; -Value $user
	Add-Member -InputObject $Response -MemberType NoteProperty -Name &quot;Wachtwoord&quot; -Value $pass
	$access_codes += $Response

	$i++;
} while ( $i -le $NumDays )

# Save and disconnect SSH
Invoke-ssh &quot;write mem&quot;
Remove-SshSession

# Export to CSV
$access_codes | Export-Csv $OutputCSV

# Helper functions
function RandomPassword ([int]$intPasswordLength)
{
   $strNumbers = &quot;1234567890&quot;
   $strCapitalLetters = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
   $strLowerLetters = &quot;abcdefghijklmnopqrstuvwxyz&quot;
   $rand = new-object random

   for ($a=1; $a -le $intPasswordLength; $a++)
      {
         if ($a -gt 3)
           {
      	      $b = $rand.next(0,3) + $a
      	      $b = $b % 3 + 1
      	   } else { $b = $a }
      	 switch ($b)
      	   {
      	      &quot;1&quot; {$b = &quot;$strNumbers&quot;}
      	      &quot;2&quot; {$b = &quot;$strCapitalLetters&quot;}
      	      &quot;3&quot; {$b = &quot;$strLowerLetters&quot;}
      	   }
         $charset = $($b)
         $number = $rand.next(0,$charset.Length)
         $RandomPassword += $charset[$number]
      }
   return $RandomPassword
}
</pre>
<p>Special thanks to Joel Bennett&#8217;s SharpSSH wrapper for PowerShell (located here: <a href="http://huddledmasses.org/scriptable-ssh-from-powershell/">http://huddledmasses.org/scriptable-ssh-from-powershell/</a>) which I used to automate the command line commands for the HP WSEM.<br />
This shows the great power of PowerShell for automating virtually anything! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2010/07/mass-creation-of-hp-wsem-wifi-guest-accounts-using-ssh-and-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

