Thursday, November 29, 2012

Meet my new friend Arduino

My thanksgiving gift to me this year in addition to 3 Kinects was the Arduino UNO R3 which is an open source electronics prototyping platform using Atmel's ATMEGA328P Microcontroller.  I ordered the starter kit from amazon.com which  has few components like jumper wires, Arduino prototyping board, battery connector, USB connector, bread  board and a base stand.

  Now on to next stage to make some LEDs blink.  Some more glamour shots of the board.

Hmm.  But that is not enough, so please show me your back side (no pun intended) I want to see your soldering.
Stay tuned to check out my rookie projects with it.  

Wednesday, November 14, 2012

Create a Default IIS Website using PowerShell

First you will have to import module named "WebAdministration"

PS C:\> Import-Module "WebAdministration"

PS C:\> Get-Command -Module "WebAdministration"

 You can create new website, app pools, bindings with these commandlets. I have combined few commandlets and created my script which does the following:

1.  Does a remote session into a specific computer with specific credentials
2.  Imports Module WebAdministration on that server.
3.  Creates WebAppPool and set's its property.  I have parameter where you can specify .net framework.
4.  Tests physical path of the website if it doesn't exists then it creates one for you.
5.  Create Website with bindings and set's application pool to the one created in step 3.

Here is the script. Enjoy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
param(
[parameter(Position=0,Mandatory=$true,HelpMessage="Name of Server")]
[ValidateNotNullorEmpty()]
[string]$serverName,
[parameter(Position=1,Mandatory=$true)]
[ValidateNotNullorEmpty()]
[string]$WebSiteName,
[parameter(Position=2,Mandatory=$true)]
[ValidateNotNullorEmpty()]
[string]$ServiceUser,
[parameter(Position=3,Mandatory=$true)]
[ValidateNotNullorEmpty()]
[string]$ServicePassword,
[parameter(Position=4,Mandatory=$true)]
[ValidateNotNullorEmpty()]
[string]$PhysicalPath,
[parameter(Position=5,Mandatory=$false)]
[ValidateNotNullorEmpty()]
[string]$WebBinding,
[parameter(Position=6,Mandatory=$true)]
[ValidateNotNullorEmpty()]
[string]$ManagedRunTimeVersion
)
$session = New-PSSession -ComputerName $serverName -Credential Get-Credential
     Invoke-Command -Session $session -ScriptBlock   {
param(
[string]$serverName,
[string]$strName,      #Site Name
[string]$strUser,      #Service Account
[string]$strPass,      #Account Password
[string]$strPath,      #Physical path for website
[string]$strNewURL,    #HostHeader - Bindings
[string]$strRunTime #Managed Runtime Version - .Net Framework version
)
Import-Module WebAdministration 
#Create App Pool
New-WebAppPool -Name $strName
Set-ItemProperty ("IIS:\AppPools\" + $strName) -name processModel.identityType -value 3
Set-ItemProperty ("IIS:\AppPools\" + $strName) -name processModel.username -value $strUser
Set-ItemProperty ("IIS:\AppPools\" + $strName) -name processModel.password -value $strPass
Set-ItemProperty ("IIS:\AppPools\" + $strName) -name managedRuntimeVersion -value $strRunTime
if (test-path $strPath){
#Create Web Site
New-Website –Name $strName –Port 80 –HostHeader $strNewURL –PhysicalPath $strPath
Set-ItemProperty ("IIS:\Sites\" + $strName) -name applicationPool -value $strName
Set-ItemProperty ("IIS:\Sites\" + $strName) -name ApplicationDefaults.applicationPool -value $strName
Set-ItemProperty ("IIS:\Sites\" + $strName) -name ..username -value $strUser
Set-ItemProperty ("IIS:\Sites\" + $strName) -name ..password -value $strPass
}
else{
New-item -path $strPath -type directory
New-Website –Name $strName –Port 80 –HostHeader $strNewURL –PhysicalPath $strPath | Out-Null
Set-ItemProperty ("IIS:\Sites\" + $strName) -name applicationPool -value $strName
Set-ItemProperty ("IIS:\Sites\" + $strName) -name ApplicationDefaults.applicationPool -value $strName
Set-ItemProperty ("IIS:\Sites\" + $strName) -name ..username -value $strUser
Set-ItemProperty ("IIS:\Sites\" + $strName) -name ..password -value $strPass
}
} -args $serverName,$WebSiteName,$ServiceUser,$ServicePassword,$PhysicalPath,$WebBinding,$ManagedRunTimeVersion
Remove-PSSession $session


With PowerShell V3 I do Show-command createdefaultwebsite.ps1 name and it shows me nice form to fill in the details.  I love this feature in V3.