Tag Archives: PowerShell

New Module: Creating an RDP file password with PowerShell

Windows_PowerShell_iconHere’s something that is surprisingly tricky to automate in this day and age. Creating a password and storing it in an RDP file. I’m not here to debate the security “knock ons” of doing this, it’s not in my interest and if I’m asked to do something despite advice against it, I do it!

But as always I figured I’d share this feature in case anyone else needs it.

So RDP files encrypt a password in a very specific way and details online are cagey.This is something I set about doing myself and I’m happy to annouce I’ve included it in the following Free Powershell module for your use!

Continue reading


Dealing with multi numbered versions in powershell.

Windows_PowerShell_iconSo here’s a quick little blog about something i discovered in powershell while googling today.

Lots of vendors like to use version numbers including Major.Minor.Build.Revision.

An example of a vendor I was dealing with recently was Citrix themselves.


The problem is, in powershell, it’s not that easy to take a string (text) representative of these, split it up then label it yourself. you’re splitting, taking objects in an array, assigning them values… nasty.


Did you know .Net has a native ability to do this?

Introducing system.version

Now with system.version, it’s very easy to do comparisons! Just cast your string into a [system.version] as below:



After that, just compare the major, minor, build or revision at will!



Happy version comparing!

Accurately checking the Citrix PVS “cache in Ram, Overflow to disk” RAM cache size

Citrix_Provisioning_Services_ImplementationCitrix Provisioning services “Cache in RAM, overflow to disk”, even with it’s challenges is something I’ve always felt was a great idea, hell, I foresaw it’s implementation back in 2012!

Not withstanding the issues that can occur when the cache is heavily in use, it’s a great piece of technology. One of the features you see on twitter repeatedly is trying to report on the exact size of the PVS cache in RAM.

Many blogs and scripts (Matt’s here, as an example) will take the raw performance counter details for Non Paged Pool memory and assume this is the size of the cache. This is faulty logic, but close enough. It’s like looking into a can of beans and trying to determine which one gave you gas.

The Non paged Pool is a collective pool of memory used by the system that guarantee’s the services using it (drivers, etc) that the contents will never reach the disk and will always be maintained in memory. As an example, imagine you created your own disk driver, but the disk driver tried to reference it’s memory and it had since been flushed to the disk…. Chicken and Egg stuff!

Microsoft has a fairly clear description here:

The memory manager creates the following memory pools that the system uses to allocate memory: nonpaged pool and paged pool. Both memory pools are located in the region of the address space that is reserved for the system and mapped into the virtual address space of each process. The nonpaged pool consists of virtual memory addresses that are guaranteed to reside in physical memory as long as the corresponding kernel objects are allocated.

So with this in mind, taking a total of the Non Paged Pool memory and assuming it’s PVS is “OK”… But not accurate. Many other sources can bloat that memory cache, particularly in x64 systems where limits on these pools are now enormous compared to the tiny pools we had to deal with in x86 architectures.

Nerdy digression aside, if you REALLY want accurate information on what’s going on inside of this pool. You need to grab a copy of Poolmon from the Windows Driver Kit (WDK). Download the WDK, install it and you’ll find your poolmon in:

C:\Program Files (x86)\Windows Kits\10\Tools\x64\poolmon.exe

Once you have a copy, fire up poolmon and you’ll see in all their glory.


Pro tip: Press “p” once to sort my non pooled, then “b” to sort by bytes used.

Each pool tag and the respective space they are using. Interestingly, the Citrix caching technology seems to use the “VhdR” pooltag allocation. There’s also a Microsoft Pool tag for this (http://blogs.technet.com/b/yongrhee/archive/2009/06/24/pool-tag-list.aspx) but the case sensitivity differences between VhdR and VHDr may make all the difference.

I did reach out to Citrix on this one, but they didn’t provide any further insight.

Any-who, if you want to see the size of your PVS cache accurately? Use PoolMon. Here’s a quick script using poolmon to get the GB value back:

$poolmonpath= "d:\poolmon.exe"
$poollog= "$env:temp\poolmon.txt"
if(test-path $poollog){Remove-Item $poollog}
Start-Process-FilePath $poolmonpath -ArgumentList "-n $poollog" -Wait
((Get-Content $poollog | ? {$_ -like "*VhdR*"}) -split "\s+")[6] /1gb
if(test-path $poollog){Remove-Item $poollog}

Adding a list of Authorised files to RES Workspace Manager Building Block

Windows_PowerShell_iconThis is just a quick article on how to search for exe’s recursively in a specific path and add them to an RES Workspace Manager building block to be imported back in.

I needed to do this recently as the customer in question had an application that lived on a network share and after 14+ years of development in this style, everyone was afraid to move it!

Steps to use this script:

  • Export an existing building block for the application you wish to authorize
  • Ensure the exported building block has at least one authorized file
  • Modify the $import and $exportbuildingblockpath
  • Modify the $exedirpath to be the path you wish to search recursively for exe’s.
$importBuildingBlockPath = 'H:\path\bb.xml'
$exportBuildingBlockPath = 'h:\path\export.xml'
$exedirpath = "\\servername\Share\APPS"
Get-ChildItem -Recurse $dirpath | ?{!($_.psiscontainer) -and $_.Extension -like ".exe"}  | %{
[xml]$bb = Get-Content $importBuildingBlockPath
$bb.respowerfuse.buildingblock.application.appguard.authorizedfiles.authfile | %{
Compare-Object $alreadyauth $ExeForAuth | ? {$_.SideIndicator -eq "=>"} | % {
    $newnode.description="Auto Appended item via script"                                                                                        

Viewing open files on a file server from powershell.

/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&h=58&h=58So this is a situation you should all be aware of in an SBC / VDI environment, despite all warnings, you’ve redirected folders to your network drive and your file servers are screaming in agony?

Having been in this situation recently, I needed to audit and report on the types of files open on the file server, my hunch was a certain select number of users were running applications (like *gulp* lotus notes) from the network share.

Disappointed with the powershell scripts on the interwebs, I decided to write my own function to perform this task:

[sourcecode language=”powershell”]
function get-openfiles{
$collection = @()
foreach ($computer in $computername){
$netfile = [ADSI]"WinNT://$computer/LanmanServer"

$netfile.Invoke("Resources") | foreach {
$collection += New-Object PsObject -Property @{
Id = $_.GetType().InvokeMember("Name", ‘GetProperty’, $null, $_, $null)
itemPath = $_.GetType().InvokeMember("Path", ‘GetProperty’, $null, $_, $null)
UserName = $_.GetType().InvokeMember("User", ‘GetProperty’, $null, $_, $null)
LockCount = $_.GetType().InvokeMember("LockCount", ‘GetProperty’, $null, $_, $null)
Server = $computer
if ($verbose){write-warning $error[0]}
Return $collection

The function above (get-openfiles) has been written to accept an array of servers to the command line and it will return the following items:

  • The ID of the open file.
  • The server it’s open from.
  • The username who has the file open.
  • The amount of locks the file has.

A couple of quick examples for using this command are below:

Retrieving open files from server1:


[sourcecode language=”powershell”]get-openfiles -computername server1 | select server,itempath,lockcount[/sourcecode]

Retrieve a count of open files that end with the nsf file type (Lotus Notes):


[sourcecode language=”powershell”](get-open files -computername server1,server2 | ? {$_.itempath -like "*.nsf*"}).count()[/sourcecode]

Retrieve a report of total open files on a number of file servers:



[sourcecode language=”powershell”]get-openfiles -computername server1,server2,server3,server4,server5 | group -property server[/sourcecode]