I am getting below error while executing below PS script from Jenkins job. Same script runs fine If I execute manually from server. What my script is doing-
I need to check whether if a Site exists in IIS. If exits, then I need to execute PS script if not then I need to create a new IIS website of that name and execute the PS script.
My PS script is
Import-Module WebAdministration
Function WAPublish
{
Param(
[parameter(Mandatory=$true)]
[String]
$RELEASEDIR,
[parameter(Mandatory=$true)]
[String]
$DESTINATION,
[parameter(Mandatory=$true)]
[String]
$SERVER,
[parameter(Mandatory=$true)]
[String]
$SITE,
[parameter(Mandatory=$true)]
[String]
$HostName,
[parameter(Mandatory=$true)]
[String]
$PhysicalPath
)
if(Test-Path IIS:\Sites\$site)
{
Write-Host "The provided website name is $site and it is a valid website`r`n" -ForegroundColor Cyan
Get-ChildItem "$RELEASEDIR\*"
Copy-Item "$RELEASEDIR\*" "\\$SERVER\$DESTINATION" -Force -Recurse
Write-Host "Deployment completed"
invoke-command -computername "$SERVER" -scriptblock {iisreset /RESTART}
}
else
{
Write-Host "There is not a website present in the name provided`r`n" -ForegroundColor Red
New-Item iis:\Sites\$SITE -bindings @{protocol="http";bindingInformation=":80:$HostName"} -physicalPath $PhysicalPath
Get-ChildItem "$RELEASEDIR\*"
Copy-Item "$RELEASEDIR\*" "\\$SERVER\$DESTINATION" -Force -Recurse
Write-Host "Deployment completed"
invoke-command -computername "$SERVER" -scriptblock {iisreset /RESTART}
Exit
}
if ($error) { exit 1 }
}
WAPublish -RELEASEDIR "C:\Location" -DESTINATION "c$\test" -SERVER "$env:WEBAPISERVER" -SITE "$env:SITE" -HostName "$env:HOSTNAME" -PhysicalPath "C:\test"
Error logs-
Time Elapsed 00:00:14.68
[BTP] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\ADMINI~1\AppData\Local\Temp\hudson5229396596966613327.ps1'"
Test-Path : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with
CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered
(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\Release\RPCPS\WebApiPublish-2.ps1:24 char:4
+ if(Test-Path IIS:\Sites\$site)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Test-Path], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.TestPathCommand
Test-Path : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with
CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered
(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\Release\RPCPS\WebApiPublish-2.ps1:24 char:4
+ if(Test-Path IIS:\Sites\$site)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Test-Path], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.TestPathCommand