Azure Pipeline Extract Task 7zip - azure

Unable to extract zip to destination with default usage of Extract Task its fails with error:
##[error]Unable to locate executable file: 'C:\azagent\A5\_work\_tasks\ExtractFiles_5e1e3830-fbfb-11e5-aab1-090c92bc4988\1.200.0\7zip\7z.exe'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
Stating its fails to locate default 7zip path. Tried to use custom PATH setting but also fails with the same error.
UPDATE
Issue seem to be caused by permissions of agent. Still haven't been able to execute Release with Admin privileges in service mode. When run in interactive mode as Admin the release executes successfully.
Task fails whenever admin permission is required.

From the error message, 7zip seems not installed on your self-hosted agent. Try to install the 7zip before you use the Extract Task.
Take Bash Task as an example:
brew install p7zip
For Windows, use the below PowerShell script to install:
$dlurl = 'https://7-zip.org/' + (Invoke-WebRequest -UseBasicParsing -Uri 'https://7-zip.org/' | Select-Object -ExpandProperty Links | Where-Object {($_.outerHTML -match 'Download')-and ($_.href -like "a/*") -and ($_.href -like "*-x64.exe")} | Select-Object -First 1 | Select-Object -ExpandProperty href)
# modified to work without IE
# above code from: https://perplexity.nl/windows-powershell/installing-or-updating-7-zip-using-powershell/
$installerPath = Join-Path $env:TEMP (Split-Path $dlurl -Leaf)
Invoke-WebRequest $dlurl -OutFile $installerPath
Start-Process -FilePath $installerPath -Args "/S" -Verb RunAs -Wait
Remove-Item $installerPath

Related

Unable to run command using Azure scale set extension for Windows

