Samples/InstallAndAddDataGateway-Sample.ps1
# This sample script helps automate the installation and configuration of a single member gateway cluster and optional additional admin using the available `DataGateway` PowerShell cmdlets. # # Note: Before beginning to install and register a gateway, you must be connected to the service with the `Connect-DataGatewayServiceAccount` cmdlet. # # Visit the help page for more information on each `DataGateway` PowerShell cmdlet. Param( # Documented on the Install-DataGateway help page [Parameter()] [Switch] $AcceptConditions, # Documented on the Install-DataGateway help page [Parameter()] [string] $InstallerLocation, # Documented on the Add-DataGatewayCluster help page [Parameter(Mandatory = $true)] [SecureString] $RecoveryKey, # Documented on the Add-DataGatewayCluster help page [Parameter(Mandatory = $true)] [string] $GatewayName, # Documented on the Add-DataGatewayClusterUser help page as $PrincipalObjectId # Note: If you are using a service principal to configure your gateway, # specifying this paramater will be the only way to administer the # gateway outside of the PowerShell module. [Parameter()] [Guid] $AdditionalGatewayAdminIdForNewGateway ) $ErrorActionPreference = "stop" # Thrown an error if not logged in Get-DataGatewayAccessToken | Out-Null # Run the gateway installer on the local computer $installDataGatewayArguments = @{ AcceptConditions = $AcceptConditions; InstallerLocation = $InstallerLocation; } Install-DataGateway @installDataGatewayArguments # Create a gateway cluster and save the cluster ID $addDataGatewayClusterArguments = @{ RecoveryKey = $RecoveryKey; GatewayName = $GatewayName; } $newGatewayClusterId = (Add-DataGatewayCluster @addDataGatewayClusterArguments).GatewayObjectId # Optionally add admin to new gateway if ($null -ne $AdditionalGatewayAdminIdForNewGateway) { $addDataGatewayClusterUserArguments = @{ GatewayClusterId = $newGatewayClusterId; PrincipalObjectId = $AdditionalGatewayAdminIdForNewGateway; Role = "Admin"; AllowedDataSourceTypes = $null; } Add-DataGatewayClusterUser @addDataGatewayClusterUserArguments } |