File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change 1
- Import-Module SQLServer
1
+ Import-Module SQLServer - Verbose
2
2
3
- $clientid = " "
4
- $tenantid = " "
5
- $secret = " "
3
+ $ClientID = " " # enter application id that corresponds to the Service Principal" # Do not confuse with its display name
4
+ $TenantID = " " # enter the tenant ID of the Service Principal
5
+ $ClientSecret = " " # enter the secret associated with the Service Principal
6
6
7
- $request = Invoke-RestMethod - Method POST `
8
- - Uri " https://login.microsoftonline.com/$tenantid /oauth2/token" `
9
- - Body @ { resource = " https://database.windows.net/" ; grant_type = " client_credentials" ; client_id = $clientid ; client_secret = $secret }`
7
+ $RequestToken = Invoke-RestMethod - Method POST `
8
+ - Uri " https://login.microsoftonline.com/$TenantID /oauth2/token" `
9
+ - Body @ { resource = " https://database.windows.net/" ; grant_type = " client_credentials" ; client_id = $ClientID ; client_secret = $ClientSecret }`
10
10
- ContentType " application/x-www-form-urlencoded"
11
- $access_token = $request .access_token
11
+ $AccessToken = $RequestToken .access_token
12
12
13
- Invoke-Sqlcmd - ServerInstance SERVERNAME.database.windows.net - Database DBNAME - AccessToken $access_token - query ' select * from dbo.NumberSerie where UsedBy IS NULL;'
13
+ # SQL server, database & table information
14
+ $SQLServer = " ServerName.database.windows.net"
15
+ $DBName = " DatbaseName"
16
+ $DBTableName1 = " dbo.TableName"
14
17
18
+ # Database query
19
+ $Query = " Select * from $DBTableName1 "
20
+ Invoke-Sqlcmd - ServerInstance $SQLServer - Database $DBName - AccessToken $AccessToken - Query $Query
You can’t perform that action at this time.
0 commit comments