Windows Workflow met Windows PowerShell on the DFO Show
I've just posted a few minutes back a new DFO Show episode that we put together with Full Armor's Danny Kim. In the show Danny shows how they have combined Windows Workflow Foundation with Windows PowerShell to create an amazing product.
In the demo we show how we can find IIS 7 servers, then provision them with new web sites and content. Here are some of the code snippets we used.
1st we go and grab the servers from AD then query them using WMI for the exsistence of the "Web Server" Role. Note we use the new win32_ServerComponent WMI Provider.
$strCategory = "computer"
$IIS7Servers = new-object Collections.ArrayList
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$searcher=New-object DirectoryServices.DirectorySearcher
$Searcher.SearchRoot = $objDomain
$searcher.Filter= ("(objectCategory=$strCategory)")
$PropList = "name","distinguishedName"
$PropList | foreach {[void]$searcher.PropertiesToLoad.Add($_)}
$Computers = $searcher.FindAll()
foreach ($comp in $Computers)
{
[string]$CompName = $comp.Properties.name
if (get-wmiobject -query "select * from win32_ServerComponent where Name='Web Server' and State<>'Not Applicable'")
{
$IIS7Servers.Add($CompName)
}
}
Set-Variable -name IIS7Svrs -value ($IIS7Servers) -passthru -scope global -option AllScope
Then we create a new site using the Microsoft.Web.Administration namespace.
$configPath = "\\$server\C$\Windows\System32\inetsrv\config\applicationHost.config"
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$serverManager = new-object Microsoft.Web.Administration.ServerManager $configPath
$site = $serverManager.Sites.Add($_.SiteName,$_.DirPath,$_.Port)
$site.ServerAutoStart = $true
$serverManager.CommitChanges()
Copying the files was easy
$ServerList = (Get-variable IIS7Svrs).value
foreach ($server in $ServerList)
{
[string] $localpath = $_.DirPath
$remotepath = $localpath -replace(":", "$")
$destpath = "\\$server\$remotepath"
copy-item "c:\Site Staging" $destpath -recurse
}
THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS
Comments
Anonymous
April 10, 2007
Would seem one can only stream the video... I'd like to download and watch at a later time. Is it possible somehow?Anonymous
April 10, 2007
If you right-click on the Full Screen button, and choose "Save Target As..." it should download the file.