Skip to content

Commit 09f8039

Browse files
committed
Update global variables and fix linefeed issue
1 parent a4ec4eb commit 09f8039

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

recipes/powershell/New-Policy-StepByStep.ps1

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Param (
2323
####################
2424

2525
$port = 1556
26-
$basePath = "https://" + $MasterServer + ":" + $port + "/netbackup"
26+
$baseUri = "https://" + $MasterServer + ":" + $port + "/netbackup/"
27+
$policiesUri = "config/policies/";
2728
$contentType = "application/vnd.netbackup+json;version=2.0"
2829
$testPolicyName = "vmware_test_policy"
2930
$testClientName = "MEDIA_SERVER"
@@ -32,14 +33,12 @@ $testScheduleName = "vmware_test_schedule"
3233
###############################################################
3334
# Setup to allow self-signed certificates and enable TLS v1.2
3435
###############################################################
35-
3636
Function Setup()
3737
{
3838
# Allow self-signed certificates
3939
if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy')
4040
{
41-
Add-Type -TypeDefinition
42-
@"
41+
Add-Type -TypeDefinition @"
4342
using System.Net;
4443
using System.Security.Cryptography.X509Certificates;
4544
public class TrustAllCertsPolicy : ICertificatePolicy {
@@ -56,7 +55,7 @@ Function Setup()
5655
# Force TLS v1.2
5756
try {
5857
if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') {
59-
[Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
58+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
6059
}
6160
}
6261
catch {
@@ -70,7 +69,7 @@ Function Setup()
7069

7170
Function Login()
7271
{
73-
$uri = $basepath + "/login"
72+
$uri = $baseUri + "login"
7473

7574
$body = @{
7675
userName=$UserName
@@ -106,7 +105,7 @@ Function Login()
106105
#################################################
107106
Function CreatePolicyWithDefaults()
108107
{
109-
$uri = $basepath + "/config/policies"
108+
$uri = $baseUri + $policiesUri
110109

111110
$policy = @{
112111
policyName=$testPolicyName
@@ -147,7 +146,7 @@ Function CreatePolicyWithDefaults()
147146
#####################
148147
Function ListPolicies()
149148
{
150-
$uri = $basepath + "/config/policies"
149+
$uri = $baseUri + $policiesUri
151150

152151
Write-Host "`nSending a GET request to list all policies...`n"
153152
$response = Invoke-WebRequest `
@@ -169,7 +168,7 @@ Function ListPolicies()
169168
#################
170169
Function ReadPolicy()
171170
{
172-
$uri = $basepath + "/config/policies/" + $testPolicyName
171+
$uri = $baseUri + $policiesUri + $testPolicyName
173172

174173
Write-Host "`nSending a GET request to read policy $testPolicyName...`n"
175174
$response = Invoke-WebRequest `
@@ -191,7 +190,7 @@ Function ReadPolicy()
191190
###################
192191
Function DeletePolicy()
193192
{
194-
$uri = $basepath + "/config/policies/" + $testPolicyName
193+
$uri = $baseUri + $policiesUri + $testPolicyName
195194

196195
Write-Host "`nSending a DELETE request to delete policy $testPolicyName..."
197196

@@ -214,7 +213,7 @@ Function DeletePolicy()
214213
############################
215214
Function AddClient()
216215
{
217-
$uri = $basepath + "/config/policies/" + $testPolicyName + "/clients/" + $testClientName
216+
$uri = $baseUri + $policiesUri + $testPolicyName + "/clients/" + $testClientName
218217

219218
$data = @{
220219
type="client"
@@ -248,7 +247,7 @@ Function AddClient()
248247
#################################
249248
Function DeleteClient()
250249
{
251-
$uri = $basepath + "/config/policies/" + $testPolicyName + "/clients/" + $testClientName
250+
$uri = $baseUri + $policiesUri + $testPolicyName + "/clients/" + $testClientName
252251

253252
Write-Host "`nSending a DELETE request to delete client $testClientName from policy $testPolicyName..."
254253

@@ -271,7 +270,7 @@ Function DeleteClient()
271270
######################################
272271
Function AddBackupSelection()
273272
{
274-
$uri = $basepath + "/config/policies/" + $testPolicyName + "/backupselections"
273+
$uri = $baseUri + $policiesUri + $testPolicyName + "/backupselections"
275274

276275
$data = @{
277276
type="backupSelection"
@@ -303,7 +302,7 @@ Function AddBackupSelection()
303302
############################
304303
Function AddSchedule()
305304
{
306-
$uri = $basepath + "/config/policies/" + $testPolicyName + "/schedules/" + $testScheduleName
305+
$uri = $baseUri + $policiesUri + $testPolicyName + "/schedules/" + $testScheduleName
307306

308307
$data = @{
309308
type="schedule"
@@ -370,7 +369,6 @@ Function AddSchedule()
370369
}
371370

372371
$body = @{data=$data} | ConvertTo-Json -Depth 6
373-
Write-Host $body
374372

375373
Write-Host "`nSending a PUT request to add schedule $testScheduleName to policy $testPolicyName..."
376374
$response = Invoke-WebRequest `
@@ -393,7 +391,7 @@ Function AddSchedule()
393391
###################################
394392
Function DeleteSchedule()
395393
{
396-
$uri = $basepath + "/config/policies/" + $testPolicyName + "/schedules/" + $testScheduleName
394+
$uri = $baseUri + $policiesUri + $testPolicyName + "/schedules/" + $testScheduleName
397395

398396
Write-Host "`nSending a DELETE request to delete schedule $testScheduleName from policy $testPolicyName..."
399397

0 commit comments

Comments
 (0)