Simon Darlow
Simon Darlow

Reputation: 550

Executing Remote Command via Powershell in Azure with no script

I am trying to setup Azure VM's using Powershell but i wish to do it all remotely with no logging into the machine. I have been able to spin up the VM using commands like New-AzVM but now i need to run specific powershell commands e.g. Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole

I can see you can run remote scripts using the following but as this is a brand new server there are no scripts on that box to execute.

 Invoke-AzVMRunCommand -ResourceGroupName $ResourceGroupName -Name $VmName -CommandId 'RunPowerShellScript' -ScriptPath '<pathToScript>' -Parameter @{"arg1" = "var1";"arg2" = "var2"}

How can i copy scripts to the server remotely so i can use the above command, or run commands without the need for a script file.

Upvotes: 0

Views: 320

Answers (2)

Sharbag
Sharbag

Reputation: 255

What you need is to look into the direction of PowerShell Desired State Configuration (DSC)

  1. Here you can find general explanation for this technology
  2. Get started manual for DSC

Upvotes: 0

Nancy Xiong
Nancy Xiong

Reputation: 28224

You don't need to copy the scripts remotely to the Azure VM. You can run it locally.

Save the PowerShell scripts to a format .ps1 file, then run it on local PowerShell with referencing the path of the script via parameter -ScriptPath.

Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole

You also could copy that scripts on the Virtual machine---Run command---RunPowerShellScript on the Azure portal, refer to this.

Upvotes: 1

Related Questions