[GH-ISSUE #14] Windows Specific command execution #10

Closed
opened 2026-02-26 17:32:06 +03:00 by kerem · 5 comments
Owner

Originally created by @AdminSecNum on GitHub (Jan 30, 2024).
Original GitHub issue: https://github.com/Corsinvest/cv4pve-api-powershell/issues/14

What happened?

Hello, I have a few questions.

I'm coming from VMware and was using PowerCLI to do my VM creation + configuration.

However with ( cv4pve-api-powershell | PVE-API ) I encounter some problems:

1 - I have the impression that anything related to url encoding is prohibited.
1.1 - For example if I have a password like "P@s+w0r&&rd!", I receive a failed authentication; if I use "P@ssw0rd!" No problem

How to avoid this kind of problem? (For example passwords are generated randomly and removing possible chars from url encoding is not an option)

2 - Sending a command does not allow you to send a group of commands:

$Cmd3 = @"
touch /home/manager/pve3
echo 'test' > /home/manager/pve3
"@

New-PveNodesQemuAgentExec -PveTicket $PveTicket `
                           -Node $Node_Name `
                           -Vmid 500 `
                           -Command $Cmd3

Same as for point 1, if I use &&

New-PveNodesQemuAgentExec -PveTicket $PveTicket `
                           -Node $Node_Name `
                           -Vmid 500 `
                           -Command "touch /home/manager/pve4 && echo 'test' > /home/manager/pve4"

How can I send blocks of orders?

The goal being that under Windows if the commands "follow each other" in the terminal I can use the variables sent previously such as for example:

(The tild allows me that powershell does not interpret the variable currently, but that the vm which receives it does (The tild is removed when it is received by the vm) finally it worked under PowerCli->Windows I think that will be the case here too I haven't tested)

`$Username = $Username
`$Password = ConvertTo-SecureString $Password -AsPlainText -Force
`$Credential = New-Object System.Management.Automation.PSCredential(`$Username, `$password)
Start-Process Executable1.exe -Credential `$Credential

the try with

New-PveNodesQemuAgentFileWrite

Work for the cmd3 example but not with the Tild example

The final goal is to be able to fully configure a Windows server, for example, via this API:

  • Create the VM
  • Configure the vm (Host name, network, Disk, etc.)
  • Add and configure the role (Active Directory for example)

Perhaps one or more elements are the "fault" of the PVE API and necessarily of the Powershell module, I'm just trying to understand how to migrate my massive scripts to this module without "too much" change.

Even if I more or less understood that the simplest would be to send the scripts 1 by 1 to the VM rather than direct execution through the API.

Expected behavior

N/A

Relevant log output

No response

Proxmox VE Version

5.15.131-3

Version (bug)

1.0.0

Version (working)

No response

On what operating system are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request
Originally created by @AdminSecNum on GitHub (Jan 30, 2024). Original GitHub issue: https://github.com/Corsinvest/cv4pve-api-powershell/issues/14 ### What happened? Hello, I have a few questions. I'm coming from VMware and was using PowerCLI to do my VM creation + configuration. However with ( cv4pve-api-powershell | PVE-API ) I encounter some problems: 1 - I have the impression that anything related to url encoding is prohibited. 1.1 - For example if I have a password like "P@s+w0r&&rd!", I receive a failed authentication; if I use "P@ssw0rd!" No problem How to avoid this kind of problem? (For example passwords are generated randomly and removing possible chars from url encoding is not an option) 2 - Sending a command does not allow you to send a group of commands: ``` $Cmd3 = @" touch /home/manager/pve3 echo 'test' > /home/manager/pve3 "@ New-PveNodesQemuAgentExec -PveTicket $PveTicket ` -Node $Node_Name ` -Vmid 500 ` -Command $Cmd3 ``` Same as for point 1, if I use && ``` New-PveNodesQemuAgentExec -PveTicket $PveTicket ` -Node $Node_Name ` -Vmid 500 ` -Command "touch /home/manager/pve4 && echo 'test' > /home/manager/pve4" ``` How can I send blocks of orders? The goal being that under Windows if the commands "follow each other" in the terminal I can use the variables sent previously such as for example: (The tild allows me that powershell does not interpret the variable currently, but that the vm which receives it does (The tild is removed when it is received by the vm) finally it worked under PowerCli->Windows I think that will be the case here too I haven't tested) ``` `$Username = $Username `$Password = ConvertTo-SecureString $Password -AsPlainText -Force `$Credential = New-Object System.Management.Automation.PSCredential(`$Username, `$password) Start-Process Executable1.exe -Credential `$Credential ``` the try with ``` New-PveNodesQemuAgentFileWrite ``` Work for the cmd3 example but not with the Tild example The final goal is to be able to fully configure a Windows server, for example, via this API: - Create the VM - Configure the vm (Host name, network, Disk, etc.) - Add and configure the role (Active Directory for example) Perhaps one or more elements are the "fault" of the PVE API and necessarily of the Powershell module, I'm just trying to understand how to migrate my massive scripts to this module without "too much" change. Even if I more or less understood that the simplest would be to send the scripts 1 by 1 to the VM rather than direct execution through the API. ### Expected behavior N/A ### Relevant log output _No response_ ### Proxmox VE Version 5.15.131-3 ### Version (bug) 1.0.0 ### Version (working) _No response_ ### On what operating system are you experiencing the issue? Windows ### Pull Request - [ ] I would like to do a Pull Request
kerem closed this issue 2026-02-26 17:32:06 +03:00
Author
Owner

@franklupo commented on GitHub (Jan 31, 2024):

Hi,
the version of Proxmox VE you are using is no longer supported. I advise you to update it to 8.
As regards the commands you need to read the Promoxm VE API documentation https://pve.proxmox.com/pve-docs/api-viewer/

best reagrds

<!-- gh-comment-id:1918937128 --> @franklupo commented on GitHub (Jan 31, 2024): Hi, the version of Proxmox VE you are using is no longer supported. I advise you to update it to 8. As regards the commands you need to read the Promoxm VE API documentation https://pve.proxmox.com/pve-docs/api-viewer/ best reagrds
Author
Owner

@AdminSecNum commented on GitHub (Feb 1, 2024):

Proxmox updated in 8.1.4, but still the same Exception: authentication failure with complex password with + or # and &

Can be solved with :

$PVE_Pass = [uri]::EscapeDataString('@b3kpJFY^$HLWVM{TpVL#+&')
<!-- gh-comment-id:1920926785 --> @AdminSecNum commented on GitHub (Feb 1, 2024): Proxmox updated in 8.1.4, but still the same `Exception: authentication failure` with complex password with `+` or `#` and `&` Can be solved with : ``` $PVE_Pass = [uri]::EscapeDataString('@b3kpJFY^$HLWVM{TpVL#+&') ```
Author
Owner

@AdminSecNum commented on GitHub (Feb 1, 2024):

Trying to pass command with argument not work

New-PveNodesQemuAgentExec -PveTicket $PveTicket `
                          -Node $Node_Name `
                          -Vmid 200 `
                          -Command @('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', '-Command', 'echo', 'test')
Response            : 
StatusCode          : 500
ReasonPhrase        : Agent error: Guest agent command failed, error was 'Failed to execute child process (Invalid argument)'
IsSuccessStatusCode : False
RequestResource     : /nodes/XXXXX/qemu/200/agent/exec
Parameters          : {[command, System.Object[]]}
Method              : Post
ResponseType        : json

I can see in the debug log on the windows machine no argument are passed

1706799305.640347: debug: read data, count: 223, data: {"arguments":{"id":1180076},"execute":"guest-sync-delimited"}
{"arguments":{"path":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -Command echo test","capture-output":true,"arg":[]},"execute":"guest-exec"}

In PVE shell with

qm guest exec 200 -- 'powershell.exe' '-Command' 'echo' 'test'

i can retrieve the args

1706800669.536899: debug: read data, count: 181, data: {"arguments":{"id":17594202},"execute":"guest-sync-delimited"}
{"execute":"guest-exec","arguments":{"path":"powershell.exe","arg":["-Command","echo","test"],"capture-output":true}}

Any advice ?

<!-- gh-comment-id:1921387465 --> @AdminSecNum commented on GitHub (Feb 1, 2024): Trying to pass command with argument not work ``` New-PveNodesQemuAgentExec -PveTicket $PveTicket ` -Node $Node_Name ` -Vmid 200 ` -Command @('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', '-Command', 'echo', 'test') ``` ``` Response : StatusCode : 500 ReasonPhrase : Agent error: Guest agent command failed, error was 'Failed to execute child process (Invalid argument)' IsSuccessStatusCode : False RequestResource : /nodes/XXXXX/qemu/200/agent/exec Parameters : {[command, System.Object[]]} Method : Post ResponseType : json ``` I can see in the debug log on the windows machine no argument are passed ``` 1706799305.640347: debug: read data, count: 223, data: {"arguments":{"id":1180076},"execute":"guest-sync-delimited"} {"arguments":{"path":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -Command echo test","capture-output":true,"arg":[]},"execute":"guest-exec"} ``` In PVE shell with ``` qm guest exec 200 -- 'powershell.exe' '-Command' 'echo' 'test' ``` i can retrieve the args ``` 1706800669.536899: debug: read data, count: 181, data: {"arguments":{"id":17594202},"execute":"guest-sync-delimited"} {"execute":"guest-exec","arguments":{"path":"powershell.exe","arg":["-Command","echo","test"],"capture-output":true}} ``` Any advice ?
Author
Owner

@franklupo commented on GitHub (Feb 12, 2024):

Proxmox updated in 8.1.4, but still the same Exception: authentication failure with complex password with + or # and &

Can be solved with :

$PVE_Pass = [uri]::EscapeDataString('@b3kpJFY^$HLWVM{TpVL#+&')

now add support encription password

<!-- gh-comment-id:1938911415 --> @franklupo commented on GitHub (Feb 12, 2024): > Proxmox updated in 8.1.4, but still the same `Exception: authentication failure` with complex password with `+` or `#` and `&` > > Can be solved with : > > ``` > $PVE_Pass = [uri]::EscapeDataString('@b3kpJFY^$HLWVM{TpVL#+&') > ``` now add support encription password
Author
Owner

@franklupo commented on GitHub (Feb 13, 2024):

Fix in new version

<!-- gh-comment-id:1941427258 --> @franklupo commented on GitHub (Feb 13, 2024): Fix in new version
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cv4pve-api-powershell#10
No description provided.