Running a PowerShell Command via 'pvesh create exec' Inside a VM

Aug 16, 2024
2
0
1
Good day,

I am trying to run the command "powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:/install/rename_nics.ps1" from the CLI of Proxmox.

When I execute the following:
pvesh create /nodes/$(hostname)/qemu/${VM_ID}/agent/exec --command "powershell.exe" --command "-NoProfile -ExecutionPolicy Bypass -File C:/install/rename_nics.ps1"

It appears to run, and I receive a PID, but then I encounter an error.

It seems like the arguments are not being transferred correctly.
1723844577313.png

at the eventlog:
1723845705123.png

What is the correct way to pass arguments in a command?
 
Last edited:
Hi,

try
Code:
pvesh create /nodes/$(hostname)/qemu/${VM_ID}/agent/exec --command 'powershell.exe' --command 'Set-ExecutionPolicy bypass -scope Process -force; C:\install\rename_nics.ps1'

Regards
 
  • Like
Reactions: razul187

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!