0

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?

Manjunath Rao
  • 1,397
  • 4
  • 26
  • 42
  • how would it access the net share? – 4c74356b41 Feb 26 '18 at 16:02
  • I would suggest running these commands from inside the VM itself so you can troubleshoot further. Once you confirm the commands work when running inside the VM you can implement them via CSE (Custom Script Extension) – micahmckittrick Feb 26 '18 at 18:33
  • The VM is exposed to the internet. I can see the script downloaded inside the virtual machine. I have manually executed the script (downloaded inside the VM via CSE) and it works. However, when the CSE runs the script, only the first line is executed and the other two lines do not get executed. – Manjunath Rao Feb 27 '18 at 06:16
  • I suspect the lines do get executed but are failing? You can add the -Debug switch to the cmdlet and see what the log says... Also, the CSE will run under the local system account - does that account have access to the admin file share on the other machine? – bmoore-msft Feb 27 '18 at 17:11

2 Answers2

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.

Shadar
  • 21
  • 2
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:

enter image description here

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.

Community
  • 1
  • 1
Jason Ye
  • 13,710
  • 2
  • 16
  • 25
  • Okay I will try this work around and let you know if it works. However, keeping an exec file in storage will cost me money plus I will have to download that file each time when I provision a new server. The solution I have will copy the exe file from a jump host to the server , which will be in same VNET. – Manjunath Rao Feb 27 '18 at 09:18
  • @ManjunathRao OK, please try it, Azure storage account is very cheap. Also you can use jump host to copy that file. Please let me know if you need more help:) – Jason Ye Feb 27 '18 at 09:24
  • The workaround is successful, however, I would like to copy the MSI file from my jump server to the new server using "copy-item". – Manjunath Rao Feb 27 '18 at 14:33