Feeds:
Posts
Comments

Archive for the ‘Powershell’ Category

This is something I’ve done recently, i.e. to create IIS applications via Powershell scripting.

# Run this powerscript as an administrator (needed for IIS stuff)

#
# Create folders for the web site
#

$drive = “c:\”

“Creating folders…”

# home folder
$myhome = $drive + “mysite\”
new-item $myhome -itemtype directory

# log folders
new-item ($myhome + “Log”) -itemtype directory
new-item ($myhome + “Log\WebLog”) -itemtype directory

# web folders
new-item ($myhome + “www”) -itemtype directory
new-item ($myhome + “www\client”) -itemtype directory

#
# IIS stuff
#

# Load IIS module, to be able to do IIS stuff
import-module webadministration

# Set webadministration as default for all commands
IIS:

# Creating app pool, with some properties
$appPoolName = “myAppPool”
new-item (“AppPools\” + $appPoolName)
Set-ItemProperty (“AppPools\” + $appPoolName) -Name recycling.periodicRestart.requests -Value 1000
Set-ItemProperty (“AppPools\” + $appPoolName) managedRuntimeVersion v4.0
Set-ItemProperty (“AppPools\” + $appPoolName) enable32BitAppOnWin64 “true”

# Create the webapp & site
$homedir = $drive + “mysite\www\”
$hostname = “www.myhostname.com”
$sitename = “MySiteName”
$appname = “www.myhostname.com”
New-Item (“\Sites\” + $sitename) -bindings @{protocol=”http”;bindingInformation=(“:80:” + $hostname)} -physicalPath $homedir
Set-ItemProperty (“\sites\” + $sitename) -name applicationPool -value $appPoolName
New-Item (“\Sites\” + $sitename + “\client”) -type Application -physicalPath ($homedir + “client”) -force

# Change Logging
Set-ItemProperty (“\Sites\” + $sitename) -name logFile.directory -value ($drive + $sitename + “\Log\WebLog”)

“Done!”

Advertisements

Read Full Post »

$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$apps = $comAdmin.GetCollection(“Applications”)
$apps.Populate();

$newComPackageName = “MyApplicationName”

$appExistCheckApp = $apps | Where-Object {$_.Name -eq $newComPackageName}

if($appExistCheckApp)
{
$appExistCheckAppName = $appExistCheckApp.Value(“Name”)
“This COM+ Application already exists : $appExistCheckAppName”
}
Else
{
$newApp1 = $apps.Add()
$newApp1.Value(“Name”) = $newComPackageName
$newApp1.Value(“ApplicationAccessChecksEnabled”) = 0 # Security Tab, Authorization Panel, “Enforce access checks for this application
$newApp1.Value(“Identity”) = “nt authority\localservice”

$saveChangesResult = $apps.SaveChanges()
“Results of the SaveChanges operation : $saveChangesResult”
}

read-host ‘Press enter key to continue . . .’

Read Full Post »