Advertisement
Guest User

Untitled

a guest
Nov 12th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 KB | None | 0 0
  1. Function Get-RESWMApplications {
  2. [CmdletBinding()]
  3. param (
  4. [Parameter(Mandatory=$true)]
  5. [string]$OutputFile,
  6. [string]$Inputfile,
  7. [switch]$SkipExporat
  8. )
  9. if(-not($SkipExport)){
  10. Write-Verbose 'Checking if RES WM Management console is running...'
  11. foreach ($process in (gwmi win32_process | where {$_.name -eq "pwrtech.exe"})){
  12. $owner = ($process.getowner()).user
  13. if ($owner -eq "$env:username") {
  14. Write-Warning "pwrtech.exe is currently running in your session, close it and try again."
  15. exit
  16. }
  17. }
  18. Write-Verbose 'It was not running.'
  19.  
  20. Write-Verbose "Checking if $Outputfile exists..."
  21. If(Test-Path $Outputfile) {
  22. $OutputfileInfo = Get-Item $Outputfile
  23. Write-Verbose 'Found.'
  24.  
  25. Write-Verbose "Checking if $Outputfile locked..."
  26. try
  27. {
  28. $Stream = $OutputfileInfo.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::None)
  29. }
  30. catch [System.IO.IOException]
  31. {
  32. # locked
  33. Write-Warning "$Outputfile is locked by another application, close the workbook in excel and try again."
  34. exit
  35. }
  36. finally
  37. {
  38. if ($stream){$stream.Close()}
  39. }
  40. # not locked
  41. Write-Verbose "Not locked."
  42. } Else {
  43. Write-Verbose "$Outputfile not found, it will be created..."
  44. }
  45.  
  46. Write-Verbose 'Exporting buildingblock...'
  47. Write-Progress -Activity 'Exporting buildingblock...'
  48. Start-Process -FilePath "C:\Program Files (x86)\RES Software\Workspace Manager\pwrtech.exe" -ArgumentList "/export $Inputfile /type:application" -Wait
  49. } # end of SkipExport
  50.  
  51. # Timing execution of script
  52. $StopWatch = New-Object System.Diagnostics.Stopwatch
  53. $StopWatch.Start()
  54.  
  55. Write-Verbose 'Reading exported building block to memory...'
  56. [xml]$xml = Get-Content $Inputfile
  57. $workspacesxml = $xml.respowerfuse.buildingblock.workspaces
  58. $applicationsxml = $xml.respowerfuse.buildingblock.application
  59.  
  60. # Workspaces
  61. Write-Verbose 'Parsing xmlobj for workspaces...'
  62. $workspaceobj = $workspacesxml.workspace | ForEach-Object {
  63. Write-Verbose "Adding workspace $($_.Name)..."
  64. $workspacerows = [ordered]@{
  65.  
  66. # Workspace information
  67. workspace=$_.name;
  68. guid=$_.guid;
  69. 'access_match'=foreach($access in $_.accesscontrol){
  70. switch($access.access_mode){
  71. 'or' {"any"}
  72. 'and' {"all"}
  73. }
  74. };
  75. 'access filters'=$(foreach($access in $_.accesscontrol){
  76. switch($access.access.type){
  77. 'global' {"global"}
  78. 'user' {"user: '$($access.access.object)'"}
  79. 'group' {"in group: '$($access.access.object)'"}
  80. 'notingroup' {"not in group: '$($access.access.object)'"}
  81. }
  82. }) -join ', ';
  83. 'zone_match'=foreach($access in $_.accesscontrol){
  84. switch($access.zone_mode){
  85. 'or' {"any"}
  86. 'and' {"all"}
  87. }
  88. };
  89. 'zone filters'=$(foreach($access in $_.accesscontrol){
  90. switch($access.access.type){
  91. 'powerzone' {"in zone: '$($access.SelectNodes("access[type='powerzone']").object | ForEach-Object{$powerzonesxml.SelectNodes("powerzone[guid='$_']").Name})'"}
  92. 'notinpowerzone' {"not in zone: '$($access.SelectNodes("access[type='notinpowerzone']").object | ForEach-Object{$powerzonesxml.SelectNodes("powerzone[guid='$_']").Name})'"}
  93. }
  94. }) -join ', ';
  95. agents=if($_.includeallcomputers -eq 'yes'){
  96. 'All agents'
  97. } else {
  98. $_.computercontrol.item.agent -join ', '
  99. };
  100. enabled=$_.enabled;
  101.  
  102. }
  103. new-object psobject -Property $workspacerows
  104. }
  105.  
  106. # Applications
  107. Write-Verbose 'Parsing xmlobj for applications...'
  108. $applicationsobj = $applicationsxml | ForEach-Object {
  109. Write-Verbose "Adding values for $($_.configuration.title)..."
  110. $applicationrows = [ordered]@{
  111.  
  112. # Most important fields first
  113. 'start menu folder' = $_.configuration.menu;
  114. application = $_.configuration.title;
  115. commandline=$_.configuration.commandline;
  116. parameters=$_.configuration.parameters;
  117. guid=$_.guid;
  118.  
  119. # Configuration
  120. administrativenote=$_.configuration.administrativenote;
  121. appv5packagefile=$_.configuration.appv5packagefile;
  122. appv5packagemode=$_.configuration.appv5packagemode;
  123. appv5packageroot=$_.configuration.appv5packageroot;
  124. appv5packageupdate=$_.configuration.appv5packageupdate;
  125. createmenushortcut=$_.configuration.createmenushortcut;
  126. defaulticon=$_.configuration.defaulticon;
  127. description=$_.configuration.description;
  128. desktop=$_.configuration.desktop;
  129. intercept_launch=$_.configuration.intercept_launch;
  130. pintostartmenu=$_.configuration.pintostartmenu;
  131. quicklaunch=$_.configuration.quicklaunch;
  132. runwithsccm=$_.configuration.runwithsccm;
  133. startmenu=$_.configuration.startmenu;
  134. subscribed=$_.configuration.subscribed;
  135. unmanagedshortcuts=$_.configuration.unmanagedshortcuts;
  136. workingdir=$_.configuration.workingdir
  137.  
  138. # Access info
  139. workspaces=($_.workspacecontrol.workspace | ForEach-Object{$workspacesxml.SelectNodes("workspace[guid='$_']").Name}) -join ', ';
  140. accesstype=$_.accesscontrol.accesstype;
  141. groups=foreach ($group in $_.accesscontrol.grouplist){$group.group.'#text' -join ', '};
  142. zones=foreach ($zone in $_.powerzones){$zone.powerzone.'#text' -join ', '};
  143.  
  144. # Settings
  145. enabled=$_.settings.enabled;
  146. instances=$_.settings.instances;
  147. startstyle=$_.settings.startstyle;
  148. priority=$_.settings.priority;
  149. requiredconnectionstate=$_.settings.requiredconnectionstate;
  150. nopowerhelp=$_.settings.nopowerhelp;
  151. noinstancemsg=$_.settings.noinstancemsg;
  152. nonewappmsg=$_.settings.nonewappmsg;
  153. onlyresshell=$_.settings.onlyresshell;
  154. onlywindowsshell=$_.settings.onlywindowsshell;
  155. systemtray=$_.settings.systemtray;
  156. autoall=$_.settings.autoall;
  157. noauto=$_.settings.noauto;
  158. password=$_.settings.password;
  159. nocpushield=$_.settings.nocpushield;
  160. nopowerload=$_.settings.nopowerload;
  161. nomemoryshield=$_.settings.nomemoryshield;
  162. separatememory=$_.settings.separatememory;
  163. hidefrommenu=$_.settings.hidefrommenu;
  164. checkappexists=$_.settings.checkappexists;
  165. genericisolation=$_.settings.genericisolation;
  166. nofolderredir=$_.settings.nofolderredir;
  167.  
  168. # Licensing
  169. LicenseType=$_.licensing.type;
  170. cost=$_.licensing.cost;
  171. Licenses=$_.licensing.count;
  172. user=$_.licensing.user;
  173. users=$_.licensing.users;
  174.  
  175.  
  176. }
  177. New-Object psobject -Property $applicationrows
  178. }
  179.  
  180. Write-Verbose "Exporting the collected powershell objects to $OutputFile..."
  181.  
  182. $applicationsobj | Export-Csv -Encoding UTF8 -Delimiter ';' -NoTypeInformation -Path $OutputFile
  183. # $applicationsobj | Out-GridView
  184.  
  185. $StopWatch.Stop()
  186. "Finished in $($StopWatch.Elapsed.Minutes) Minutes $($StopWatch.Elapsed.Seconds) Seconds"
  187.  
  188. } # end of function
  189.  
  190. $date = Get-Date
  191. $XMLFilename = "Applications.xml"
  192. $OutputPath = "C:\Temp"
  193. $OutputFileName = "RES_Output_$($date.Year)-$($date.Month)-$($date.Day).csv"
  194.  
  195. Get-RESWMApplications -Inputfile "$OutputPath\$XMLFilename" -OutputFile "$OutputPath\$OutputFileName" -Verbose # -SkipExport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement