To Call a File from Azure VM which resides within it using PowerShell

147 Views Asked by At

How to call a file where the File Path resides in Azure VM Using the Powershell (ISE Locally).

Using Powershell ISE with local computer and trying to call a Ps file which is placed in the Azure Vm.

1

There are 1 best solutions below

10
On BEST ANSWER

If you mean to run an .ps1 file inside the VM, then you can use the PowerShell command Invoke-AzVMRunCommand. You can create a script in your local machine and put the command that you will execute to run the .ps1 inside the VM to the script. For example:

the script script.ps1 in your local machine:

powershell.exe -f 'C:\script_inside_VM.ps1'    # this is the command that will run inside the VM

Use the PowerShell command:

Invoke-AzVMRunCommand -ResourceGroupName groupName -VMName vmName -CommandId 'RunPowerShellScript' -ScriptPath '\path\script.ps1'