Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Get-RESWMApplications {
- [CmdletBinding()]
- param (
- [Parameter(Mandatory=$true)]
- [string]$OutputFile,
- [string]$Inputfile,
- [switch]$SkipExporat
- )
- if(-not($SkipExport)){
- Write-Verbose 'Checking if RES WM Management console is running...'
- 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, close it and try again."
- exit
- }
- }
- Write-Verbose 'It was not running.'
- Write-Verbose "Checking if $Outputfile exists..."
- If(Test-Path $Outputfile) {
- $OutputfileInfo = Get-Item $Outputfile
- Write-Verbose 'Found.'
- Write-Verbose "Checking if $Outputfile locked..."
- try
- {
- $Stream = $OutputfileInfo.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::None)
- }
- catch [System.IO.IOException]
- {
- # locked
- Write-Warning "$Outputfile is locked by another application, close the workbook in excel and try again."
- exit
- }
- finally
- {
- if ($stream){$stream.Close()}
- }
- # not locked
- Write-Verbose "Not locked."
- } Else {
- Write-Verbose "$Outputfile not found, it will be created..."
- }
- Write-Verbose 'Exporting buildingblock...'
- Write-Progress -Activity 'Exporting buildingblock...'
- Start-Process -FilePath "C:\Program Files (x86)\RES Software\Workspace Manager\pwrtech.exe" -ArgumentList "/export $Inputfile /type:application" -Wait
- } # end of SkipExport
- # Timing execution of script
- $StopWatch = New-Object System.Diagnostics.Stopwatch
- $StopWatch.Start()
- Write-Verbose 'Reading exported building block to memory...'
- [xml]$xml = Get-Content $Inputfile
- $workspacesxml = $xml.respowerfuse.buildingblock.workspaces
- $applicationsxml = $xml.respowerfuse.buildingblock.application
- # Workspaces
- Write-Verbose 'Parsing xmlobj for workspaces...'
- $workspaceobj = $workspacesxml.workspace | ForEach-Object {
- Write-Verbose "Adding workspace $($_.Name)..."
- $workspacerows = [ordered]@{
- # Workspace information
- workspace=$_.name;
- guid=$_.guid;
- 'access_match'=foreach($access in $_.accesscontrol){
- switch($access.access_mode){
- 'or' {"any"}
- 'and' {"all"}
- }
- };
- 'access filters'=$(foreach($access in $_.accesscontrol){
- switch($access.access.type){
- 'global' {"global"}
- 'user' {"user: '$($access.access.object)'"}
- 'group' {"in group: '$($access.access.object)'"}
- 'notingroup' {"not in group: '$($access.access.object)'"}
- }
- }) -join ', ';
- 'zone_match'=foreach($access in $_.accesscontrol){
- switch($access.zone_mode){
- 'or' {"any"}
- 'and' {"all"}
- }
- };
- 'zone filters'=$(foreach($access in $_.accesscontrol){
- switch($access.access.type){
- 'powerzone' {"in zone: '$($access.SelectNodes("access[type='powerzone']").object | ForEach-Object{$powerzonesxml.SelectNodes("powerzone[guid='$_']").Name})'"}
- 'notinpowerzone' {"not in zone: '$($access.SelectNodes("access[type='notinpowerzone']").object | ForEach-Object{$powerzonesxml.SelectNodes("powerzone[guid='$_']").Name})'"}
- }
- }) -join ', ';
- agents=if($_.includeallcomputers -eq 'yes'){
- 'All agents'
- } else {
- $_.computercontrol.item.agent -join ', '
- };
- enabled=$_.enabled;
- }
- new-object psobject -Property $workspacerows
- }
- # Applications
- Write-Verbose 'Parsing xmlobj for applications...'
- $applicationsobj = $applicationsxml | ForEach-Object {
- Write-Verbose "Adding values for $($_.configuration.title)..."
- $applicationrows = [ordered]@{
- # Most important fields first
- 'start menu folder' = $_.configuration.menu;
- application = $_.configuration.title;
- commandline=$_.configuration.commandline;
- parameters=$_.configuration.parameters;
- guid=$_.guid;
- # Configuration
- administrativenote=$_.configuration.administrativenote;
- appv5packagefile=$_.configuration.appv5packagefile;
- appv5packagemode=$_.configuration.appv5packagemode;
- appv5packageroot=$_.configuration.appv5packageroot;
- appv5packageupdate=$_.configuration.appv5packageupdate;
- createmenushortcut=$_.configuration.createmenushortcut;
- defaulticon=$_.configuration.defaulticon;
- description=$_.configuration.description;
- desktop=$_.configuration.desktop;
- intercept_launch=$_.configuration.intercept_launch;
- pintostartmenu=$_.configuration.pintostartmenu;
- quicklaunch=$_.configuration.quicklaunch;
- runwithsccm=$_.configuration.runwithsccm;
- startmenu=$_.configuration.startmenu;
- subscribed=$_.configuration.subscribed;
- unmanagedshortcuts=$_.configuration.unmanagedshortcuts;
- workingdir=$_.configuration.workingdir
- # Access info
- workspaces=($_.workspacecontrol.workspace | ForEach-Object{$workspacesxml.SelectNodes("workspace[guid='$_']").Name}) -join ', ';
- accesstype=$_.accesscontrol.accesstype;
- groups=foreach ($group in $_.accesscontrol.grouplist){$group.group.'#text' -join ', '};
- zones=foreach ($zone in $_.powerzones){$zone.powerzone.'#text' -join ', '};
- # Settings
- enabled=$_.settings.enabled;
- instances=$_.settings.instances;
- startstyle=$_.settings.startstyle;
- priority=$_.settings.priority;
- requiredconnectionstate=$_.settings.requiredconnectionstate;
- nopowerhelp=$_.settings.nopowerhelp;
- noinstancemsg=$_.settings.noinstancemsg;
- nonewappmsg=$_.settings.nonewappmsg;
- onlyresshell=$_.settings.onlyresshell;
- onlywindowsshell=$_.settings.onlywindowsshell;
- systemtray=$_.settings.systemtray;
- autoall=$_.settings.autoall;
- noauto=$_.settings.noauto;
- password=$_.settings.password;
- nocpushield=$_.settings.nocpushield;
- nopowerload=$_.settings.nopowerload;
- nomemoryshield=$_.settings.nomemoryshield;
- separatememory=$_.settings.separatememory;
- hidefrommenu=$_.settings.hidefrommenu;
- checkappexists=$_.settings.checkappexists;
- genericisolation=$_.settings.genericisolation;
- nofolderredir=$_.settings.nofolderredir;
- # Licensing
- LicenseType=$_.licensing.type;
- cost=$_.licensing.cost;
- Licenses=$_.licensing.count;
- user=$_.licensing.user;
- users=$_.licensing.users;
- }
- New-Object psobject -Property $applicationrows
- }
- Write-Verbose "Exporting the collected powershell objects to $OutputFile..."
- $applicationsobj | Export-Csv -Encoding UTF8 -Delimiter ';' -NoTypeInformation -Path $OutputFile
- # $applicationsobj | Out-GridView
- $StopWatch.Stop()
- "Finished in $($StopWatch.Elapsed.Minutes) Minutes $($StopWatch.Elapsed.Seconds) Seconds"
- } # end of function
- $date = Get-Date
- $XMLFilename = "Applications.xml"
- $OutputPath = "C:\Temp"
- $OutputFileName = "RES_Output_$($date.Year)-$($date.Month)-$($date.Day).csv"
- Get-RESWMApplications -Inputfile "$OutputPath\$XMLFilename" -OutputFile "$OutputPath\$OutputFileName" -Verbose # -SkipExport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement