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"
Related
So I'm using the inline script on Azure DevOps, what variables or string should I add to continue to the next script once the npm run start completed, because at the moment my pipeline hangs at after starting the script and not gong to the next frontend script :
$backendFolder = "C:\path\to\backend"
$nodejsExecutable = "C:\Program Files\nodejs\npm.cmd"
Set-location $backendFolder
Start-Process -FilePath $nodejsExecutable -ArgumentList "run","build" -wait -NoNewWindow -ErrorAction Stop -Verbose -WorkingDirectory $backendFolder
Start-Process -FilePath $nodejsExecutable -ArgumentList "run","start" -wait -NoNewWindow -ErrorAction Stop -Verbose -WorkingDirectory $backendFolder
What am I missing here?
Notes # I've tried a lot of different combinations of the Start-Process command but still no go, I've also followed a couple of blog post, not going to share each and everyone here, as it's a lot but here is 2 > https://lazyadmin.nl/powershell/start-process/ & https://ss64.com/ps/
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
This code:
$username = 'Username'
$password = 'Password'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process -FilePath powershell -WorkingDirectory "$env:ALLUSERSPROFILE" -Credential $credential -WindowStyle Hidden -ArgumentList "-NoProfile -Command `"Start-Process -FilePath wscript -Verb RunAs -ArgumentList '\`"$((Get-Location).Path -replace "'", "''")\test.vbs\`" \`"/CurrentDirectory:$((Get-Location).Path -replace "'", "''")\`" \`"/AppData:$($env:APPDATA -replace "'", "''")\`"'`""
works when I run it line by line from the PowerShell command prompt.
The problem occurs both when I associate the .ps1 extension to "Windows PowerShell" and then double-click on the script, and when I compile the script in .exe through IronMan Software's "PSScriptPad".
A similar problem is present at the following link:
Powershell script executes correctly when I choose "run with powershell", but not when I "open with" powershell or double-click it
but in my case it doesn't even work with "Run with PowerShell" and perhaps the cause of the problem is the same one that also affects executables.
Another useful link is the following:
https://stackoverflow.com/a/58245206/45375
How can I solve the problem?
Windows 10 Pro 64-bit
Powershell Version: 5.1.19041.1237 (Integrated in Windows 10).
The compiled executable works correctly when it is not in a directory containing the apostrophe characters while in the case of double-clicking on a .ps1 script, the directory containing it cannot even contain spaces.
This is a useful link:
https://social.technet.microsoft.com/Forums/en-US/bf3344de-3af6-48e3-9f43-f595bb41c62d/bug-powershell-starts-w-error-when-opened-by-context-menu-in-folder-w-apostrophe-in-its-name?forum=win10itprogeneral
For the apostrophes path problem in .exe files, I sent a bug report to IronMan Software PSScriptPad, which was then taken care of.
For the problem of paths with apostrophes or consecutive whitespaces when double-clicking or doing "Run with PowerShell" on .ps1 scripts, I have solved by fixing the following registry values:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.ps1]
#="Microsoft.PowerShellScript.1"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command]
#="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -NoExit -Command \"Set-Location -LiteralPath \\\"%V\\.\\\"\""
[HKEY_CLASSES_ROOT\Directory\Shell\Powershell\command]
#="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -NoExit -Command \"Set-Location -LiteralPath \\\"%V\\.\\\"\""
[HKEY_CLASSES_ROOT\Drive\shell\Powershell\command]
#="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -NoExit -Command \"Set-Location -LiteralPath \\\"%V\\.\\\"\""
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\DefaultIcon]
#="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\",0"
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
#="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Command \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force }; & \\\"%1\\\"\""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\0\Command]
#="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Command \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force }; & \\\"%1\\\"\""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\Edit\Command]
#="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell_ise.exe\" -File \"%1\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
"ExecutionPolicy"="RemoteSigned"
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
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 ]]