PoshCode Logo PowerShell Code Repository

Set-PowerGUIWelcomePage by Dmitry Sotnikov 32 months ago (modification of post by Dmitry Sotnikov view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1129"></script>download | new post

This script customizes the welcome screen which PowerGUI admin console displays on start-up or when a folder is selected in the left-hand tree.
You can use it to introduce branding to the PowerGUI consoles used in your company or to provide your employees with additional information.
Create the MHT file by saving it from Internet Explorer, Microsoft Word or another editor, then run this script to set a reference to the file from PowerGUI configuration.

Version 1.3 makes the script compatible with PowerGUI 1.8

See http://dmitrysotnikov.wordpress.com/2009/02/11/rebranding-powergui-console/ for details

  1. ########################################################
  2. # Modifies the default PowerGUI admin console
  3. # welcome screen to the mht file you supply
  4. # Details available at:
  5. # http://dmitrysotnikov.wordpress.com/2009/02/11/rebranding-powergui-console/
  6. ########################################################
  7. # Usage:
  8. # To change the homepage:
  9. #   & .\Set-PowerGUIWelcomePage.ps1 \\server\share\my.mht
  10. # To rollback the change:
  11. #   & .\Set-PowerGUIWelcomePage.ps1 -ResetToDefault $true
  12. ########################################################
  13. # (c) Dmitry Sotnikov, Oleg Shevnin
  14. #  1.3 - May 27: made it compatible with PowerGUI 1.8
  15. #  1.2 - Mar 30:
  16. #   added parameter to reset home page to default
  17. #   fixed the issue which aroused when path was supplied interactively
  18. #  1.1 - Mar 17: added exception if PowerGUI Admin Console is running
  19. #  v1, Feb 11, 2009
  20. #
  21. ########################################################
  22.  
  23. param ([string] $mhtpath, [bool] $ResetToDefault = $false)
  24. # this should be path (local or UNC) to the new welcome page
  25.  
  26. # make sure that the admin console is closed
  27. if (( get-process Quest.PowerGUI -ErrorAction SilentlyContinue ) -ne $null) {
  28.         throw "Please close the PowerGUI administrative console before running this script"
  29. }
  30.  
  31. # Locate PowerGUI configuration for current user on this computer
  32. $cfgpath = "$($env:APPDATA)\Quest Software\PowerGUI\quest.powergui.xml"
  33.  
  34. # If quest.powergui.xml not found - try new name of the file (PowerGUI 1.8 and later)
  35. if ( -not (Test-Path $cfgpath) ) {  
  36.         $cfgpath = "$($env:APPDATA)\Quest Software\PowerGUI\config.xml"
  37.  
  38.         if ( -not (Test-Path $cfgpath) ) {  
  39.                 throw "ERROR: PowerGUI configuration file not found"
  40.         }
  41. }
  42.  
  43.  
  44.  
  45. # Create backup
  46. Copy-Item $cfgpath "$cfgpath.backupconfig"
  47.  
  48. # Read the file
  49. $xml = [xml]$(Get-Content $cfgpath)
  50.  
  51.  
  52. # check if this is run to roll back the changes or to introduced them
  53. if ( $ResetToDefault ) {
  54.  
  55.         # Locate the custom homepage section
  56.         $node = $xml.SelectSingleNode("//container[@id='4b510268-a4eb-42e0-9276-06223660291d']")
  57.         if ($node -eq $null) {
  58.                 "Configuration is already using default homepage. No rollback required."
  59.         } else {
  60.                 $xml.SelectSingleNode("/configuration/items").RemoveChild($node) | Out-Null
  61.                 $xml.Save($cfgpath)
  62.                 "SUCCESS: Successfully rolled PowerGUI back to default welcome page."
  63.         }
  64.                
  65. } else {
  66.  
  67.         # change the welcome screen to the mht supplied as parameter
  68.        
  69.         # verify that the new file exists and is mht
  70.         if ( $mhtpath -eq $null ) {
  71.                 $mhtpath = Read-Host "Please provide path to the MHT file"
  72.         }
  73.         $mhtfile = Get-ChildItem $mhtpath
  74.         if ( $mhtfile -eq $null) {
  75.                 throw "MHT file $mhtpath not found. Please verify the script parameter."
  76.         }
  77.         if ( $mhtfile.Extension -ne ".mht" ) {
  78.                 throw "File $mhtpath is not an MHT file. Only MHT files are supported."
  79.         }
  80.        
  81.        
  82.         # If the section for custom welcome page does not exist - create it
  83.         $node = $xml.SelectSingleNode("//container[@id='4b510268-a4eb-42e0-9276-06223660291d']")
  84.         if ($node -eq $null) {
  85.                 $node = $xml.CreateElement("container")
  86.                
  87.                 $node.SetAttribute("id", "4b510268-a4eb-42e0-9276-06223660291d")
  88.                 $node.SetAttribute("name", "Home Page")
  89.                
  90.                 $node.AppendChild($xml.CreateElement("value")) | Out-Null
  91.                 $xml.SelectSingleNode("/configuration/items").AppendChild($node) | Out-Null
  92.         }
  93.        
  94.         # Set the new value and save the file
  95.         $node.Value = [String] $mhtpath
  96.         $xml.Save($cfgpath)
  97.         "SUCCESS: $mhtpath is now set as your custom welcome screen."
  98. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me