-
Notifications
You must be signed in to change notification settings - Fork 20
/
AddCustomMenusInteractively.ps1
72 lines (56 loc) · 2.18 KB
/
AddCustomMenusInteractively.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
<#------------- CONNECT TO SWIS -------------#>
# load the snappin if it's not already loaded (step 1)
if (!(Get-PSSnapin | Where-Object { $_.Name -eq "SwisSnapin" })) {
Add-PSSnapin "SwisSnapin"
}
$hostname = "localhost"
$swis = Connect-Swis -Hostname $hostname -Trusted
#alternative connection method
#$user = "user"
#$password = "pass"
#$swis = connect-swis -host $hostname -username $user -password $password -ignoresslerrors
<#------------- ACTUAL SCRIPT -------------#>
$MenuTitle = Read-Host -Prompt "What is the title of the drop down menu you want to work with?"
# check if that drop down already exiss
$MenuTest = get-swisdata $swis @"
SELECT ID, Name, DefaultTitle, Tags, SortOrder, OrionFeatureName, URI
FROM Orion.Web.ViewGroup
where DefaultTitle = '$MenuTitle'
"@
if (!$MenuTest) {
$MenuProps = @{
Name = $MenuTitle.replace(' ','')
DefaultTitle = $MenuTitle
Tags = "navigation"
SortOrder = 99
}
"`Creating new menu called $MenuTitle"
$MenuResults = New-SwisObject -SwisConnection $swis -EntityType "Orion.Web.ViewGroup" -Properties $MenuProps
} else {
$MenuResults = $MenuTest.URI
}
"`Menu called $MenuTitle exists..."
$ViewURL = Read-Host -Prompt "What is the URL you want to add to this menu? (You can provide full URL's or use relative links by starting the address with a '/')"
$ViewTitle = Read-Host -Prompt "What is the title you want to give to this item?"
$ViewProps = @{
Name = $ViewTitle.replace(' ','-')
DefaultTitle = $ViewTitle
Type = "legacy"
URL = $ViewURL
IsCustom = "True"
SortOrder = 0
OpenInNewWindow = "False"
}
"`Creating new menu item called $ViewTitle under $MenuTitle"
$ViewResults = New-SwisObject -SwisConnection $swis -EntityType "Orion.Web.View" -Properties $ViewProps
$MenuID = get-swisdata $swis @"
SELECT ID FROM Orion.Web.ViewGroup where uri = '$MenuResults'
"@
$ViewID = get-swisdata $swis @"
SELECT ID FROM Orion.Web.View where uri = '$ViewResults'
"@
$LinkViewtoGroup = Invoke-SwisVerb $swis 'Orion.Reporting' 'ExecuteSQL' @"
INSERT WebViewGroupWebView (WebViewGroupID, WebViewID, SortOrder)
VALUES ($MenuID,$ViewID,0)
"@
$ClearCache = Invoke-SwisVerb $swis 'Orion.Web.Menu' 'ClearCache' -Arguments ""