hello
I was hoping to add another server to my IIS environment running windows 2012r2 with Powershell 5.0.10586.117.
my other servers are running Powershell 4.0.
when I try to push out to the new server I get:
VERBOSE: [WEB3]: [[cWebApplication]intranetdev_abc_com_subsitetest_Application] Setting Application Pool for Application subsitetest in site intranetdev.abc.com
to intranetdev.abc.com
Cannot find path ‘IIS:\Sites\intranetdev.abc.com\subsitetest’ because it does not exist.
+ CategoryInfo : ObjectNotFound: (IIS:\Sites\intr…com\subsitetest:) , CimException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand
+ PSComputerName : web3
here is my webapplication.
thanks
function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] param ( [parameter(Mandatory = $true)] [System.String] $Site, [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $PhysicalPath, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [ValidateSet("Present","Absent")] [System.String] $Ensure = 'Present', [ValidateSet('PassThrough','NamedUser')] [System.String] $AuthenticationType = 'PassThrough', [System.String] $UserName = '' ) Write-Verbose "Application: $Site/$Name" #If there's no virtual directory to get, don't panic. $ExistingVirtual = Get-ItemProperty -Path "IIS:\Sites\$Site\$Name" -ErrorAction SilentlyContinue | Where-Object {$_.elementTagName -eq 'application'} # if ($ExistingVirtual) { if ($ExistingVirtual.userName -eq '') {$ExistingAuthType = 'PassThrough'} else {$ExistingAuthType='NamedUser'} Write-Verbose "Status: Present" Write-Verbose "PhysicalPath: $($ExistingVirtual.physicalPath)" Write-Verbose "ApplicationPool: $($ExistingVirtual.applicationPool)" Write-Verbose "UserName: $($ExistingVirtual.userName)" @{ Site=$Site Name=$Name Ensure='Present' PhysicalPath=$ExistingVirtual.physicalPath ApplicationPool=$ExistingVirtual.applicationPool AuthenticationType=$ExistingAuthType UserName = $ExistingVirtual.userName } } else { Write-Verbose "Status: Absent" @{Site=$Site; Name=$Name; Ensure='Absent'} } } function Test-TargetResource { [CmdletBinding()] [OutputType([System.Boolean])] param ( [parameter(Mandatory = $true)] [System.String] $Site, [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $PhysicalPath, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [ValidateSet("Present","Absent")] [System.String] $Ensure = 'Present', [ValidateSet('PassThrough','NamedUser')] [System.String] $AuthenticationType = 'PassThrough', [System.String] $UserName = '' ) Write-Verbose "Getting Target Resource" $Resource = Get-TargetResource -Site $Site -Name $Name -PhysicalPath $PhysicalPath -ApplicationPool $ApplicationPool Write-Verbose "Got Target Resource: $($Resource.Name)" if ($Resource.Ensure -ne $Ensure) { Write-Verbose "Site: $Site" Write-Verbose "Name: $Name" Write-Verbose "Existing Application state $($Resource.Ensure) does not match $Ensure" return $false } if ($Resource.Ensure -eq 'Present') #Only Check additional properties if the Virtual Directory exists. { if ($Resource.PhysicalPath -ne $PhysicalPath) { Write-Verbose "Site: $Site" Write-Verbose "Name: $Name" Write-Verbose "Existing Physical Path '$($Resource.PhysicalPath)' does not match '$PhysicalPath'" return $false } if ($Resource.ApplicationPool -ne $ApplicationPool) { Write-Verbose "Site: $Site" Write-Verbose "Name: $Name" Write-Verbose "Existing Application Pool '$($Resource.ApplicationPool)' does not match '$ApplicationPool'" return $false } if ($Resource.AuthenticationType -ne $AuthenticationType) { Write-Verbose "Site: $Site" Write-Verbose "Name: $Name" Write-Verbose "Physical Path: $PhysicalPath" Write-Verbose "Authentication Type of $($Resource.AuthenticationType) does not match $AuthenticationType" return $false } if ($Resource.UserName-ne $UserName) { Write-Verbose "Site: $Site" Write-Verbose "Name: $Name" Write-Verbose "Physical Path: $PhysicalPath" Write-Verbose "Authentication Type: $AuthenticationType" Write-Verbose "User Name of $($Resource.UserName) does not match $UserName" return $false } } #If there are no issues, return $true. $true } function Set-TargetResource { [CmdletBinding()] param ( [parameter(Mandatory = $true)] [System.String] $Site, [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $PhysicalPath, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [ValidateSet("Present","Absent")] [System.String] $Ensure = 'Present', [ValidateSet('PassThrough','NamedUser')] [System.String] $AuthenticationType = 'PassThrough', [System.String] $UserName = '' ) $Resource = Get-TargetResource -Site $Site -Name $Name -PhysicalPath $PhysicalPath -ApplicationPool $ApplicationPool if ($Ensure -eq 'Present') { if ($Resource.Ensure -ne 'Present' ) #If the Virtual Directory doesn't exist. { Write-Verbose "Creating new Application $Name in site $Site to path $PhysicalPath" New-WebApplication -Site $Site -Name $Name -PhysicalPath $PhysicalPath -ApplicationPool $ApplicationPool } elseif ($Resource.PhysicalPath -ne $PhysicalPath) #If it exists but the path is wrong, delete and recreate { Write-Verbose "Removing Application $Name in site $Site" Remove-WebApplication -Site $site -Name $name Write-Verbose "Creating new Application $Name in site $Site to path $PhysicalPath" New-WebApplication -Site $Site -Name $Name -PhysicalPath $PhysicalPath -ApplicationPool $ApplicationPool } if ($Resource.ApplicationPool -ne $ApplicationPool) { Write-Verbose "Setting Application Pool for Application $Name in site $Site to $ApplicationPool" set-ItemProperty -Path "IIS:\Sites\$Site\$Name" -Name applicationPool -Value $ApplicationPool } if (($AuthenticationType -eq 'PassThrough') -and ($Resource.AuthenticationType -ne $AuthenticationType)) { Write-Verbose "Removing UserName from Application $Name in site $Site to set Pass-Through Authentication." set-ItemProperty -Path "IIS:\Sites\$Site\$Name" -Name userName -Value '' #Null Username is how you set passthrough } if (($AuthenticationType -eq 'NamedUser') -and ($Resource.UserName-ne $UserName)) { Write-Verbose "Setting UserName $UserName on Application $Name in site $Site and disabling Pass-Through Authentication." set-ItemProperty -Path "IIS:\Sites\$Site\$Name" -Name userName -Value $UserName #Setting password is not supported yet } } else #if ($Ensure -eq 'Absent') { Write-Verbose "Removing virtual directory $Name in site $Site" Remove-WebApplication -Site $site -Name $name } } Export-ModuleMember -Function *-TargetResource