09 August 2023

List all hyper-v host in a scvmm cluster

 Get-SCVMHost -VMHostCluster ( Get-SCVMHostCluster -Name cluster_name) |  Select-Object Name

25 July 2023

Rescan disks remotely for a list of computers

 Get-Content .\records.txt | %{Invoke-Command -ComputerName $PSItem -ScriptBlock {@('RESCAN','EXIT') | diskpart}}

22 February 2023

Define powershell custom objects

 $hash = @{
    Prop1      = 'Value1'
    Prop2      = 'Value2'
    Prop3      = 'Value3'
}

$CustomObject = [pscustomobject]$hash

Powershell generic List

list are allways to be used what the collection has to grow or shrink.

arrays should be used only when the collection have a fixed length and it will not change.


[System.Collections.Generic.List[string]]::new()

[System.Collections.Generic.List[int]]::new()

[System.Collections.Generic.List[Object]]::new()


Powershell - ignoring output performance

 

(Measure-Command -Expression { [void]$(1..100000) }).Milliseconds

53

(Measure-Command -Expression { $null = $(1..100000) }).Milliseconds

49

(Measure-Command -Expression { $(1..100000) > $null }).Milliseconds

62

(Measure-Command -Expression { $(1..100000) | Out-Null }).Milliseconds

393