Public/New-Config.ps1

<#
    .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
    The new 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 {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '', Justification='needed to collect')]
    param(
        [Switch]
        $Prompt = $false,

        [ValidateNotNullOrEmpty()]
        [String]
        $SfUserName,

        [ValidateNotNullOrEmpty()]
        [String]
        $SfPassword,

        [ValidateNotNullOrEmpty()]
        [String]
        $SfSecurityToken,

        [ValidateNotNullOrEmpty()]
        [String]
        $SfOauthConsumerKey,

        [ValidateNotNullOrEmpty()]
        [String]
        $SfOauthConsumerSecret,

        [ValidateNotNullOrEmpty()]
        [String]
        $IamHsdpUserName,

        [ValidateNotNullOrEmpty()]
        [String]
        $IamHsdpUserPassword,

        [Switch]
        $SandBox = $false,

        [ValidateNotNullOrEmpty()]
        [String]
        $Path = "./config.xml",

        [String[]]
        $Scopes = @("profile","email","read_write")
    )
    $config = $null
    if ($Prompt) {
        $config = Read-Config
    } else {
        $config = (New-Object PSObject -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))
            IamCredentials = New-Object System.Management.Automation.PSCredential ($IamHsdpUserName, (ConvertTo-SecureString -String $IamHsdpUserPassword -AsPlainText -Force))
            Sandbox = $Sandbox
            Scopes = $Scopes
        })
    }
    if ($Path) {
        $config | Export-Clixml -Path $Path
    }
    Write-Output $config
}