PoshCode Logo PowerShell Code Repository

Set-PowerGUIWelcomePage by Dmitry Sotnikov 34 months ago (modification of post by Dmitry Sotnikov view diff)
View followups from Dmitry Sotnikov | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/984"></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.2 adds the ability to roll the welcome page back to default

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

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