Azure Devops IIS web app manage failed with powershell error

Viewed 777

I have a release pipeline in Azure Devops that without any changes stop working. The task where my pipeline fails is a "IIS web app manage" task, where I do a AppPool stop enter image description here

The error that I get is

Exit code 1 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if ([Console]::InputEncoding -is [Text.UTF8Encoding] -and [Console]::InputEncoding.GetPreamble().Length -ne 0) { [Console]::InputEncoding = New-Object Text.UTF8Encoding $false } if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name 'C:\azagent\A3\_work\_tasks\IISWebAppManagementOnMachineGroup_1b2aec60-dc49-11e6-9b76-63056e018cac\0.5.15\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList @{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\azagent\A3\_work\_tasks\IISWebAppManagementOnMachineGroup_1b2aec60-dc49-11e6-9b76-63056e018cac\0.5.15\IISWebAppManagementOnMachineGroup.ps1'''))"'.

But the interessting thing is that the App pool is stopped and the pipeline works fine until 2 days ago. No changes on the pipeline and on the destination folder. Recreated also the tragets in the deployment groups.

Thanks for any hint.

##UPDATE: LOGS

2021-09-29T15:43:11.3350887Z ##[section]Starting: Stop IIS
2021-09-29T15:43:11.3523223Z ==============================================================================
2021-09-29T15:43:11.3523551Z Task         : IIS web app manage
2021-09-29T15:43:11.3523878Z Description  : Create or update websites, web apps, virtual directories, or application pools
2021-09-29T15:43:11.3524171Z Version      : 0.5.15
2021-09-29T15:43:11.3524416Z Author       : Microsoft Corporation
2021-09-29T15:43:11.3524782Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/iis-web-app-management-on-machine-group
2021-09-29T15:43:11.3525169Z ==============================================================================
2021-09-29T15:43:15.0041212Z ##[command]"C:\Windows\system32\inetsrv\appcmd.exe" stop apppool /apppool.name:"MYHOST"
2021-09-29T15:43:15.0731119Z "MYHOST" successfully stopped
2021-09-29T15:43:15.1615455Z ##[error]Exit code 1 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if ([Console]::InputEncoding -is [Text.UTF8Encoding] -and [Console]::InputEncoding.GetPreamble().Length -ne 0) { [Console]::InputEncoding = New-Object Text.UTF8Encoding $false } if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name 'C:\azagent\A3\_work\_tasks\IISWebAppManagementOnMachineGroup_1b2aec60-dc49-11e6-9b76-63056e018cac\0.5.15\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList @{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\azagent\A3\_work\_tasks\IISWebAppManagementOnMachineGroup_1b2aec60-dc49-11e6-9b76-63056e018cac\0.5.15\IISWebAppManagementOnMachineGroup.ps1'''))"'.
2021-09-29T15:43:15.1631012Z ##[section]Finishing: Stop IIS

enter code here
1 Answers

Thanks shayki abramczyk, It looks like your IT Team has put some security in the computers that blocked running some PowerShell scripts (maybe only it from remote).

Try to run it in your PowerShell:

$ExecutionContext.SessionState.LanguageMode

I guess you will get this output:

ConstrainedLanguage

If yes, try to switch it to FullLanguage:

$ExecutionContext.SessionState.LanguageMode = "FullLanguage"

If it doesn't help maybe it's also blocked, so you need to talk with IT Team that will change it or try to change the registry like explained here or set the environment variable __PSLockdownPolicy to 0.

Please check SO link for reference

Related