问题
I want to install tools like NAGIOS inside an Azure virtual machine once it is provisioned. I want to use "Azure Custom Script" to install the tools. Below is the code that I am using.
Powershell script that is being sent as custom script:
new-item "C:\newfile.txt" -Type file
copy-item -Path "\\xxx.xx.x.x\c$\Nagios for windows" -Destination "C:\nagios" -Recurse
Start-Process "c:\nagios\NSCP-0.4.3.143-x64.msi" /qn -Wait
Problem: The first line of code is working (I have it as a sanity check to confirm that the script is indeed working). However, the second and third line is not working (the most important part). I am not seeing any errors in the logs as well. Can someone help me out, please?
回答1:
As a work around, you can upload your file to Azure storage account(Blob, Container), then use PowerShell to download it.
You can create container like this:
Then upload file to that blob via Azure portal.
Then you can use PowerShell command to download it:
Invoke-WebRequest -Uri https://jasondisk2.blob.core.windows.net/msi/01.PNG -outfile 'C:\'
You can add this command to Azure custom script extension.
Hope this helps.
回答2:
just came across this.
To deepen the troubleshooting approach I would suggest you try to run your script as "system" account. You could do this with the psexec tool from the sysinternal suite
You can start a new powershell session with "psexec /s powershell" from an elevated cmd.exe (run as administrator) and run your script as "system".
I assume you will see that the download will fail because of lack of permissions for "system" on the c$ file share on the jumphost.
You can then go ahead and create a new share on the jumphost which is accessible for "Everyone" and try to download the Nagios software from there. It is also good to avoid any spaces and special characters in the share/folder/filename as it always make thinks unnecessary "complex" on the script level.
来源:https://stackoverflow.com/questions/48992248/unable-to-copy-files-using-azure-custom-script-extension