3

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
asur
  • 1,759
  • 7
  • 38
  • 81
  • 1
    This looks to be a similar question: http://stackoverflow.com/questions/6866150/powershell-new-webapplication So perhaps the issues is that you need to use 32-bit PowerShell instead of 64-bit Powershell. – Mark Wragg Feb 24 '17 at 12:11
  • How should I execute this using Jenkins Job – asur Feb 24 '17 at 12:13
  • 1
    I'm not a Jenkins expert but I think it has something to do with whether the Jenkins slave is running as 32bit or 64bit. – Mark Wragg Feb 24 '17 at 12:21
  • You may need to do the opposite of what is described here: http://stackoverflow.com/questions/28331924/jenkins-powershell-plugin-is-running-32-bit-powershell-and-i-need-64bit – Mark Wragg Feb 24 '17 at 12:22
  • @Mark I am not able to follow up your mentioned post. Could you please help me here or with more precise steps so that I can follow the same. – asur Feb 28 '17 at 04:05

0 Answers0