dewyser.net

solutions, scripting and more

Documenting, love it or hate it … (Part 2) — 8th Nov 2022

Documenting, love it or hate it … (Part 2)

Part 2: Connection to the Horizon API

To access the Horizon API we need a credential that has read access. Let’s begin …

What I usually do in this scenario is creating an account and saving the password as a secure string in the same location as the script. This method is more secure then passing it along in clear text.

'<password>' | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File ./secure-password.txt

You only need to do this again when your password has changed. Next we will create a credential object that we can use to connect to the Horizon API.

$svc_account_username = '<username>@<domain>'
$svc_account_password = get-content .\secure-password.txt | ConvertTo-SecureString

$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList ($svc_account_username, $svc_account_password)

The next part is actually connecting to the Horizon API using the credential and storing the output in a variable:

$services = Open-HVConnection -HVServer <connection server fully qualified domain name> -Credential $Credential

Last piece of the puzzle is to close the connection and we are done for part 2.

Close-HVConnection -HVServer <connection server fully qualified domain name>

In Part 3 we will have a look at what we received.

Documenting, love it or hate it … (Part 1) — 7th Nov 2022

Documenting, love it or hate it … (Part 1)

In the next series you will see how we can use the VMware Horizon API in combination with some Powershell modules to document the environment.

Part 1: Installing the necessary Tools and Powershell modules

First we need to install Powershell. There or several ways to do so but I tend to turn to Homebrew whenever I can.

Brew Install --cask powershell

PScribo: PScribo provides a set of functions that make it easy to create a document-like structure within Powershell scripts without having to be concerned with handling output formatting or supporting multiple output formats.

Install-Module PScribo  

Next we will need the VMware modules. With the following command you get a list of the possibilities:

Find-Module -name VMware.*

We only need the one for VMware Horizon for now, let’s install it:

Install-Module VMware.VimAutomation.HorizonView

That’s all for now. In part 2 of the series we will set-up the credential and connect to the Horizon API.

VMware DEM printer assignments — 10th Jun 2022

VMware DEM printer assignments

The script below creates a xml for each printer on a print server. Just replace the flex path and printer server place holders.

Refresh DEM and edit the assignment conditions and you’re done.

$PrintServer = '<unc path print server>'
$FlexPath = '\\<unc path dem config server>\general\FlexRepository\Printer\'
 
$Printers = Get-Printer -ComputerName $PrintServer | Where Name -ne 'Microsoft XPS Document Writer'
 
 
foreach($Printer in $Printers){
    [System.XML.XMLDocument]$XML = New-Object System.XML.XMLDocument
    [System.Xml.XmlWriterSettings] $XmlSettings = New-Object System.Xml.XmlWriterSettings
    [System.Xml.XmlWriter] $XmlWriter = [System.Xml.XmlWriter]::Create($XmlFile, $XmlSettings)
    [System.XML.XMLElement]$Root = $XML.CreateElement("userEnvironmentSettings")
   
    $XmlFile = $FlexPath + $Printer.Name + ".xml"
    $XmlSettings.Encoding = New-Object System.Text.UTF8Encoding($false)
   
    $XML.appendChild($Root)
 
    [System.XML.XMLElement]$Node1 = $Root.AppendChild($XML.CreateElement("setting"))
    $Node1.SetAttribute("type","Printer Mapping")
    $Node1.SetAttribute("async","1")
    $Node1.SetAttribute("remote","\\" + $PrintServer + "\" + $Printer.ShareName)
    $Node1.SetAttribute("default","1")
    $Node1.SetAttribute("label",$Printer.Name)
    $Node1.SetAttribute("undo","1")
   
    
    [System.XML.XMLElement]$Node2 = $Root.AppendChild($XML.CreateElement("conditions"))
 
   
    $XML.Save($XmlWriter)
}