Tag Archives: RES Workspace Manager

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'
 
$alreadyauth=@()
$ExeForAuth=@()
$exedirpath = "\\servername\Share\APPS"
 
 
Get-ChildItem -Recurse $dirpath | ?{!($_.psiscontainer) -and $_.Extension -like ".exe"}  | %{
    $ExeForAuth+=$_.fullname.ToLower()
}
 
 
[xml]$bb = Get-Content $importBuildingBlockPath
 
 
$bb.respowerfuse.buildingblock.application.appguard.authorizedfiles.authfile | %{
    $alreadyauth+=$_.authorizedfile.tolower()
}
 
 
Compare-Object $alreadyauth $ExeForAuth | ? {$_.SideIndicator -eq "=>"} | % {
    $newnode=$bb.respowerfuse.buildingblock.application.appguard.authorizedfiles.authfile[0].Clone()
    $newnode.authorizedfile=$_.inputobject.tostring()                                                                                     
    $newnode.description="Auto Appended item via script"                                                                                        
    $newnode.process="*"                                                                                          
    $newnode.learningmode="no"                                                                                               
    $newnode.enabled="yes"   
    $bb.respowerfuse.buildingblock.application.appguard.authorizedfiles.AppendChild($newnode)
}
 
$bb.save($exportBuildingBlockPath)

Powershell Script to add all applications to a RES Workspace Container.

As Part of a recent Proof of concept, I needed to move all of my applications from one workspace to another. With 50 + applications in just the proof of concept environment, the idea of opening each and modifying them individually did not excite me.

Upon starting my investigation, I found an interesting article by the PepperCrew’s @IngmarVerheij where he exported all building blocks, then used a find and replace command to add the workspace to the application, then added all building blocks back in again.

This approach worked great for his implementation, but I wanted to further automate my process while giving me the ability to amend a workspace without removing any currently configured workspaces.

My search continued to the following article on the RESGURU Blog, Where the RESGURU has kindly documented the usage of Powertech to automate (Certain) commands in the powerfuse / Workspace manager world. Sadly as they document, exporting from the database is not currently supported, but there was a glimmer of hope, they do support importing building blocks… result!

So the first task is to create your workspace and add one application to it, in my case I used notepad:

Next step is to export all applications to building blocks, this can be done easily by simply right clicking start icon and choosing building blocks > create…

Choose the directory you wish to work from (I Chose c:temp) and click ok, I’ll later refer to this directory as your “scratch directory”.

Step three is to find the GUID of the workspace you wish to add all your applications to. Of the building blocks you’ve exported, find the application you added to the workspace. The workspaceGUID can be found as below, take a copy of this value for later:

Now that you have all the building blocks and the guid, the fun can begin!

Below you will find the automated script to add a workspace to each xml file, then load them back into workspace manager using the powertech.exe command line interface. Below is a quick screen shot of how it looks:

Although I’ve written this for Applications, this could just as easily work for printers, user registry, anything so long as you ammend the XML path correctly. If you do have a requirement for other components or building blocks, drop me a commend and I’ll see what I can do.

Two Values will need to amended for this script to work in your environment, I’ve highlighted them bold in the script

  • The workspace GUID
  • the scratch directory
$WorkspaceGUID="{D3DC6EFF-BA8C-4A8A-A6DC-C5039DCC9F46}"
$scratchdirectory="c:temp*.xml"

foreach ($process in (gwmi win32_process | where {$_.name -eq "pwrtech.exe"})){
    $owner = ($process.getowner()).user
    if ($owner -eq "$env:username") {
        Write-warning "pwrtech.exe is currently running in your session and can cause issues, close it now, I'll wait 20 seconds."
        start-sleep 20
    }#end if
}#end for

$blocks = get-childitem $scratchdirectory
foreach ($block in $blocks) {
 $i++
 Write-Progress -activity "Adding Workspace to Applications and importing the building blocks:" -status "Currently working on: $($Block.name)  ($i of $($blocks.length))" -PercentComplete (($i / $blocks.length) * 100)

   [xml]$XMLBlock = get-content $block.fullname

    if (!($XMLBlock.respowerfuse.buildingblock.application.workspacecontrol)){
        #did not find a reference to Workspace Control,
        #write-host "Adding Workspacecontrol and Workspace element to $block"
        $workspacecontrolelement = $XMLBlock.CreateElement("workspacecontrol")

        #create individual workspace entry
        $WorkspaceElement = $XMLBlock.CreateElement("workspace")
        $WorkspaceElement.psbase.innertext=$WorkspaceGUID

        #append both elements
        $workspacecontrolelement.appendchild($WorkspaceElement) | out-null

        #append elements to xml
        $XMLBlock.respowerfuse.buildingblock.application.appendchild($workspacecontrolelement)  | out-null

        #saving XML file:
        $XMLBlock.save($block.fullname)

        #committing to database
        start-process "C:Program Files (x86)RES SoftwareWorkspace Managerpwrtech.exe" -wait -argumentlist "/add /overwrite ""$($block.fullname)"""
    }#end IF
    Else{
        #Found a reference of workspace control, checking if our building block already contains the workspace we wish to add:
        if ($XMLBlock.respowerfuse.buildingblock.application.workspacecontrol.workspace -notcontains $WorkspaceGUID){
            #create a new workspace element to add to a current workspace control element
            #write-host "appending workspace in $block"
            $WorkspaceElement = $XMLBlock.CreateElement("workspace")
            $WorkspaceElement.psbase.innertext=$WorkspaceGUID
            $XMLBlock.respowerfuse.buildingblock.application.workspacecontrol.appendchild($WorkspaceElement) | out-null
            #saving XML file:
            $XMLBlock.save($block.fullname)

            #committing to database
            start-process "C:Program Files (x86)RES SoftwareWorkspace Managerpwrtech.exe" -wait -argumentlist "/add /overwrite ""$($block.fullname)"""        
         }#end If
        Else {
            Write-warning "$block contains this workspace container already, skipping."
        }#end else
    }#end Else

}#end for