Remko Weijnen's Blog (Remko's Blog)

About Virtualization, VDI, SBC, Application Compatibility and anything else I feel like

Archive for the ‘PowerShell’ Category

From a script I needed to schedule a project in RES Automation Manager 2011 for a particular server.

imageThis can be done with the WMC.exe commandline tool as documented in the Admin Guide. However we must specify the agent’s GUID instead of it’s name. We can of course use the AM console to get the agent’s GUID but it’s more flexible to script this.

imageUnfortunately there’s no API we can call so I am directly quering the AM database using a PowerShell script.

The script read the database server and database name from the registry so it assumes you have the AM console installed.


  • Filed under: PowerShell, RES
  • PowerShell RegEx Fun

    I am writing a script that is going to automate a number of manual steps involved in creating a new image with Citrix PVS.

    First step is to copy the most recent base image which is kept in a folder structure. The folder name is always YYYY-MM-DD (description):


    I needed to determine the most recent folder and didn’t want to rely on creation date. Instead I walk the directory tree and filter the date out of the filename with a regular expression:


  • Filed under: PowerShell
  • Convert MCli output into PowerShell Objects

    imageI was experimenting today with the PowerShell cmdlets for Citrix Provisioning Server. I was surprised to learn that the output of these cmdlets are not PowerShell types such as collections and objects with methods and properties but just plain text output.

    A google search for a method to quickly convert the garbage output to objects led me to this blog post by Frank Peter. He describes a clever use of the switch statement with regular expressions with the Get-DiskInfo cmdlet.

    Using Frank’s code as a basis I wrote a generic function that converts Mcli output to an array of objects.


    Script to Get Computer OU

    Just some quick code to get the OU Name of the computer we run the script on.



    Scripting Citrix Online Plugin Settings

    The Citrix Online Plugin has a number of settings that can be changed. This includes things as Window Size and Color Depth:

    Session Options | Window size | Default | Full Screen | Requested Color Quality

    In my case I wanted to preset the Window size to Full Screen so using Process Monitor I checked where the Online Plugin writes this setting. I Used a Filter that includes only the Online Plugin (PNAMain.exe) and the RegSetValue Operation:

    Filter on Process Name is PNAMain.exe | Operation is RegSetValue


    imageAfter reading Andy Morgan’s (excellent) blog post about Removing Screen Resolution and Personalize shell extensions from a users desktop session I couldn’t help it.

    imageI had to write a PowerShell script to take ownership of the mentioned registry keys. So here goes:


  • Filed under: PowerShell
  • Read Maximum Password Age with PowerShell

    imageI needed to read out the Maximum Password age with a PowerShell script in a Windows 2003 domain.

    Reading out the maxPwdAge attribute is a trivial task  in PowerShell (I am re-using the function AdsLargeIntegerToInt64):

    In my case this returns the value -78624000000000 but how do we interpret this?


    Embedding images in HTML

    I was creating a small dialog in an .hta file and to make a little prettier for the user I included a company logo:


    But I wanted to deploy the .hta as a single file.


    Some Active Directory attributes return an 8 byte integer in the form of an IADsLargeInteger interface. An example is the pwdLastSet attribute from a user object.

    Because the IADsLargeInteger object doesn’t provide type information PowerShell cannot read the HighPart and LowPart properties.

    So I wrote the function below to get the Int64 value of an IADsLargeInteger:


    Set homefolder permissions with PowerShell

    imageToday one of my collegues asked me to write a script that performs two actions for all users of a certain Organizational Unit:

    1. Ensure that each user has modify permissions on their homefolder
    2. Make each user visible in the Exchange Address List.

    Sounds like a PowerShell job right?

    I reused my function to set NTFS Permissions by SID:


  • Filed under: PowerShell
  • Blogroll