export and import reg vallue targeted on servername

RICOH printers installed on three RDS 2012 servers localy. Reason is the adobe PDF print problem to use local installed printers.
The printers are having the same name and drivers on all the rds servers
Users want to use the secure printing option. You set a name and a โ€œpinโ€
When the user logs in on RDS01 and set the setting then it will work :slight_smile:
when the user logs in on RDS02 (broker load balancing system) the security settings are not there.

The reg setting for this is different per server and the setting for the other server is deleted.

What i want to achieve:

User set the printer setting. The user logs of and the specifiek HKLU setting is exported recursive. The name of the export reg must contain the server name.

when the user logs in again it looks at a reg name including the servername (name example : rds001printer1.reg)
then the reg will be imported into the HKLU settings.

I am not a pro on powershell but i know it can be done.

any suggestions or examples?

The reg value would be :


To import the reg key I created this script. It works :).
Any suggestions if this is a way to do it ?

Set-ExecutionPolicy remotesigned -Force
$currentDate=get-date -Format "yyyyMMddhhmmss"
$strExportPath = "c:\export\"
$strFilename = $strExportPath+$env:COMPUTERNAME+"printer.reg"
$strRename = $strFilename+$currentdate

If (Test-Path $strFilename) {
    Rename-Item $strFilename $strRename
    Reg export  $regkey $strFilename
    $items=get-childitem $strExportPath
    $items | Sort-Object lastwritetime -Descending | Select-Object -Last ($items.Count -ge $n) | ForEach-Object {Remove-Item $strExportPath$_ }
    Reg export $regkey $strFilename