-
Notifications
You must be signed in to change notification settings - Fork 225
Invoke SqlDscQuery
Executes a query on the specified database.
Invoke-SqlDscQuery [-ServerName <String>] [-InstanceName <String>] [-Credential <PSCredential>]
[-LoginType <String>] [-Encrypt] -DatabaseName <String> -Query <String> [-PassThru]
[-StatementTimeout <Int32>] [-RedactText <String[]>] [-Force] [-WhatIf]
[-Confirm] [<CommonParameters>]
Invoke-SqlDscQuery -ServerObject <Server> -DatabaseName <String> -Query <String> [-PassThru]
[-StatementTimeout <Int32>] [-RedactText <String[]>] [-Force] [-WhatIf]
[-Confirm] [<CommonParameters>]
Executes a query on the specified database.
$serverObject = Connect-SqlDscDatabaseEngine
Invoke-SqlDscQuery -ServerObject $serverObject -DatabaseName 'master' `
-Query 'SELECT name FROM sys.databases' -PassThru
Connects to the default instance and then runs a query to return all the database names in the instance.
$serverObject = Connect-SqlDscDatabaseEngine
$serverObject | Invoke-SqlDscQuery -DatabaseName 'master' `
-Query 'RESTORE DATABASE [NorthWinds] WITH RECOVERY'
Connects to the default instance and then runs the query to restore the database NorthWinds.
$serverObject = Connect-SqlDscDatabaseEngine
Invoke-SqlDscQuery -ServerObject $serverObject -DatabaseName 'master' `
-Query "select * from MyTable where password = 'PlaceholderPa\ssw0rd1' and password = 'placeholder secret passphrase'" `
-RedactText @('PlaceholderPa\sSw0rd1','Placeholder Secret PassPhrase') `
-PassThru -Verbose
Shows how to redact sensitive information in the query when the query string is output as verbose information when the parameter Verbose is used. For it to work the sensitiv information must be known and passed into the parameter RedactText. If any single character is wrong the sensitiv information will not be redacted. The redaction is case-insensitive.
Invoke-SqlDscQuery -ServerName Server1 -InstanceName MSSQLSERVER -DatabaseName 'master' `
-Query 'SELECT name FROM sys.databases' -PassThru
Connects to the default instance and then runs a query to return all the database names in the instance.
Specifies the credentials to use to impersonate a user when connecting. If this is not provided then the current user will be used to connect to the SQL Server Database Engine instance.
Type: PSCredential
Parameter Sets: ByServerName
Aliases: DatabaseCredential, SetupCredential
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies the name of the database to execute the T-SQL query in.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies if encryption should be used.
Type: SwitchParameter
Parameter Sets: ByServerName
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Specifies that the query should be executed without any confirmation.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Specifies the instance name on which to execute the T-SQL query.
Type: String
Parameter Sets: ByServerName
Aliases:
Required: False
Position: Named
Default value: MSSQLSERVER
Accept pipeline input: False
Accept wildcard characters: False
Specifies which type of credentials are specified.
The valid types are
Integrated, WindowsUser, and SqlLogin.
If WindowsUser or SqlLogin are
specified then the Credential needs to be specified as well.
Defaults
to Integrated
.
Type: String
Parameter Sets: ByServerName
Aliases:
Required: False
Position: Named
Default value: Integrated
Accept pipeline input: False
Accept wildcard characters: False
Specifies if the command should return any result the query might return.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: WithResults
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
The query string to execute.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
One or more text strings to redact from the query when verbose messages are written to the console. Strings will be escaped so they will not be interpreted as regular expressions (RegEx).
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies the server name where the instance exist.
Type: String
Parameter Sets: ByServerName
Aliases:
Required: False
Position: Named
Default value: (Get-ComputerName)
Accept pipeline input: False
Accept wildcard characters: False
Specifies current server connection object.
Type: Server
Parameter Sets: ByServerObject
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
Set the query StatementTimeout in seconds. Default 600 seconds (10 minutes).
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 600
Accept pipeline input: False
Accept wildcard characters: False
Prompts you for confirmation before running the cmdlet.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
- Add-SqlDscNode
- Add-SqlDscTraceFlag
- Complete-SqlDscFailoverCluster
- Complete-SqlDscImage
- Connect-SqlDscDatabaseEngine
- ConvertFrom-SqlDscDatabasePermission
- ConvertFrom-SqlDscServerPermission
- ConvertTo-SqlDscDatabasePermission
- ConvertTo-SqlDscServerPermission
- Disable-SqlDscAudit
- Disconnect-SqlDscDatabaseEngine
- Enable-SqlDscAudit
- Get-SqlDscAudit
- Get-SqlDscConfigurationOption
- Get-SqlDscDatabasePermission
- Get-SqlDscManagedComputer
- Get-SqlDscManagedComputerService
- Get-SqlDscPreferredModule
- Get-SqlDscServerPermission
- Get-SqlDscStartupParameter
- Get-SqlDscTraceFlag
- Import-SqlDscPreferredModule
- Initialize-SqlDscRebuildDatabase
- Install-SqlDscServer
- Invoke-SqlDscQuery
- New-SqlDscAudit
- Remove-SqlDscAudit
- Remove-SqlDscNode
- Remove-SqlDscTraceFlag
- Repair-SqlDscServer
- Save-SqlDscSqlServerMediaFile
- Set-SqlDscAudit
- Set-SqlDscDatabasePermission
- Set-SqlDscServerPermission
- Set-SqlDscStartupParameter
- Set-SqlDscTraceFlag
- Test-SqlDscIsDatabasePrincipal
- Test-SqlDscIsLogin
- Test-SqlDscIsSupportedFeature
- Uninstall-SqlDscServer
- SqlAG
- SqlAGDatabase
- SqlAgentAlert
- SqlAgentFailsafe
- SqlAgentOperator
- SqlAGListener
- SqlAGReplica
- SqlAlias
- SqlAlwaysOnService
- SqlAudit
- SqlConfiguration
- SqlDatabase
- SqlDatabaseDefaultLocation
- SqlDatabaseMail
- SqlDatabaseObjectPermission
- SqlDatabasePermission
- SqlDatabaseRole
- SqlDatabaseUser
- SqlEndpoint
- SqlEndpointPermission
- SqlLogin
- SqlMaxDop
- SqlMemory
- SqlPermission
- SqlProtocol
- SqlProtocolTcpIp
- SqlReplication
- SqlRole
- SqlRS
- SqlRSSetup
- SqlScript
- SqlScriptQuery
- SqlSecureConnection
- SqlServiceAccount
- SqlSetup
- SqlTraceFlag
- SqlWaitForAG
- SqlWindowsFirewall