-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathcf-create-service.ps1
More file actions
28 lines (24 loc) · 1.63 KB
/
cf-create-service.ps1
File metadata and controls
28 lines (24 loc) · 1.63 KB
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
#Requires -Version 7.0
Param(
[Parameter(Mandatory = $true, HelpMessage = "UNC path to the network share. For example: '\\localhost\steeltoe_network_share'")][string]$NetworkAddress,
[Parameter(Mandatory = $true, HelpMessage = "The username for accessing the file share, can include domain. For example: 'DOMAIN\username'")][string]$UserName,
[Parameter(Mandatory = $true, HelpMessage = "The password for accessing the file share.")][string]$Password,
[Parameter(Mandatory = $false, HelpMessage = "The name of the service for storing credentials")][string]$ServiceName = "credhub",
[Parameter(Mandatory = $false, HelpMessage = "The service plan to use")][string]$ServicePlan = "default",
[Parameter(Mandatory = $false, HelpMessage = "The name of the service instance")][string]$ServiceInstanceName = "sampleNetworkShare"
)
$ErrorActionPreference = "Stop"
# Build parameter object and convert to JSON using PowerShell's built-in JSON serialization
# This automatically handles escaping of special characters including backslashes, quotes, etc.
$params = @{
location = $NetworkAddress
username = $UserName
password = $Password
}
$jsonParams = $params | ConvertTo-Json -Compress
# Create a redacted copy of the parameters for logging so the password is not exposed
$redactedParams = $params.Clone()
$redactedParams['password'] = 'REDACTED'
$redactedJsonParams = $redactedParams | ConvertTo-Json -Compress
Write-Host "cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $redactedJsonParams -t $ServiceInstanceName"
cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $jsonParams -t $ServiceInstanceName