More Powershell Oneliners - part deux

Hey All,

I thought a new post appropriate since it has been a while since the one I did in the past.

Here is couple new ones
Show listing of the folders in a datastore
Get-ChildItem vmstores:\<vCenter>@443\<Datacenter>\<Datastore>\ | Sort Name | %{$_.Name}

Same Vein longer line - Calculate Folder Size
(Get-ChildItem vmstores:\<vCenter>@443\<DataCenter>\<Datastore>\Folder -recurse | %{$_.Length} | Measure -sum).sum / 1GB

Output looks like this 


So you can use the @{"Name";[Math]::Round("Expression"} setup to format the data as shown in the above link.

Start Services on multiple other computers (SNMP used as an example)

Prepare a list of computers you want to start by either defining them 

$server = "Server A", "Server B", "Server C"

Then run the one liner.

Foreach ($Item in $Server) {get-service -computer $Item | ?{$_.Name -eq "SNMP"}}

Change the Font Colour <-- Yes, spelled right as I am Canadian

[console]::ForegroundColor = "Yellow"

Start SSH on a Host

Get-VMHostService -vmhost <vmHost> | where {$_.Label -match "SSH"} | start-vmhostservice

Stop SSH on a Host

Get-VMHostService -vmhost <vmHost> | where {$_.Label -match "SSH"} | stop-vmhostservice

Count amount of VMs of a certain OS

$(Foreach($vm in $(Get-vm)){$vm | where{$_.ExtensionData.Guest.GuestFullName -match "XP"}}).count

Dump A records in your DNS and display Host and IP Address (Windows 2012 and newer Required)

$(get-dnsserverresourceRecord -ZoneName <Domain> -computername <DNSServer>) | where {$_.RecordType -eq "A"} | select HostName, @{N="IP";E={$_.RecordData | %{$_.IPv4Address}}}

Get NodeWWN and PortWWN on each of the hosts in a cluster

Foreach ($vhost in $(Get-cluster <clusterName> | get-vmhost)) {$vhost | Get-VMHostHBA -type fibrechannel | select VMhost, @{N="NodeWWN";E={"{0:X}"-f$_.NodeWorldWideName}}, @{N="PortWWN";E={"{0:X}"-f$_.PortWorldWideName}}}

Format from Decimal to Hex (where 1740 is the decimal equivalent)

'{0:X4}' -f 1740

More to Come...