-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNWPSRestToolKit.psm1
76 lines (74 loc) · 2.32 KB
/
NWPSRestToolKit.psm1
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
function Connect-NWServer
{
[CmdletBinding()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$NWIP = "192.168.2.11",
$NWPort = 9090,
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
Position=0)][pscredential]$Credentials,
[switch]$trustCert
)
Begin
{
if ($trustCert.IsPresent)
{
Unblock-NWCerts
}
}
Process
{
if (!$Credentials)
{
$User = Read-Host -Prompt "Please enter the username for Networker Administrator"
$SecurePassword = Read-Host -Prompt "Enter Networker Password for user $user" -AsSecureString
$Global:NWCredentials = New-Object System.Management.Automation.PSCredential (“$user”,$Securepassword)
}
$Global:NWbaseurl = "https://$($NWIP):$($NWPort)/nwrestapi/v3"
}
End
{
Get-NWserverconfig | select name,serverOSType
}
}
function Unblock-NWCerts
{
Add-Type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy
}
function Get-NWyesno
{
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
SupportsShouldProcess=$true,
PositionalBinding=$false,
HelpUri = 'http://labbuildr.com/',
ConfirmImpact='Medium')]
Param
(
$title = "Delete Files",
$message = "Do you want to delete the remaining files in the folder?",
$Yestext = "Yestext",
$Notext = "notext"
)
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","$Yestext"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","$Notext"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($no, $yes)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
return ($result)
}