private/set/Set-Region.ps1
function Set-Region { [CmdletBinding(SupportsShouldProcess, PositionalBinding = $true)] param( [Parameter(Mandatory = $false)] [string] $Region ) $regionExpression = '^(af|il|ap|ca|eu|me|sa|us|cn|us-gov|us-iso|us-isob)-(central|north|(north(?:east|west))|south|south(?:east|west)|east|west)-\d{1}$' if ($Region -match $regionExpression) { if ($PSCmdlet.ShouldProcess($Region)) { Set-DefaultAWSRegion -Region $Region -Scope Script } } elseif ("$env:AWS_REGION" -match $regionExpression) { if ($PSCmdlet.ShouldProcess("$env:AWS_REGION")) { Set-DefaultAWSRegion -Region "$env:AWS_REGION" -Scope Script } } else { if ($PSCmdlet.ShouldProcess('default')) { Clear-DefaultAWSRegion -Scope Script } } } |