-
Notifications
You must be signed in to change notification settings - Fork 20
/
AlertArchiveImporter.ps1
54 lines (44 loc) · 2.07 KB
/
AlertArchiveImporter.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
#Requires -Modules pcsx
<#------------- FUNCTIONS -------------#>
Function Set-SwisConnection {
Param(
[Parameter(Mandatory=$true, HelpMessage = "What SolarWinds server are you connecting to (Hostname or IP)?" ) ] [string] $solarWindsServer,
[Parameter(Mandatory=$true, HelpMessage = "Do you want to use the credentials from PowerShell [Trusted], or a new login [Explicit]?" ) ] [ ValidateSet( 'Trusted', 'Explicit' ) ] [ string ] $connectionType,
[Parameter(HelpMessage = "Which credentials should we use for an explicit logon type" ) ] $creds
)
IF ( $connectionType -eq 'Trusted' ) {
$swis = Connect-Swis -Trusted -Hostname $solarWindsServer
} ELSEIF(!$creds) {
$creds = Get-Credential -Message "Please provide a Domain or Local Login for SolarWinds"
$swis = Connect-Swis -Credential $creds -Hostname $solarWindsServer
} ELSE {
$swis = Connect-Swis -Credential $creds -Hostname $solarWindsServer
}
RETURN $swis
}
<#------------- ACTUAL SCRIPT -------------#>
clear-host
$now = Get-Date -Format "yyyyMMdd_HHmm"
$script = $MyInvocation.MyCommand
try { $dir = Split-Path $script.path }
catch { }
$Logfile = "$dir\$($script.name)_$now.log"
Start-Transcript -Path $Logfile -Append -IncludeInvocationHeader | Out-Null
while(!$swistest) {
$hostname = Read-Host -Prompt "what server should we connect to?"
$connectionType = Read-Host -Prompt "Should we use the current powershell credentials [Trusted], or specify credentials [Explicit]?"
$swis = Set-SwisConnection $hostname $connectionType
$swistest = get-swisdata $swis "SELECT TOP 1 servername FROM Orion.Websites"
}
"Connected to $hostname Successfully using $connectiontype credentials"
# set up path to current user desktop
$UserPath = "$($env:USERPROFILE)\Desktop\AlertExports\"
# get exported alerts from folder
$Alerts = (Get-ChildItem -Path $($UserPath+"\*.xml") -Recurse -Force).FullName
foreach ($Alert in $Alerts) {
"Importing $Alert"
$toDo = ([xml](get-content -Path $Alert)).return
$result = Invoke-SwisVerb $swis Orion.AlertConfigurations Import $toDo
}
"Finished"
Stop-Transcript