128 lines
4.8 KiB
PowerShell
128 lines
4.8 KiB
PowerShell
|
function Open-AlkamiSites {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Opens Admin and WebClient Sites in the User's Default Browser
|
|||
|
|
|||
|
.DESCRIPTION
|
|||
|
Opens Admin and WebClient Sites in the User's Default Browser
|
|||
|
Supports opening admin sites only for VAU, sites based on a regex filter, or a random Client/Admin site set
|
|||
|
|
|||
|
.PARAMETER adminSitesOnly
|
|||
|
[switch] Opens only Admin sites on the server
|
|||
|
|
|||
|
.PARAMETER randomSite
|
|||
|
[switch] Opens a random Admin / WebClient URL from each matching site
|
|||
|
|
|||
|
.PARAMETER filter
|
|||
|
[string] A regex string used to match the site binding URI. Opens matching sites
|
|||
|
|
|||
|
.EXAMPLE
|
|||
|
Open-AlkamiSites
|
|||
|
PS C:\Users\dsage> Open-AlkamiSites
|
|||
|
[Open-AlkamiSites] : Opening URL https://myaccounts.bethpagefcu.com in default browser
|
|||
|
[Open-AlkamiSites] : Opening URL https://myaccounts.secumd.org in default browser
|
|||
|
[Open-AlkamiSites] : Opening URL https://myaccounts.bellco.org in default browser
|
|||
|
[Open-AlkamiSites] : Opening URL https://myadmin.bethpagefcu.com in default browser
|
|||
|
[Open-AlkamiSites] : Opening URL https://myadmin.secumd.org in default browser
|
|||
|
[Open-AlkamiSites] : Opening URL https://myadmin.bellco.org in default browser
|
|||
|
|
|||
|
.EXAMPLE
|
|||
|
Open-AlkamiSites -adminSitesOnly
|
|||
|
|
|||
|
PS C:\Users\dsage> Open-AlkamiSites -adminSitesOnly
|
|||
|
[Open-AlkamiSites] : Opening URL https://myadmin.bethpagefcu.com in default browser
|
|||
|
[Open-AlkamiSites] : Opening URL https://myadmin.secumd.org in default browser
|
|||
|
[Open-AlkamiSites] : Opening URL https://myadmin.bellco.org in default browser
|
|||
|
|
|||
|
.EXAMPLE
|
|||
|
Open-AlkamiSites -random
|
|||
|
|
|||
|
PS C:\Users\dsage> Open-AlkamiSites -random
|
|||
|
[Open-AlkamiSites] : Grabbing random entry for site WebClient
|
|||
|
[Open-AlkamiSites] : Opening URL https://myaccounts.bethpagefcu.com in default browser
|
|||
|
[Open-AlkamiSites] : Grabbing random entry for site WebClientAdmin
|
|||
|
[Open-AlkamiSites] : Opening URL https://myadmin.secumd.org in default browser
|
|||
|
|
|||
|
.EXAMPLE
|
|||
|
Open-AlkamiSites -filter bellco
|
|||
|
|
|||
|
PS C:\Users\dsage> Open-AlkamiSites -filter bellco
|
|||
|
[Open-AlkamiSites] : Opening URL https://myaccounts.bellco.org in default browser
|
|||
|
[Open-AlkamiSites] : Opening URL https://myadmin.bellco.org in default browser
|
|||
|
#>
|
|||
|
[CmdletBinding()]
|
|||
|
[OutputType([System.Object])]
|
|||
|
Param(
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[Alias("AdminOnly")]
|
|||
|
[switch]$adminSitesOnly,
|
|||
|
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[Alias("Random")]
|
|||
|
[switch]$randomSite,
|
|||
|
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[string]$filter = "",
|
|||
|
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[switch]$returnSites
|
|||
|
|
|||
|
)
|
|||
|
|
|||
|
$logLead = (Get-LogLeadName);
|
|||
|
|
|||
|
try {
|
|||
|
$sites = Get-IisSiteList -adminSitesOnly:$adminSitesOnly
|
|||
|
} catch [System.Management.Automation.RuntimeException] {
|
|||
|
Write-Warning "$logLead : Could not find any WebClient or WebClientAdmin sites on this server"
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
$openedSites = @()
|
|||
|
$sites | Where-Object { $_.State -eq "Started" } | ForEach-Object {
|
|||
|
|
|||
|
# Grab only the sites with HTTPS bindings (applying filter if applicable).
|
|||
|
$httpsSites = $_.Bindings | Where-Object { $_.Protocol -like "https" } | Where-Object { $_.Host -match $filter }
|
|||
|
|
|||
|
# Did we find any?
|
|||
|
if ($null -eq $httpsSites) {
|
|||
|
# Nope. Was it more than likely a problem with their filter?
|
|||
|
if ($null -ne $filter) {
|
|||
|
# Show the user their filter with the warning.
|
|||
|
Write-Warning ("$logLead : Could not find any https bindings for site {0} that matches filter '{1}'" -f $_.Name, $filter)
|
|||
|
} else {
|
|||
|
# Just show the user the warning.
|
|||
|
Write-Warning ("$logLead : Could not find any https bindings for site {0}" -f $_.Name)
|
|||
|
}
|
|||
|
} else {
|
|||
|
# Are we randomly selecting the site from the list?
|
|||
|
if ($randomSite.IsPresent) {
|
|||
|
|
|||
|
# Log what we're doing.
|
|||
|
Write-Host ("$logLead : Grabbing random entry for site {0}" -f $_.Name)
|
|||
|
|
|||
|
# Grab a random object from the list.
|
|||
|
[array]$httpBindings = Get-Random -InputObject $httpsSites
|
|||
|
} else {
|
|||
|
|
|||
|
# Log what we're doing.
|
|||
|
Write-Verbose ("$logLead : Opening each HTTPS binding for site {0}" -f $_.Name)
|
|||
|
|
|||
|
# Grab the first object from the list.
|
|||
|
[array]$httpBindings = $httpsSites
|
|||
|
}
|
|||
|
|
|||
|
# Build the URL, log it, and open each matching binding.
|
|||
|
foreach ($httpBinding in $httpBindings) {
|
|||
|
|
|||
|
$urlString = "{0}://{1}" -f $httpBinding.Protocol, $httpBinding.Host
|
|||
|
Write-Host ("$logLead : Opening URL {0} in default browser" -f $urlString)
|
|||
|
Open-UrlInDefaultBrowser $urlString | Out-Null
|
|||
|
$openedSites += $httpBindings
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if ($returnSites.IsPresent) {
|
|||
|
return $openedSites
|
|||
|
}
|
|||
|
}
|