-
Notifications
You must be signed in to change notification settings - Fork 4
/
Get-CosmosDatabase.ps1
67 lines (54 loc) · 1.86 KB
/
Get-CosmosDatabase.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
function Get-CosmosDatabase {
<#
.SYNOPSIS
Get a CosmosDB Database
.DESCRIPTION
Gets a specific or all Databases in a specific CosmosDB
.PARAMETER DatabaseName
Name of the Database, if a specific Database is requested
.PARAMETER All
This switch returns all the Databases in the CosmosDB
.PARAMETER CosmosDBVariables
This is the Script variable generated by Connect-CosmosDB - no need to supply this variable, unless you get really creative
.EXAMPLE
Get-CosmosDatabase -All
Returns all Databases in your CosmosDB
.EXAMPLE
Get-CosmosDatabase -DatabaseName MyPrivateCosmos
Returns the DAtabase MyPrivateCosmos from your CosmosDB
.NOTES
https://docs.microsoft.com/en-us/rest/api/documentdb/list-databases
https://docs.microsoft.com/en-us/rest/api/documentdb/get-a-database
#>
[CmdletBinding(DefaultParameterSetName='Named')]
param (
[Parameter(ParameterSetName='Named',
Mandatory=$true,
HelpMessage='Name of your database')]
[string]$DatabaseName,
[Parameter(ParameterSetName='All')]
[switch]$All,
[Parameter(Mandatory=$false,
HelpMessage="Use Connect-CosmosDB to create this Variable collection")]
[hashtable]$CosmosDBVariables=$Script:CosmosDBVariables
)
begin {
Test-CosmosDBVariable $CosmosDBVariables
}
process {
if ($DatabaseName){
$Database = $Script:CosmosDBConnection[($DatabaseName + '_db')]
if ($Database) {
$Database
} else {
Write-Warning "$DatabaseName not found"
continue
}
}
if ($All){
$CosmosDBConnection.Keys | Where-Object {$_ -match '_db$'} | ForEach-Object {$CosmosDBConnection[$_]}
}
}
end {
}
}