Set default printer for View floating desktop and Persona Management

Sometime ago I asked a question over at the VMware forum about how to set default network printers on a VMware View 5.0 floating pool that used Persona Management as Persona Management wasn’t keeping this user setting on it’s own. The printers would be added to the VM just not remember the default printer setting. I’ll admit I forgot to update the thread, but a work around was devised which I’ll share below.

Set View Desktop default printer using vbs script

Using this .vbs script I was able to have network printers installed and set as default upon a user logging into their View floating pool desktop.

[sourcecode language=”vb”]’ Installs network printer and sets default
‘ Created: 03/03/2013, By: Michael Tabor

Option Explicit
On Error Resume Next
Dim objNetwork, objSysInfo, objUser, strGroup

‘ Initialize constants with Group names
‘ AD groups should follow this convention:
‘ "!Group###name" entered here in all CAPS
Const Kentucky = "cn=!KY_Insurance"
Const Ohio = "cn=!OH_Insurance"

‘ Create objects and extract strGroup values
Set objNetwork = CreateObject("WScript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

‘ Groups are polled and listed in an array. If only 1
‘ non-builtin group exists, the 1st line errors and
‘ the 2nd line will hold the value
strGroup = UCase(Join(objUser.MemberOf))
strGroup = UCase(objUser.MemberOf))

‘ If logic testing strGroup for the values in Const groups
If InStr(strGroup, UCASE(Kentucky)) Then
objNetwork.AddWindowsPrinterConnection ‘ Adds printer
"\\kentucky-print-server\ky-ins-printer" ‘ Printer network location
objNetwork.SetDefaultPrinter ‘ Sets default printer
"\\kentucky-print-server\ky-ins-printer"

ElseIf InStr(strGroup, UCASE(Ohio)) Then
objNetwork.AddWindowsPrinterConnection
"\\ohio-print-server\oh-ins-printer"
objNetwork.AddWindowsPrinterConnection
"\\ohio-print-server\oh-office-printer"
objNetwork.SetDefaultPrinter
"\\ohio-print-server\oh-ins-printer"

End If

Set objNetwork = Nothing
Set objSysInfo = Nothing
Set objUser = Nothing

WScript.Quit[/sourcecode]

So a little more background that might be useful – the floating pool is a pool that was for our Insurance department that was used by agents in two different states (Kentucky and Ohio). Each of the users was in a different usergroup based on their office/location.

This script works by looking at the usergroups each user is a member of upon log-in and then installs the users required printer(s) and sets a default. The process is nearly instant or within just a few seconds.

How the vbs script works

The break down of the important parts of the script is this:

[sourcecode language=”vb”]Const Kentucky = "cn=!KY_Insurance"
Const Ohio = "cn=!OH_Insurance"
[/sourcecode]

Constants are assigned for each usergorup using Kentucky and Ohio and looking for usergroups !KY_Insurance and !OH_Insurance respectively.

Then based on their usergroup membership the printer(s) was added and default set. For example say the member was part of the !KY_Insurance usergroup the following code would be ran for them:

[sourcecode language=”vb”]If InStr(strGroup, UCASE(Kentucky)) Then
objNetwork.AddWindowsPrinterConnection ‘ Adds printer
"\\kentucky-print-server\ky-ins-printer" ‘ Printer network location
objNetwork.SetDefaultPrinter ‘ Sets default printer
"\\kentucky-print-server\ky-ins-printer"
[/sourcecode]

This code goes to the printer server (\\kentucky-print-server) and adds a printer (ky-ins-printer), the last line sets that printer as default. You can see above that for the Ohio users that office had two printers added and then one set as default. So this can be expanded upon for any additional printers needed.

The script can be added to GPO and ran upon user login or placed on the VM parent image in the start-up folder:

%appdata%\Microsoft\Windows\Start Menu\Programs\Startup

Using this same script as well as Persona Management, I’ve been able to convert many persistent view desktop pools into floating pools as well. Works great and nice to have fewer persistent desktop pools.

If you know of any way to improve the script please share!

Download script: view-default-printer.vbs

