Unable to copy files using Azure Custom script extension

你离开我真会死。 提交于 2019-12-24 23:14:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!