Seems like a few bugs exist in the PowerShell Web Administration cmdlets, for example I was trying to use Get-Website to find a website by its name but it always retured an array of all websites and ignored the name argument:

This DOESN'T WORK:

 $site = Get-Website -Name "DanSite"  

This WORKS:

 $site = Get-Item "iis:sites/DanSite"  

 


Posted in: IIS7 , PowerShell  Tags: , ,
Admin posted on October 11, 2011 12:50

Here's a PowerShell script that determines if the OS is Windows Server 2008 and enables a list of windows features.  To get a list of features and enabled status run Get-WindowsFeature (after importing the  servermanager module).

 

 Import-Module servermanager  
   
 function IsWindows2008(){  
   $operatingSystem = gwmi win32_operatingSystem | select name  
   return $operatingSystem.name.contains("Server 2008")  
 }  
   
 function EnableWindowsFeatures($featureList) {  
   foreach ($feature in $featureList) {  
     $featureInfo = Get-WindowsFeature $feature  
     if (!$featureInfo.installed){  
       Add-WindowsFeature $feature  
     }  
   }  
 }  
   
 function Main() {  
   if(IsWindows2008){  
     $features = "Web-Windows-Auth", "Web-Asp-Net"  
     EnableWindowsFeatures $features  
   }  
 }  
   
 Main  
   

Here's how to enable IIS7 ISAPI CGI restrictions using PowerShell and the webadministration modules:

 

 Import-Module webadministration  
   
 function Is64Bit  
 {  
      [IntPtr]::Size -eq 8  
 }  
   
 function EnableIsapiRestriction($isapiPath){  
      $isapiConfiguration = get-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$isapiPath']/@allowed"  
   
      if (!$isapiConfiguration.value){  
           set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$isapiPath']/@allowed" -value "True" -PSPath:IIS:\  
           Write-Host "Enabled ISAPI - $isapiPath " -ForegroundColor Green  
      }  
 }  
   
 function EnableDotNet40Isapi($systemArchitecture){  
      $frameworkPath = "$env:windir\Microsoft.NET\Framework$systemArchitecture\v4.0.30319\aspnet_isapi.dll"  
      EnableIsapiRestriction $frameworkPath       
 }  
   
 function Main(){  
      if (Is64Bit){  
           EnableDotNet40Isapi "64"  
      }  
      EnableDotNet40Isapi  
 }  
   
 Main  

Posted in: IIS7 , PowerShell  Tags: , ,
 function Is64Bit  
 {  
      [IntPtr]::Size -eq 8  
 }  
 function InstallIISRewriteModule(){  
      $wc = New-Object System.Net.WebClient  
      $dest = "IISRewrite.msi"  
      $url  
      if (Is64Bit){  
           $url = "http://go.microsoft.com/?linkid=9722532"  
      } else{  
           $url = "http://go.microsoft.com/?linkid=9722533"       
      }  
      $wc.DownloadFile($url, $dest)  
      msiexec.exe /i IISRewrite.msi /passive  
 }  
 if (!(Test-Path "$env:programfiles\Reference Assemblies\Microsoft\IIS\Microsoft.Web.Iis.Rewrite.dll")){  
      InstallIISRewriteModule  
 } else  
 {  
      Write-Host "IIS Rewrite Module - Already Installed..." -ForegroundColor Green  
 }  

Posted in: IIS7 , PowerShell  Tags: , ,

I came across an interesting problem today with MSDeploy whilst trying to recycle the application pool from a custom manifest.

Here's the manifest:

<?xml version="1.0" encoding="utf-8"?>

<sitemanifest>

  <RecycleApp path="SiteName" recycleMode="StopAppPool" />

  <IisApp path="c:\projects\test\app1" managedRuntimeVersion="v4.0" />

  <RecycleApp path="SiteName" recycleMode="StartAppPool" />

</sitemanifest>

and here's the error:

 

EXEC : error : Object of type 'manifest' and path 'c:\projects\app1\DeployManifests\DeployManifest.xml' cannot be created. [c:\projects\app1\Build.proj]
EXEC : error : One or more entries in the manifest 'sitemanifest' are not valid. [c:\projects\app1\Build.proj]
EXEC : error Code: ERROR_SITE_DOES_NOT_EXIST [c:\projects\app1\Build.proj]

The error is actually helpful in that it's telling us what is wrong (the site is missing) and to fix the problem you just need to make suire the site exists but for me this runs on our build server so the sites don't exist!

This is pretty useless and I haven't found a workaround for it so I've been finding that whilst MSDeploy is really good for some thing like file copying it's rather bad at other things so my adive is to use remote powershell to do anything "slightly complicated".

 

 


Posted in: IIS7 , MSDeploy  Tags:

 

I've been working with PowerShell recently to automate our deployments particularly around IIS so more for my benefit I'm starting a Powershell tips section containing things that I need to remember or others routines that I couldn't easily find on the Internet.

So for my first tip:  How to Update IIS Virtual Directories With Powershell

 

import-module webadministration


Set-Location 'IIS:\Sites\XpertHR.Blue'

foreach ($item in Get-Childitem 'IIS:\Sites\SiteName.Blue' | 
         where {$_.Schema.Name -eq 'Application'}) {

 $item.PhysicalPath = $item.PhysicalPath.Replace("Blue", "Green")

 set-itemproperty $item.PSPath -name physicalPath -Value 
       $item.PhysicalPath.Replace("Blue", "Green")

 Write-Host $item 

}

Posted in: IIS7 , PowerShell  Tags: , ,
Dan posted on March 22, 2010 07:41

I came across an interesting problem today whilst working on a new build IIS7 server with SQL Server 2008 reporting services.  No matter what I tried navigating to the reports directory resulted in a:

HTTP Error 503. The service is unavailable.

After working through a few tests like putting a basic aspx file in the application reports directory, checking permissions, application pools to no avail I wondered what could be wrong.

SQL Server Reporting was installed but not running so the "reports" problem was sounding suspicious.

Work around:

  1. Run "Reporting Services Configuration Manager"
  2. If reporting services are disabled you'll need to run them for a minute
  3. Click on "Report Manager URL" , change it something else and apply
  4. You can now disable reporting services if need be

    image

Problem solved, hope this helps someone else!


Posted in: IIS7 , SQL Server 2008  Tags: ,

Calendar

«  May 2012  »
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
View posts in large calendar

Recent Comments

Banners

Theme Grabber
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 Dan Gibbons .Net Developer