-
-
Notifications
You must be signed in to change notification settings - Fork 271
/
Get-GPPShortcut.ps1
180 lines (153 loc) · 6.14 KB
/
Get-GPPShortcut.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
Function Get-GPPShortcut {
<#
.SYNOPSIS
Find GPP Shortcut preference items in your current domain.
.DESCRIPTION
Find GPP Shortcut preference items in your current domain.
If no parameter is specified, search all GPOs
Requires GroupPolicy module. Get it in the RSAT, enable the Windows Feature.
The filters property will be an array of all filters
.PARAMETER GUID
If specified, search this GUID
.PARAMETER Name
If specified, search this Name
.FUNCTIONALITY
Group Policy
.EXAMPLE
#Get all group policy preferences with shortcut preference items
Get-GPPShortcut
.EXAMPLE
#Explore basic info in out grid view
Get-GPPShortcut | Select GPOName, action, TargetPath, Arguments, shortcutPath | out-gridview
.EXAMPLE
#Pick a date to filter shortcuts by
$date = (get-date).adddays(-7)
#Find shortcuts changed in last 7 days, explore in gridview
Get-GPPShortcut | ?{$_.changed -gt $date} | Sort Changed -descending | out-gridview
.EXAMPLE
#Get all shortcut items from the 'Group policy x' GPO
Get-GPPShortcut -Name "Group policy x"
.NOTES
Thanks to Johan Dahlbom for the workflow this command borrows: http://365lab.net/2013/12/31/getting-all-gpp-drive-maps-in-a-domain-with-powershell/
#>
[cmdletbinding(DefaultParameterSetName='Name')]
param(
[Parameter( Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ParameterSetName='Name'
)]
[string[]]$Name = $null,
[Parameter( Position=1,
ParameterSetName='GUID'
)]
[string[]]$GUID = $null
)
Begin
{
try
{
Import-Module GroupPolicy -ErrorAction Stop
If(-not (Get-Module GroupPolicy -ErrorAction SilentlyContinue))
{
throw "GroupPolicy module not Installed"
break
}
}
catch
{
throw "Error importing GroupPolicy module: $_"
break
}
$xmlProps = "NamespaceURI",
"Prefix",
"NodeType",
"ParentNode",
"OwnerDocument",
"IsEmpty",
"Attributes",
"HasAttributes",
"SchemaInfo",
"InnerXml",
"InnerText",
"NextSibling",
"PreviousSibling",
"Value",
"ChildNodes",
"FirstChild",
"LastChild",
"HasChildNodes",
"IsReadOnly",
"OuterXml",
"BaseURI"
}
Process
{
#if name or guid isn't specified, get them all
if(-not $GUID -and -not $Name)
{
Write-Verbose "Getting all GPOs"
$GPO = Get-GPO -all
}
#If a GUID or Name is specified, get the GPOs
if ( $Name -and $PsCmdlet.ParameterSetName -eq "Name" )
{
$GPO = foreach($nam in $Name)
{
Get-GPO -Name $nam
}
}
if( $GUID -and $PsCmdlet.ParameterSetName -eq "GUID" )
{
$GPO = foreach($ID in $GUID)
{
Get-GPO -Guid $ID
}
}
foreach ($Policy in $GPO){
$GPOID = $Policy.Id
$GPODom = $Policy.DomainName
$GPODisp = $Policy.DisplayName
#we want to check both user and computer configurations
$configTypes = "User", "Machine"
foreach($configType in $configTypes)
{
#Test the path in sysvol where drive maps would be...
$path = "\\$($GPODom)\SYSVOL\$($GPODom)\Policies\{$($GPOID)}\$configType\Preferences\Shortcuts\Shortcuts.xml"
if (Test-Path $path -ErrorAction SilentlyContinue)
{
[xml]$xml = Get-Content $path
#Pull relevant data from the xml
foreach ( $prefItem in $xml.Shortcuts.Shortcut )
{
#Get all filters for this preference item
$childNodes = @( $prefItem.filters.childnodes )
#output the object with appropriate properties, sorted
New-Object PSObject -Property @{
GPOName = $GPODisp
ConfigType = $configType
action = $prefItem.Properties.action.Replace("U","Update").Replace("C","Create").Replace("D","Delete").Replace("R","Replace")
targetType = $prefItem.Properties.targetType
targetPath = $prefItem.Properties.targetPath
shortcutKey = $prefItem.Properties.shortcutKey
startIn = $prefItem.Properties.startIn
arguments = $prefItem.Properties.arguments
iconPath = $prefItem.Properties.iconPath
window = $prefItem.Properties.window
shortcutPath = $prefItem.Properties.shortcutPath
disabled = $prefItem.disabled
changed = $( Try { Get-Date "$( $prefItem.changed )"} Catch {"Err"} )
filters = $(
#Here we loop through each filter, only select the non-XML properties
foreach($filter in $childNodes){
Try { $filter | select -Property * -ExcludeProperty $xmlProps }
Catch { Continue }
}
)
} | Select GPOName, ConfigType, action, targetType, targetPath, shortcutKey, startIn, arguments, iconPath, window, shortcutPath, disabled, changed, filters
}
}
}
}
}
}