Module/Administration/New-BCSTenant.ps1
<#
.SYNOPSIS Sets up a new Brightcom Tenant .DESCRIPTION .PARAMETER asda .NOTES Author: Mathias Stjernfelt Website: http://www.brightcom.se .EXAMPLE New-BCSTenant -CustomerName "Your Customer Name" -CreatePasswordStateEntry -PasswordStateUrl "https://passwordstate" -PasswordStateApiKey (Get-BCSSecureString "Your Private API Key") New-BCSTenant -CustomerName "Your Customer Name" #> function New-BCSTenant { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUsernameAndPasswordParams', '')] Param ( [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)] $CustomerName, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] [System.Management.Automation.PSCredential]$databaseCredentials, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)] $businessCentralServer, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] $businessCentralserverInstance = "BCNUP", [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)] $databaseServer, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] $databaseServerInstance = "SEBCDB02", [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] $templateDatabase = "Template (19-0)", [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] $tempFolder = "c:\temp\", [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] [switch]$CreatePasswordStateEntry = $false, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] $PasswordStateListID = "6", [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] $PasswordStateUrl, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] [SecureString]$PasswordStateApiKey, [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)] $businessCentralUserName = "admin" ) begin { if ($CreatePasswordStateEntry) { if (-not $PasswordStateUrl) { Throw "You need to specify a Password State URL using parameter -PasswordStateUrl" } if (-not $PasswordStateApiKey) { Throw "You need to specify a Password State Api Key using parameter -PasswordStateApiKey" } } } process { $userProfile = Get-BCSModuleProfile if (-not $databaseCredentials) { $databaseCredentials = Get-BCSCredential -userName $userProfile.databaseUserName -securePassword (ConvertTo-SecureString -String $userProfile.databasePassword) } try { # New-BCSTenantDatabase -databaseServer $databaseServer ` # -databaseServerInstance $databaseServerInstance ` # -databaseName $CustomerName ` # -databaseCredentials $databaseCredentials ` # -templateDatabase $templateDatabase ` # -tempFolder $tempFolder } catch { Write-Host -ForegroundColor Red "Error Creating database: exception: $($_.Exception.Message)" Throw } try { # Mount-BCSTenant -businessCentralServer $businessCentralServer ` # -serverInstance $businessCentralserverInstance ` # -tenant $CustomerName ` # -databaseserver $databaseServer } catch { Write-Host -ForegroundColor Red "Error Mounting tenant: exception: $($_.Exception.Message)" Throw } if ($CreatePasswordStateEntry) { try { $password = New-BCSPasswordStateEntry -PasswordStateListID $PasswordStateListID -CustomerName $CustomerName -PasswordStateURL $PasswordStateUrl -PasswordStateApiKey $PasswordStateApiKey } catch { Write-Host -ForegroundColor Red "Error Creating password: exception: $($_.Exception.Message)" Throw } try { $securePassword = Get-BCSSecureString $password $credential = New-Object System.Management.Automation.PSCredential -argumentList $businessCentralUserName, $securePassword Set-BCSUserPassword -businessCentralServer $businessCentralServer ` -businessCentralserverInstance $businessCentralserverInstance ` -CustomerName $CustomerName ` -BusinessCentralCredential $credential } catch { Write-Host -ForegroundColor Red "Error Updating BC user password: exception: $($_.Exception.Message)" Throw } } } end { } } Export-ModuleMember -Function New-BCSTenant |