Page 2 of 2

PowerCLI 10 On A Raspberry PI

First things first I am a big fan on the raspberry PI and have more or less every iteration scattered around the house doing different jobs. In fact i tend to use one for access to my home lab using either a ssh session or via xrdp to a nice xfce session via tightvnc (maybe thats for another blog post).

However running PowerCLI on it never occurred until recently.  So i though why not try it so here goes..

Assuming your running Raspbian Stretch on a PI 3

Microsoft have kindly given some nice instructions on how to install PowerShell on the Raspberry PI and others at: Microsoft Link (I made a change to the below as we need version v6.0.1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Install prerequisites
sudo apt-get install libunwind8

# Grab the latest tar.gz (Changed as PowerCLI needs v6.0.1)
wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.1/powershell-6.0.1-linux-arm32.tar.gz

# Make folder to put powershell
mkdir ~/powershell

# Unpack the tar.gz file
tar -xvf ./powershell-6.0.1-linux-arm32.tar.gz -C ~/powershell

# Start PowerShell
~/powershell/pwsh

This gets up PowerShell up and running now all we need to do is install the PowerCLI modules. Again VMware this time have provided some instructions at VMware Link

1
2
#Install PowerCLI Module
Install-Module -Name VMware.PowerCLI -Scope CurrentUser

It Takes a little while to run, then you need to give it permission to do the install (Press Y)

And that is it, we can now use PowerCLI from our Raspberry PI

PowerCLI Enable SSH On A Host

Must admit there comes a time when you need to enable SSH on an ESXi host and i for one find navigating the GUI a bit time consuming and to be honest not really necessary.

To that matter using good old PowerCLI we can enable ssh on a host with a very simple command line

1
Get-VMHost HostName | Get-VMHostService | Where Key -EQ "TSM-SSH" | Start-VMhostService

And then once we are finished its good practise to disable SSH once again.

1
Get-VMHost HostName | Get-VMHostService | Where Key -EQ "TSM-SSH" | Stop-VMHostService -Confirm:$False

 

PowerCLI VMtools Update on Reboot

Easy task for today was to set all the virtual machines to auto update the VMware tools on next reboot, we could of course manually use the webclient on each virtual machine but that is a bit time consuming, so we may as well use some PowerCLI to get the job done.

Here is some quick code to do the job.

1
2
3
4
5
6
7
Foreach ($VMS in (Get-VM)) {
$VM = $VMS | Get-View
$VMConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$VMConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$VMConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$VM.ReconfigVM($vmConfigSpec)
}

 

 

 

 

PowerCli Eager Zero To Thin

Well job for today was to convert a load of virtual machines from good old eager zero to thin, now the hard way to do this is to do every one individually by hand.. As you can imagine that not exactly a good use of our time so lets automate this process and give ourselves some time for a coffee instead.

The code below is really very basic but does the job, its a straight forward storage vMotion between 2 datastores to do the conversion process and then a nice move back to the original store (in essence we are using the $THINSTORE as a bit of a buffer).

1
2
3
4
5
6
7
8
9
10
11
12
$THICKSTORE = "thick"
$THINSTORE = "thin"
$VMs = Get-datastore | Where {$_.name -like $THICKSTORE } | Get-VM

Foreach ($VM in $VMs){
Write-Host "VM: "$VM "Moving from: "$THICKSTORE "To: " $THINSTORE
Move-VM $VM -Datastore $THINSTORE -DiskStorageFormat Thin

# NOW its Thin move it back to original store
Write-Host "VM: "$VM "Moving from: "$THINSTORE "To: " $THICKSTORE
Move-VM $VM -Datastore $THICKSTORE
}

Well it seems to have done the trick so guess i am due that coffee now.

Newer posts »