Documentation de l'API Proxmox : https://pve.proxmox.com/wiki/Proxmox_VE_API
Utilisation avec Powersell :https://github.com/Corsinvest/cv4pve-api-powershell
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet"
Ouvrir une console Powershell
PS > Install-Module -Name Corsinvest.ProxmoxVE.Api
PS> Import-Module Corsinvest.ProxmoxVE.Api PS > $ticket = Connect-PveCluster -HostsAndPorts 10.187.36.13:8006 -SkipCertificateCheck -ApiToken nom_jeton=valeur_jeton #return Ticket, default set $Global:PveTicketLast #this is useful when connections to multiple clusters are needed use parameter -SkipRefreshPveTicketLast # visualiser le ticket PS> $ticket HostName : 1.0xxx.xxx.xxx Port : 8006 SkipCertificateCheck : True CSRFPreventionToken : ApiToken : nom_jeton=valeur_jeton CSRFPreventionToken : #For disable output call Connect-PveCluster > $null #Get version PS > $ret = Get-PveVersion #$ret return a class PveResponse #Show data PS > $ret.Response.data version repoid release ------- ------ ------- 8.1.4 ec5affc9e41f1d79 8.1 #Show data 2 PS /home/frank> $ret.ToTable() version repoid release ------- ------ ------- 8.1.4 ec5affc9e41f1d79 8.1
PS > (Get-PveNodesQemu -node siohyp2 -Full).ToTable() mem diskread status disk cpu diskwrite netout cpus maxmem qmpstatus netin uptime maxdisk name vmid --- -------- ------ ---- --- --------- ------ ---- ------ --------- ----- ------ ------- ---- ---- 0 0 stopped 0 0 0 0 4 2147483648 stopped 0 0 34359738368 WinCouderchon 262 0 0 stopped 0 0 0 0 2 4194304000 stopped 0 0 53687091200 ServeurAD 214 0 0 stopped 0 0 0 0 4 1073741824 stopped 0 0 10737483776 SNS 105
(Get-PveNodeslxc -node siohyp2).ToTable() netin maxmem type uptime maxdisk name vmid mem diskread status diskwrite netout disk cpu swap maxswap cpus ----- ------ ---- ------ ------- ---- ---- --- -------- ------ --------- ------ ---- --- ---- ------- ---- 0 536870912 lxc 0 8589934592 abdessamad.elbouzrati 669 0 0 stopped 0 0 0 0 0 536870912 1 0 536870912 lxc 0 8589934592 debian-client-11 150 0 0 stopped 0 0 0 0 0 536870912 1 0 536870912 lxc 0 8589934592 debian-routeur 166 0 0 stopped 0 0 0 0 0 536870912 1
Afficher que les Vmid
PS C:\Users\boulesteix.fabien> (Get-PveNodeslxc -node siohyp2).response.data | Select-Object vmid
(Get-PvePools).todata()
(Get-PvePools -Poolid nompool).Response.data.members | where-Object type -EQ "qemu" | Select-Object vmid
(Get-PvePools -Poolid nompool).Response.data.members | where-Object type -EQ "lxc" | Select-Object vmid
Remove-PveNodesLxc -DestroyUnreferencedDisks -Force -Node siohyp1 -Purge -Vmid 188 Response : @{data=UPID:siohyp1:00189780:20ABFE12:66DC528F:vzdestroy:188:nom_jeton:} StatusCode : 200 ReasonPhrase : IsSuccessStatusCode : True RequestResource : /nodes/siohyp1/lxc/188 Parameters : {[force, 1], [purge, 1], [destroy-unreferenced-disks, 1]} Method : Delete ResponseType : json
(Get-PvePools -Poolid nom_pool).Response.data.members | where-Object type -EQ "lxc" | Select-Object vmid, node | foreach-object { Remove-PveNodesLxc -DestroyUnreferencedDisks -Force -Node $PSItem.node -Purge -Vmid $PSItem.vmid}
PS > (Get-PvePools).todata() | Where-Object poolid -like "*2022*" | foreach-object {(Get-PvePools -Poolid $PSItem.poolid).Response.data.members } | where-Object type -EQ "lxc" | foreach-object { Remove-PveNodesLxc -DestroyUnreferencedDisks -Force -Node $PSItem.node -Purge -Vmid $PSItem.vmid}
#arrêter les VM (Get-PvePools -Poolid nom_pool).Response.data.members | where-Object type -EQ "qemu" | Select-Object vmid, node | foreach-object { Stop-PveVm -VmIdOrName $PSItem.vmid} #supprimer les VM (Get-PvePools -Poolid nom_pool).Response.data.members | where-Object type -EQ "qemu" | Select-Object vmid, node | foreach-object { Remove-PveNodesQemu -DestroyUnreferencedDisks -Node $PSItem.node -Purge -Vmid $PSItem.vmid}
#Arrêter toutes les VM concernées PS > (Get-PvePools).todata() | Where-Object poolid -like "*2022*" | foreach-object {(Get-PvePools -Poolid $PSItem.poolid).Response.data.members} | where-Object type -EQ "qemu" | Select-Object vmid, node | foreach-object { Stop-PveVm -VmIdOrName $PSItem.vmid} #supprimer toutes les VM concernées PS > (Get-PvePools).todata() | Where-Object poolid -like "*2022*" | foreach-object {(Get-PvePools -Poolid $PSItem.poolid).Response.data.members} | where-Object type -EQ "qemu" | Select-Object vmid, node | foreach-object { Remove-PveNodesQemu -DestroyUnreferencedDisks -Node $PSItem.node -Purge -Vmid $PSItem.vmid}
#Arrêter toutes les VM concernées PS > (Get-PvePools).todata() | Where-Object poolid -like "*2022*" | foreach-object {Remove-PvePools -Poolid $PSItem.poolid } ===== Lister les étudiants d'une promotion ===== <code powershell> PS > (Get-PveAccessusers -full).Response.data | Where-Object groups -eq 'BTSSIO2022' | Select-Object userid userid ------ toto.florian@Valadon tata@Valadon
PS > (Get-PveAccesspermissions -Userid hajji.maryam@Valadon).Response.data