PoshCode Archive  Check-in [e111cdcac1]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:e111cdcac10c25ccde77365243e0730e4ce5c17e4cb22b192e3776816a00bb6e
User & Date: Dmitry Sotnikov 2018-06-10 14:27:51
Context
2018-06-10
14:27
Check and md5 or sha1 hash in a “single line” of PowerShell. check-in: 43450bf8b2 user: Joel Bennett tags: trunk
14:27
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. check-in: e111cdcac1 user: Dmitry Sotnikov tags: trunk
14:27
Generates a Linux VMDK Backup Script check-in: 5c57dea9b6 user: Patrick tags: trunk
Changes

Changes to Set-PowerGUIWelcomePage.ps1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24

25


26
27



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61































62
63
64
65
66
67
68
69
70
71
72
73
74
75
76


# encoding: ascii
# api: powershell
# title: Set-PowerGUIWelcomePage
# description: 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.
# version: 1.1
# type: script
# author: Dmitry Sotnikov
# license: CC0
# x-poshcode-id: 961
# x-derived-from-id: 984
# x-archived: 2016-03-19T17:57:10
# x-published: 2009-03-17T14:17:00
#
# 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.

# See http://dmitrysotnikov.wordpress.com/2009/02/11/rebranding-powergui-consolerebranding-powergui-console/ for details
#
########################################################
# Modifies the default PowerGUI admin console
# welcome screen to the mht file you supply
# Details available at:
# http://dmitrysotnikov.wordpress.com/2009/02/11/rebranding-powergui-consolerebranding-powergui-console/ 
########################################################
# Usage:

# & .\Set-PowerGUIWelcomePage.ps1 \\server\share\my.mht


########################################################
# (c) Dmitry Sotnikov, Oleg Shevnin



#  1.1 - Mar 17: added exception if PowerGUI Admin Console is running
#  v1, Feb 11, 2009
#
########################################################

param ($mhtpath)
# this should be path (local or UNC) to the new welcome page

# make sure that the admin console is closed
if (( get-process Quest.PowerGUI -ErrorAction SilentlyContinue ) -ne $null) { 
	throw "Please close the PowerGUI administrative console before running this script " 
}

# verify that the new file exists and is mht
if ( $mhtpath -eq $null ) {
	$mhtpath = Read-Host "Please provide path to the MHT file."
}
$mhtfile = Get-ChildItem $mhtpath
if ( $mhtfile -eq $null) { 
	throw "MHT file $mhtpath not found. Please verify the script parameter." 
}
if ( $mhtfile.Extension -ne ".mht" ) {
	throw "File $mhtpath is not an MHT file. Only MHT files are supported." 
}

# Locate PowerGUI configuration for current user on this computer
$cfgpath = "$($env:APPDATA)\Quest Software\PowerGUI\quest.powergui.xml"

# Create backup
Copy-Item $cfgpath "$cfgpath.backupconfig"

# Read the file
$xml = [xml]$(Get-Content $cfgpath)
































# If the section for custom welcome page does not exist - create it
$node = $xml.SelectSingleNode("//container[@id='4b510268-a4eb-42e0-9276-06223660291d']")
if ($node -eq $null) {
	$node = $xml.CreateElement("container")
	
	$node.SetAttribute("id", "4b510268-a4eb-42e0-9276-06223660291d")
	$node.SetAttribute("name", "Home Page")
	
	$node.AppendChild($xml.CreateElement("value"))
	$xml.SelectSingleNode("/configuration/items").AppendChild($node)
}

# Set the new value and save the file
$node.Value = $mhtpath
$xml.Save($cfgpath)






|



|
|
|
|



>









>
|
>
>


>
>
>





|




|
<
<
<
<
<
<
<
<
<
<
<
<











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45












46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# encoding: ascii
# api: powershell
# title: Set-PowerGUIWelcomePage
# description: 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.
# version: 1.2
# type: script
# author: Dmitry Sotnikov
# license: CC0
# x-poshcode-id: 984
# x-derived-from-id: 1129
# x-archived: 2016-03-05T14:30:37
# x-published: 2010-03-30T08:34:00
#
# 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
#
########################################################
# Modifies the default PowerGUI admin console
# welcome screen to the mht file you supply
# Details available at:
# http://dmitrysotnikov.wordpress.com/2009/02/11/rebranding-powergui-consolerebranding-powergui-console/ 
########################################################
# Usage:
# To change the homepage:
#   & .\Set-PowerGUIWelcomePage.ps1 \\server\share\my.mht
# To rollback the change:
#   & .\Set-PowerGUIWelcomePage.ps1 -ResetToDefault $true
########################################################
# (c) Dmitry Sotnikov, Oleg Shevnin
#  1.2 - Mar 30:
#   added parameter to reset home page to default
#   fixed the issue which aroused when path was supplied interactively
#  1.1 - Mar 17: added exception if PowerGUI Admin Console is running
#  v1, Feb 11, 2009
#
########################################################

param ([string] $mhtpath, [bool] $ResetToDefault = $false)
# this should be path (local or UNC) to the new welcome page

# make sure that the admin console is closed
if (( get-process Quest.PowerGUI -ErrorAction SilentlyContinue ) -ne $null) { 
	throw "Please close the PowerGUI administrative console before running this script" 












}

# Locate PowerGUI configuration for current user on this computer
$cfgpath = "$($env:APPDATA)\Quest Software\PowerGUI\quest.powergui.xml"

# Create backup
Copy-Item $cfgpath "$cfgpath.backupconfig"

# Read the file
$xml = [xml]$(Get-Content $cfgpath)


# check if this is run to roll back the changes or to introduced them
if ( $ResetToDefault ) {

	# Locate the custom homepage section
	$node = $xml.SelectSingleNode("//container[@id='4b510268-a4eb-42e0-9276-06223660291d']")
	if ($node -eq $null) {
		"Configuration is already using default homepage. No rollback required."
	} else {
		$xml.SelectSingleNode("/configuration/items").RemoveChild($node) | Out-Null 
		$xml.Save($cfgpath)
		"SUCCESS: Successfully rolled PowerGUI back to default welcome page."
	}
		
} else {

	# change the welcome screen to the mht supplied as parameter
	
	# verify that the new file exists and is mht
	if ( $mhtpath -eq $null ) {
		$mhtpath = Read-Host "Please provide path to the MHT file"
	}
	$mhtfile = Get-ChildItem $mhtpath
	if ( $mhtfile -eq $null) { 
		throw "MHT file $mhtpath not found. Please verify the script parameter." 
	}
	if ( $mhtfile.Extension -ne ".mht" ) {
		throw "File $mhtpath is not an MHT file. Only MHT files are supported." 
	}
	
	
	# If the section for custom welcome page does not exist - create it
	$node = $xml.SelectSingleNode("//container[@id='4b510268-a4eb-42e0-9276-06223660291d']")
	if ($node -eq $null) {
		$node = $xml.CreateElement("container")
		
		$node.SetAttribute("id", "4b510268-a4eb-42e0-9276-06223660291d")
		$node.SetAttribute("name", "Home Page")
		
		$node.AppendChild($xml.CreateElement("value")) | Out-Null 
		$xml.SelectSingleNode("/configuration/items").AppendChild($node) | Out-Null 
	}
	
	# Set the new value and save the file
	$node.Value = [String] $mhtpath
	$xml.Save($cfgpath)
	"SUCCESS: $mhtpath is now set as your custom welcome screen."
}