Public/New-Config.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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
<# .SYNOPSIS Initialize a new org configuration .DESCRIPTION Creates a new org configuration and writes it to a file. .INPUTS None. You cannot pipe objects to New-Config. .OUTPUTS A new PSCustomObject with configuration .PARAMETER Prompt If you should be prompted for the values. Default is $false .PARAMETER SfUserName The Salesforce username to connect to the connected App .PARAMETER SfPassword The Salesforce password to connect to the connected App .PARAMETER SfSecurityToken The Salesforce security token to connect to the connected App .PARAMETER SfOauthConsumerKey The Salesforce connected app consumer key .PARAMETER SfOauthConsumerSecret The Salesforce connected app consumer secret .PARAMETER IamHsdpUserName The HSDP IAM username that has access to the CDR/PDS instance .PARAMETER IamHsdpUserPassword The HSDP IAM password for he username that has access to the CDR/PDS instance .PARAMETER SandBox Indicates if this is a sandbox instance. Defaults to $false (Note: $true has not been tested ) .PARAMETER Path The path to write the persistant configuration file. Defaults to "config.xml" .PARAMETER Scopes An array of scope values for HSDP IAM. defaults to @("profile","email","read_write") .EXAMPLE PS> New-Config -SfUserName "philipsupport@ecc.onboard" -SfPassword "23457293457829345" -SfSecurityToken "lkjLkdfjLKFjdLKJflDKJFF" ` -SfOauthConsumerKey "3MVG9JZ_r.QzrS7izXVWrETc3v0NfBxwFgCay87uv43B4MWDgRSVaTnGG.zn2dddYk8tRk2ea5memOKg4hd22" -SfOauthConsumerSecret "3487139487139487134" ` -IamHsdpUserName "testqlikpdsupgrade@mailinator.com" -IamHsdpUserPassword "LDSKJHF*#RSKLKFJD" -Scopes @("profile","email","READ_WRITE") #> function New-Config { [CmdletBinding()] [OutputType([PSCustomObject])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '', Justification = 'needed to collect')] param( [Parameter(Mandatory = $false, Position = 0)] [Bool] $Prompt = $false, [Parameter(Mandatory = $false, Position = 1)] [ValidateNotNullOrEmpty()] [String] $SfUserName, [Parameter(Mandatory = $false, Position = 2)] [ValidateNotNullOrEmpty()] [String] $SfPassword, [Parameter(Mandatory = $false, Position = 3)] [ValidateNotNullOrEmpty()] [String] $SfSecurityToken, [Parameter(Mandatory = $false, Position = 4)] [ValidateNotNullOrEmpty()] [String] $SfOauthConsumerKey, [Parameter(Mandatory = $false, Position = 5)] [ValidateNotNullOrEmpty()] [String] $SfOauthConsumerSecret, [Parameter(Mandatory = $false, Position = 6)] [ValidateNotNullOrEmpty()] [String] $IamHsdpUserName, [Parameter(Mandatory = $false, Position = 7)] [ValidateNotNullOrEmpty()] [String] $IamHsdpUserPassword, [Parameter(Mandatory = $false, Position = 8)] [Switch] $SandBox = $false, [Parameter(Mandatory = $false, Position = 9)] [String] $Path = "./config.xml", [Parameter(Mandatory = $false, Position = 10)] [String[]] $Scopes = @("profile", "email", "read_write"), [Parameter(Mandatory = $false, Position = 11)] [ValidateNotNullOrEmpty()] [String] $ServiceKeyFile, [Parameter(Mandatory = $false, Position = 12)] [ValidateNotNullOrEmpty()] [String] $ServiceAppId ) begin { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" } end { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete" } process { Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $config = $null if ($Prompt) { $config = Read-Config } else { if ($PSBoundParameters.ContainsKey('ServiceKeyFile')) { if (-not (Test-Path $ServiceKeyFile -PathType Leaf)) { throw "Service Keyfile '$($ServiceKeyFile)' does not exist." } } $config = (New-Object PSCustomObject -Property @{ SfCredentials = New-Object System.Management.Automation.PSCredential ($SfUserName, (ConvertTo-SecureString -String $SfPassword -AsPlainText -Force)) SfSecurityToken = $SfSecurityToken SfOauth = New-Object System.Management.Automation.PSCredential ($SfOauthConsumerKey, (ConvertTo-SecureString -String $SfOauthConsumerSecret -AsPlainText -Force)) Sandbox = $Sandbox Scopes = $Scopes }) if ($ServiceKeyFile -and $ServiceAppId) { $config | Add-Member -MemberType NoteProperty -Name "ServiceKeyFile" -Value $ServiceKeyFile $config | Add-Member -MemberType NoteProperty -Name "ServiceAppId" -Value $ServiceAppId } if ($IamHsdpUserName -and $IamHsdpUserPassword) { $config | Add-Member -MemberType NoteProperty -Name "IamCredentials" -Value (New-Object System.Management.Automation.PSCredential ($IamHsdpUserName, (ConvertTo-SecureString -String $IamHsdpUserPassword -AsPlainText -Force))) } } if ($Path) { $config | Export-Clixml -Path $Path } Write-Output $config } } |