Wednesday Tidbit: Automate VMware OSOT for your VDI Images

The other day I tweeted a short bit of code on how to automate the zeroing-out of your VDI images using SDelete:

I got quite a few DMs afterwards asking if it was possible to do the same with VMware’s OS Optimization Tool.

So without further ado, here’s the code I use as the last step in my Packer builds before closing them down for svMotioning:


$ErrorActionPreference = "Stop"
$webserver = "webserver.contoso.local"
$url = "http://" + $webserver
$files = @("VMwareOSOptimizationTool.exe","VMwareOSOptimizationTool.exe.config","my_osot.xml")
$exe = $files[0]
$arg = "-o -t " + $files[2]
# Verify connectivity
if (Test-Connection $webserver Quiet){
# Get the OSOT files
ForEach ($file in $files)
{
Invoke-WebRequest Uri ($url + "/" + $file) OutFile $env:TEMP\$file
}
} else {
throw "No connection to server. Aborting."
}
# Change to temp folder
Set-Location $env:TEMP
# Run OSOT
Try
{
Start-Process $exe ArgumentList $arg Passthru Wait ErrorAction stop
}
Catch
{
Write-Error "Failed to run OSOT"
Write-Error $_.Exception
Exit -1
}
# Delete files
ForEach ($file in $files)
{
Remove-Item Path $env:TEMP\$file Confirm:$false
}

view raw

osot.ps1

hosted with ❤ by GitHub

Please remember to swap out your web server and to specify your own XML file. You could also YOLO it and use one of the built-in templates…

Bill OReilly Well Do It Live GIF - BillOReilly WellDoItLive Mad GIFs

…but don’t be surprised when you cripple half your apps 🙂

Automating VDI Template Creation with VMware Code Stream and HashiCorp Packer – Part 3: Automating the Solution

In part 2 we automated the installation of our VMware Horizon agents, including AppVolumes and Dynamic Environment Manager. We also patched our template and applied optimization settings using the VMware OSOT fling. In this final part, we automate the entire solution from end-to-end using VMware CI/CD tool, Code Stream. In the end, with one-click, we will generate our template ready for use. Continue reading

Automating VDI Template Creation with VMware Code Stream and HashiCorp Packer – Part 2: Installing the VDI Agents

In part 1 of this series, we built a Windows 10 desktop using HashiCorp Packer. Now we will script the installation of the VDI agents needed for our VMware Horizon environment. After this, we will patch the box with the latest updates, before applying the VMware OS Optimization Tool to produce a lean and clean image. In the last part, we will automate the solution using VMware Code Stream.
Continue reading

Automating VDI Template Creation with VMware Code Stream and HashiCorp Packer – Part 1: Building Windows

In previous consultancies I’ve worked, it was common practice to frequently patch corporate VDI templates. Whilst continuous patching is a good thing, it is quite often laborious. Any attempt to automate this is seen as difficult and organizations often give up and continue with manual processes. Here I will show how it can be done using Code Stream and HashiCorp Packer. Continue reading

Uninstall the Horizon View Toolbox before upgrading your Connection Servers

20151023 - 1Late last year I worked on a vRealize Automation project for customer in the training industry. They required their users to be able to request a Horizon View desktop from the self-service catalog, and subject to approval, one is provisioned. This week I wanted to replicate this in the lab as a full Desktop-as-a-Service model. Continue reading

Implementing a VMware Virtual Desktop Infrastructure with Horizon View 6.2 – Part 7: Load-balancing

20151023 - 1So far in the series we have installed our View Connection Servers and provisioned both desktops and applications. In this part we introduce load-balancing to ensure our requests for resources are equally distributed, and that in the event a Connection Server fails, we can still provision resources to our users.
Continue reading