-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTutorial.dib
More file actions
123 lines (68 loc) · 2.41 KB
/
Copy pathTutorial.dib
File metadata and controls
123 lines (68 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!meta
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"name":"csharp"}]}}
#!markdown
# Hello World
## What do you do with this notebook?
This notebook is intended to help you learn use the PowerShell for Proxmox VE. You can:
- Work through these notebooks on your own.
- Use these notebooks as prompts to write your own code
## What is PowerShell?
[PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/overview) is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS.
## Operation
Proxmox VE provides [Web Api](https://pve.proxmox.com/wiki/Proxmox_VE_API), in order to automate processes.
The use of Api requires access, and is possible through:
- login with user and password and generate a token
- using api-token
#!markdown
## Installing the module From PowerShell Gallery
#!pwsh
Install-Module -Name Corsinvest.ProxmoxVE.Api
# Update module
# Update-Module -Name Corsinvest.ProxmoxVE.Api
# Show Version
Get-Module -list -Name Corsinvest.ProxmoxVE.Api
#!markdown
## Connection Cluster
#!pwsh
# Connection with username and password
# Remeber to change ip address and user. On prompt insert password and press enter
Connect-PveCluster -HostsAndPorts 10.92.90.101 -SkipCertificateCheck -Credentials (Get-Credential -UserName root)
#!pwsh
# Alternative mode to connect
# Connection with ApiToken
Connect-PveCluster -HostsAndPorts 10.92.90.101 -SkipCertificateCheck -ApiToken root@pam!qqqqqq=8a8c1cd4-d373-43f1-b366-05ce4cb8061f
#!markdown
The values of the response (Ticket, CSRFPreventionToken, ApiToken), are saved in the global variable **$PveTicketLast**
#!markdown
## Execute command
Get version of node
#!pwsh
Get-PveVersion
#!markdown
The response contain:
- **StatusCode** Status code of response [Http](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
- **Response** Contain real response of Proxmox VE, is converted in object Json response
#!pwsh
$ret = Get-PveVersion
#!markdown
Print data
#!pwsh
$ret.Response.data
#!markdown
Print data tabulated
#!pwsh
$ret.ToTable()
#!markdown
Export data to Cvs
#!pwsh
$ret.ToCsv("pippo.cvs")
#!markdown
Show nodes
#!pwsh
(Get-PveNodes).ToTable()
Get-PveNode
#!markdown
Get snapshot of VM/CT with number 100
#!pwsh
#Change number vm
(Get-PveVMSnapshot -VmIdOrName 100).ToTable()