I am using terraform to Launch some Azure Scale set for windows. I have wrote below code for updating the dynamic IP of the VM created by the terraform.
publisher = "Microsoft.Compute"
settings = jsonencode({
commandToExecute = "powershell.exe (((Get-Content -path C:\\Nomad\\agent\\agent.hcl -Raw) -replace '108.98.16.4','${data.azurerm_network_interface.main.private_ip_address}'| Set-Content -Path C:\\Nomad\\agent\\agent.hcl) | sc.exe start Nomad"
})
But its throwing below error :
Error: Code="VMExtensionProvisioningError" Message="VM has reported a
failure when processing extension 'joinNomadNodes'. Error message:
\"Command execution finished, but failed because it returned a
non-zero exit code of: '255'. The command had an error output of:
''Set-Content' is not recognized as an internal or external
command,\r\noperable program or batch file.\r\n'\"\r\n\r\nMore
information on troubleshooting is available at
https://aka.ms/VMExtensionCSEWindowsTroubleshoot "
Now if i am running the command manually its running without any error:
powershell.exe (((Get-Content -path C:\\Nomad\\agent\\agent.hcl -Raw) -replace '108.98.16.4','178.98.16.5'| Set-Content -Path C:\\Nomad\\agent\\agent.hcl) | sc.exe start Nomad"
I have added the escape char "^" just before the "|" .. Now its running fine.
publisher = "Microsoft.Compute"
settings = jsonencode({
commandToExecute = "powershell.exe (((Get-Content -path C:\Nomad\agent\agent.hcl -Raw) -replace '108.98.16.4','${data.azurerm_network_interface.main.private_ip_address}'^| Set-Content -Path C:\Nomad\agent\agent.hcl) ^| sc.exe start Nomad)"
})

unable to append data to sharepoint file via Azure Automation

Ok I have asked a question like this but now I am trying to perform the task via Azure Automation. I can connect to the SharePoint site via Azure Automation (powershell). with the correct credentials. I can download the file and append data to it. But I can when I try and upload the file back to SharePoint it adds the contents 3 times and then Azure Automation suspends the Runbook after 3 times.
It does run perfect if I upload this file as a different file name.
$siteurl="https://abc.sharepoint.com/sites/xxx/teamsites/os"
$credSP = Get-AutomationPSCredential -Name 'test'
$fileFolder = "$Env:temp"
Connect-PnPOnline -Url $siteurl -Credentials $credSP
Get-PnPFile -Url "/sites/xxx/teamsites/os/Directory and Operating
Systems/test.csv" -Path $fileFolder -Filename test.csv -AsFile -Force
$test = "31-07-2019 -11:35"
Add-Content -Path $fileFolder\test.csv $test
Add-PnPFile -Path $fileFolder\test.csv -Approve -Folder "Directory and
Operating Systems" #-ErrorAction Ignore
Here are the results
test test
31-07-2019 -11:35
31-07-2019 -11:35
31-07-2019 -11:35
As you can see it added $test 3 times. But I dont have this issue if I upload it as a new file name.
Ok after a while I have fix the issue.
After the add-pnpfile ...... you pipe it to | out-null
Thats it. the sript stops after it uploads ,
happy days

Running an EXE from azure blob storage with a configuration xml

could someone please help me with this? I have issues running an EXE from azure blob storage combined with a configuration file. The exe is called from the blob and then needs an argument that calls an xml configuration file in the same blob directory as the exe file. The exe is called fine but the config file is not. Any ideas?
If i run the c:\temp\setup.exe /configure configuration.xml it runs fine so i'm really not sure?
$Path = $env:TEMP
$Installer = "setup.exe"
$OfficeConfig = "configuration.xml"
Invoke-WebRequest "https://********.blob.core.windows.net/office1/setup.exe?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-16T16:00:03Z&st=2019-07-16T08:00:03Z&spr=https&sig=7sO7m3PJMne8hFYAwHY6YFZZG6AfUuhC8x%2BoR7QkWuY%3D" -OutFile $Path\$Installer
Invoke-WebRequest "https://********.blob.core.windows.net/office1/Configuration.xml?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-16T16:00:03Z&st=2019-07-16T08:00:03Z&spr=https&sig=7sO7m3PJMne8hFYAwHY6YFZZG6AfUuhC8x%2BoR7QkWuY%3D" -OutFile $Path\$OfficeConfig
Start-Process -FilePath $Path\$Installer -Argumentlist'/configure $Path\$OfficeConfig' -Verb RunAs -Wait
Remove-Item $Path\$Installer
You should change the single quote to double quote for the -Argumentlist parameter in the Start-Process cmdlet, like below:
change -Argumentlist '/configure $Path\$OfficeConfig' to -Argumentlist "/configure $Path\$OfficeConfig"

How to hide console output from Select-AzureRmSubscription

Does anyone know how to hide output from command Select-AzureRmSubscription inside azure workbook which runs as powershell workflow
Thanks
You can use Out-Null. Works for any PowerShell cmdlet.
Select-AzureRmSubscription | Out-null
The Out-Null cmdlet sends its output to NULL, in effect, removing it
from the pipeline and preventing the output to be displayed at the
screen.
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/out-null
Select-AzSubscription -SubscriptionId $s.Id | Out-Null + ~~~~~~~~ Cannot call the 'Out-Null' command. Other commands from this module have been packaged as workflow activities, but this command was specifically excluded. This is likely because the command requires an interactive Windows PowerShell session, or has behavior not suited for workflows. To run this command anyway, place it within an inline-script (InlineScript { Out-Null }) where it will be invoked in isolation

IIS: how to undeploy/delete/remove a webapp from command line?

Suppose there's a webapp deployed on local IIS server. When I need to remove/undeploy it, I can go to IIS Manager, right-click on the app, and then select "Delete application and content" - et voila. But, I need to do the same from the command line - how? It can be assumed that the name of the application is known.
Maybe this can be done via MSDeploy somehow?
If you just want to remove the application from the Web Site in IIS without physically deleting the files (like msdeploy does) or if you don't have the WebDeploy-extension installed, you can use the following command:
C:\Windows\System32\inetsrv\appcmd.exe delete app "Default Web Site/MyAppName"
This is what did it:
"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy" -verb:delete -dest:apphostconfig="Default Web Site/<webapp_name>"
I know the question says "command line", but you can use PowerShell and the IIS Administration Cmdlets to do this task. I provide all of the functions and explain the process of how to automate this on my blog. Also, you can easily swap out the IIS Administration Cmdlet calls with calls to msdeploy, appcmd, IIsVdir.vbs, etc.
For your specific question, this PowerShell code should do the trick:
$block = {
Import-Module WebAdministration
$website = "YourWebsiteName"
$applicationName = "PathUnderWebsite\ToYourApplication"
$fullPath = Join-Path $website $applicationName
Write-Host "Checking if we need to remove '$fullPath'..."
if (Get-WebApplication -Site "$website" -Name "$applicationName")
{
Write-Host "Removing '$fullPath'..."
Remove-WebApplication -Site "$website" -Name "$applicationName"
}
Write-Host "Deleting the directory '$fullPath'..."
Remove-Item -Path "IIS:\Sites\$fullPath" -Recurse -Force
}
$session = New-PSSession -ComputerName "Your.WebServer.HostName"
Invoke-Command -Session $session -ScriptBlock $block
Remove-PSSession -Session $session
iisweb /delete WebSite [/s Computer [/u [Domain ]User /p Password ]]

Resources