Similar Posts

  • How to convert VMDK to OVF file format

    Here is a quick and easy way to convert a VMDK to OVF file format using the OVF Tool from VMware.

    1. First download and install the VMware OVF Tool for your operating system.
    2. Open a command prompt as Administrator and navigate to the OVF Tool install directory:
      
      cd C:\Program Files\VMware\VMware OVF Tool
      

      vmdk to ovf command prompt

    3. Next, type in the following command to convert VMDK to OVF:
      
      ovftool.exe \virtualmachine.vmx \virtualmachine.ovf
      

      convert vmdk to ovf command

    After a few minutes time you should you should see a “Transfer Completed, Completed successfully” message and your VMDK to OVF file conversion is complete and ready for use.
    convert vmdk to ovf complete

  • VMware ESXi 6.0 CBT bug fix released

    VMware

    You may remember ESXi 4.x-5.x had a CBT bug, as mentioned here, that could potentially cause your backups to be pretty useless. Well it seems ESXi 6.0 isn’t without it’s own CBT bug which could cause the following to possibly occur:

    • Backing up a VM with CBT enabled fails.
    • Powering on virtual machines fails.
    • Expanding the size of a virtual disk fails.
    • Taking VM quiesced snapshots fails.

    Prior to the fix, the workaround was to disable CBT. Thankfully VMware has released a fix for the ESXi 6.0 CBT bug and it’s recommended that anyone who uses CBT apply this patch regardless if it was a clean install of VMware ESXi 6.0 or an upgrade to ESXi 6.0.

    Read More “VMware ESXi 6.0 CBT bug fix released”

  • VMware vSphere 7 announced

    VMware vSphere 7

    Some pretty big news coming out of VMware today. The announcement of VMware vSphere 7 to become available May 1, 2020! One of the biggest item coming out of this news so far is that vSphere 7 will come in two options.

    The first being vSphere 7 as we all have known it to be for years and then the second being vSphere 7 with Kubernetes which will be available through VMware Cloud Foundation and is a new generation of vSphere for containerized applications.

    Other notables is that the flash based vSphere client is FINALLY no more! From here on out, only the HTML 5 will exist. vCenter Server on Windows will also finally be put to rest and new deployments of vCenter server will be done using the tried and tested vCenter Server Appliance (VCSA) based on PhotonOS linux.

    Read More “VMware vSphere 7 announced”

  • Install ESXi 5.1 from a USB Flash Drive

    Many servers already come with a DVD/CD-ROM drive or some kind of ability to virtually mount an ISO image from a network share onto your server to then install ESXi. However, not all do or you just want to have your ESXi image readily available. Here’s a quick step by step instructions on how to use a USB flash drive to install ESXi.

    1. Download ESXi 5.1 from VMware (if you haven’t already) as well as UNettbootin.
    2. Plug in your USB Flash Drive.
    3. Open UNetbootin and select “Diskimage”, set Type to “USB Drive”, select Drive letter of your USB flash drive, and set the path of your ESXi 5.1 ISO image. Then click on “OK”.
      unetbootin setup
    4. Read More “Install ESXi 5.1 from a USB Flash Drive”

  • How to fix vRealize Orchestrator 6 appliance, weak ephemeral Diffie-Hellman key

    vrealize orchestrator chrome error

    I’ve recently deployed the vRealize Orchestrator appliance (6.0.2) and noticed right away that my default browser Firefox, would not load the Orchestrator appliance web panel. Firefox always complained about a weak Diffie-Hellman key.

    An error occurred during a connection to ip-address:8281. SSL received a weak ephemeral Diffie-Hellman key in Server Key Exchange handshake message. (Error code: ssl_error_weak_server_ephemeral_dh_key)

    At the time I simply ignored it and just tried Google Chrome which it worked fine. That was until the latest release also broke with the same type of error message:

    Server has a weak ephemeral Diffie-Hellman public key“.

    I now had a problem and contacted VMware support, below is the very easy fix to make vCO 6 work in both the latest version of Firefox and Chrome!

    Read More “How to fix vRealize Orchestrator 6 appliance, weak ephemeral Diffie-Hellman key”

Leave a Reply

Your email address will not be published. Required fields are marked *

5 Comments

    1. Group Policy Preferences could certainly be another way to achieve the same result.

      Correct me if I’m wrong, but isn’t this a feature that is available in Server 2008 and newer? Our AD controller in this environment is Server 2003.

      1. You are hereby corrected. GPPreferences only requires that the client have the GPPreferences moving parts (which Windows 7 and later has.) The DC type and domain mode.. do not matter.

      2. If ThinPrint is enabled, the default printer configured in the Client will override these selections unless disabled in the View Client