Unfortunately, it isn't possible to load the IIS provider as the same thing on both 2008 and 2008R2. On 2008 the IIS provider is provided as only a snapin, and on 2008R2 it is provided as only a module.
With a little bit of coding, you can actually determine which to use, and dynamically load the module or snapin in your script, depending on which is necessary. I took this code from http://forums.iis.net/t/1166784.aspx when I was having a similar problem.
$ModuleName = "WebAdministration"
$ModuleLoaded = $false
$LoadAsSnapin = $false
if ($PSVersionTable.PSVersion.Major -ge 2) {
if ((Get-Module -ListAvailable | ForEach-Object {$_.Name}) -contains $ModuleName) {
Import-Module $ModuleName
if ((Get-Module | ForEach-Object {$_.Name}) -contains $ModuleName) {
$ModuleLoaded = $true
} else {
$LoadAsSnapin = $true
}
} elseif ((Get-Module | ForEach-Object {$_.Name}) -contains $ModuleName) {
$ModuleLoaded = $true
} else {
$LoadAsSnapin = $true
}
} else {
$LoadAsSnapin = $true
}
if ($LoadAsSnapin) {
if ((Get-PSSnapin -Registered | ForEach-Object {$_.Name}) -contains $ModuleName) {
Add-PSSnapin $ModuleName
if ((Get-PSSnapin | ForEach-Object {$_.Name}) -contains $ModuleName) {
$ModuleLoaded = $true
}
} elseif ((Get-PSSnapin | ForEach-Object {$_.Name}) -contains $ModuleName) {
$ModuleLoaded = $true
}
}
Before attempting to do anything with the IIS provider, check to ensure that $ModuleLoaded
is true, and you should be good to go.