Special characters in powershell via QEMU agent

Furthick

New Member
Jul 9, 2021
3
0
1
29
Hello,
I'm on a symfony project with a php api for proxmox ( https://github.com/CpuID/pve2-api-php-client )
Using QEMU agents, I'm trying to post command in powershell, for example :
powershell.exe Get-DhcpServerv4Scope | Select-Object -Property StartRange,EndRange
But the comma between StartRange and EndRange does not appear and can't be escaped.

Capture d’écran 2021-07-09 165924.png

Thanks for your help.
 
hi,

Using QEMU agents, I'm trying to post command in powershell, for example :
powershell.exe Get-DhcpServerv4Scope | Select-Object -Property StartRange,EndRange
But the comma between StartRange and EndRange does not appear and can't be escaped.
could you show us your code?

for me here it works if i try with our qm tool.

for example:
Code:
qm guest exec 2000 -- powershell -c 'Get-ChildItem "Env:" | Select-Object -Property Key,Value'
 
could you show us your code?
"powershell.exe Get-DhcpServerv4Scope | Select-Object -Property StartRange,EndRange" is in $command


PHP:
        $pve2 = new Pve2Api("192.168.100.10", "username", "pve", "password");

        foreach ($tab as $t)
        {
            foreach ($vmTypes as $vm)
            {
                if ($t[$vm->getId()] != null)
                {
                    $instructions = $vm->getInstruction();
                    foreach ($instructions as $instruct)
                    {
                            if ($pve2->login())
                            {
                                $ret2 = array();

                                $vmid = $t[$vm->getId()];

                                $i=0;
                                $vm2 = $pve2->get('/cluster/resources?type=vm');
                                while($vm2[$i]['vmid'] != $vmid)
                                {
                                    $i++;
                                }
                                if ($vm2[$i]['vmid'] == $vmid)
                                {
                                    $node = $vm2[$i]['node'];
                                }
                            }
                        }
                    if ($pve2->login()) {
                            $ret2 = array();

                            $vmid = $t[$vm->getId()];

                            $i=0;
                            $vm2 = $pve2->get('/cluster/resources?type=vm');
                        
                            while($vm2[$i]['vmid'] != $vmid)
                            {
                                $i++;
                            }
                        
                            if ($vm2[$i]['vmid'] == $vmid)
                            {
                                $node = $vm2[$i]['node'];
                            }
                            
                            $ret2['exited'] = 0;
                            $command = $instruct->getCommand()->getCode();

                            $post_array_data = array();
                            $post_array_data['command'] = $command;

                            $ret = $pve2->post("/nodes/".$node."/qemu/".$vmid."/agent/exec", $post_array_data);
                            while ($ret2['exited'] === 0) {
                                $ret2 = $pve2->get("/nodes/".$node."/qemu/".$vmid."/agent/exec-status?pid=".$ret["pid"], $ret);
                            }
                    }
                }
            }
 
API endpoints seem correct from a glance, so it's most likely because of the specific command

"powershell.exe Get-DhcpServerv4Scope | Select-Object -Property StartRange,EndRange" is in $command
could you try with the -c flag for powershell and the rest of your command quoted? (see my example above)

so your command could be powershell -c 'Get-DhcpServerv4Scope | Select-Object -Property StartRange,EndRange'
 

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!