Added VM object

This commit is contained in:
ofilter
2022-04-08 20:02:50 +02:00
parent 8c19676906
commit f13f03bef0
2 changed files with 315 additions and 21 deletions

View File

@@ -4,19 +4,19 @@
## Data storing
### Variable
```ps
```powershell
$x="Text"
```
#### Invoking / Data types
##### String
```ps
```powershell
[string]$x="Text"
```
##### Int
```ps
```powershell
PS C:\Windows\system32> [int]$x=1
PS C:\Windows\system32> [int]$x="1"
PS C:\Windows\system32> [int]$x="1a"
@@ -34,7 +34,7 @@ At line:1 char:1
### Array
```ps
```powershell
$arry = @("a", "b", "c")
```
@@ -44,13 +44,13 @@ $arry = @("a", "b", "c")
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-powershell-1.0/ee692803(v=technet.10)?redirectedfrom=MSDN
```ps
```powershell
[ordered]@{ <name> = <value>; [<name> = <value> ] ...}
```
(By default sorts by values, I believe ordered means the array trust you as the elements are ordered.)
```ps
```powershell
$X = [ordered]@{A=1;C=2;B=3}
```
@@ -59,19 +59,19 @@ $X = [ordered]@{A=1;C=2;B=3}
#### *Normal* Array
```ps
```powershell
@("a", "b", "c")[0]
>> a
```
```ps
```powershell
@("a", "b", "c")[-1 ]
>> c
```
#### Hash array
```ps
```powershell
@{A=1;C=3;B=2}["A"]
>> 1
```
@@ -95,25 +95,25 @@ Write-Host
```
```ps
```powershell
Write-Host "text"
```
#### Write-Output
```ps
```powershell
Write-Output "text"
```
## Filtering
```ps
```powershell
Write-Output "text" | Select-String -pattern $filters -notMatch
```
### Select-Object
```ps
```powershell
Select-Object HostName
```
@@ -121,13 +121,13 @@ Select-Object HostName
### Read file
```ps
```powershell
Get-Content $path
```
### write to file
```ps
```powershell
Write-Host $text | Out-File $path
```
@@ -135,7 +135,7 @@ Write-Host $text | Out-File $path
### Check if last command executed correctly
```ps
```powershell
# Do something
echo $?
```
@@ -150,14 +150,14 @@ echo $?
## Management
### Access remote PS server
```ps
```powershell
Enter-PSSession ComputerName $hostname [-Credential username]
```
> If username gets left behind, the current user will be used
### Send command remotely
```ps
```powershell
Invoke-Command -ComputerName hostname1, hostname2 -ScroptBlock {$COMMAND}
```
@@ -189,12 +189,12 @@ https://xainey.github.io/2016/powershell-classes-and-concepts/#introduction
### Create new host
```ps
```powershell
New-VM -Name "HYPER" -MemoryStartupBytes 512MB
```
### List current VM
```ps
```powershell
Get-VMHost
[[-ComputerName] <String[]>]
[[-Credential] <PSCredential[]>]
@@ -202,6 +202,15 @@ Get-VMHost
```
#### Example
##### Find VM by name
```ps
```powershell
Get-VM -ComputerName Server1
```
# VMWARE
## Connect-VIServer
```powershell
Connect-VIServer
```