bin/dbatools-index.json
[
{ "CommandName": "Add-DbaComputerCertificate", "Description": "Adds a computer certificate from a local or remote computer.", "Tags": "Certificate", "Synopsis": "Adds a computer certificate - useful for older systems.", "Name": "Add-DbaComputerCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eAdd-DbaComputerCertificate -ComputerName Server1 -Path C:\\temp\\cert.cer\r\n\r\nAdds the local C:\\temp\\cer.cer to the remote server Server1 in LocalMachine\\My (Personal).\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eAdd-DbaComputerCertificate -Path C:\\temp\\cert.cer\r\n\r\nAdds the local C:\\temp\\cer.cer to the local computer\u0027s LocalMachine\\My (Personal) certificate store.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Backup-DbaDatabase", "Description": "Performs a backup of a specified type of 1 or more databases on a SQL Server Instance. These backups may be Full, Differential or Transaction log backups.", "Tags": [ "DisasterRecovery", "Backup", "Restore" ], "Author": "Stuart Moore (@napalmgram), stuart-moore.com", "Synopsis": "Backup one or more SQL Sever databases from a SQL Server SqlInstance.", "Name": "Backup-DbaDatabase", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabase -SqlInstance Server1 -Database HR, Finance\r\n\r\nThis will perform a full database backup on the databases HR and Finance on SQL Server Instance Server1 to Server1\u0027s \r\ndefault backup directory.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabase -SqlInstance sql2016 -BackupDirectory C:\\temp -Database AdventureWorks2014 -Type Full\r\n\r\nBacks up AdventureWorks2014 to sql2016\u0027s C:\\temp folder.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabase -SqlInstance sql2016 -AzureBaseUrl https://dbatoolsaz.blob.core.windows.net/azbackups/ \r\n-AzureCredential dbatoolscred -Type Full -CreateFolder\r\n\r\nPerforms a full backup of all databases on the sql2016 instance to their own containers under the \r\nhttps://dbatoolsaz.blob.core.windows.net/azbackups/ container on Azure blog storage using the sql credential \r\n\"dbatoolscred\" registered on the sql2016 instance.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Backup-DbaDatabaseCertificate", "Description": "Exports database certificates from SQL Server using SMO and outputs the .cer and .pvk files.", "Tags": [ "Migration", "Certificate" ], "Author": "Jess Pomfret (@jpomfret)", "Synopsis": "Exports database certificates from SQL Server using SMO.", "Name": "Backup-DbaDatabaseCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseCertificate -SqlInstance Server1\r\n\r\nExports all the certificates on the specified SQL Server to the default data path for the instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$cred = Get-Credential sqladmin\r\n\r\nBackup-DbaDatabaseCertificate -SqlInstance Server1 -SqlCredential $cred\r\n\r\nConnects using sqladmin credential and exports all the certificates on the specified SQL Server to the default data \r\npath for the instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseCertificate -SqlInstance Server1 -Certificate Certificate1\r\n\r\nExports only the certificate named Certificate1 on the specified SQL Server to the default data path for the instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseCertificate -SqlInstance Server1 -Database AdventureWorks\r\n\r\nExports only the certificates for AdventureWorks on the specified SQL Server to the default data path for the instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseCertificate -SqlInstance Server1 -ExcludeDatabase AdventureWorks\r\n\r\nExports all certificates except those for AdventureWorks on the specified SQL Server to the default data path for the \r\ninstance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseCertificate -SqlInstance Server1 -Path \\\\Server1\\Certificates -EncryptionPassword \r\n(ConvertTo-SecureString -force -AsPlainText GoodPass1234!!)\r\n\r\nExports all the certificates and private keys on the specified SQL Server.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e$EncryptionPassword = ConvertTo-SecureString -AsPlainText \"GoodPass1234!!\" -force\r\n\r\n$DecryptionPassword = ConvertTo-SecureString -AsPlainText \"Password4567!!\" -force\r\nBackup-DbaDatabaseCertificate -SqlInstance Server1 -EncryptionPassword $EncryptionPassword -DecryptionPassword \r\n$DecryptionPassword\r\nExports all the certificates on the specified SQL Server using the supplied DecryptionPassword, since an \r\nEncryptionPassword is specified private keys are also exported.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseCertificate -SqlInstance Server1 -Path \\\\Server1\\Certificates\r\n\r\nExports all certificates on the specified SQL Server to the specified path.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseCertificate -SqlInstance Server1 -Suffix DbaTools\r\n\r\nExports all certificates on the specified SQL Server to the specified path, appends DbaTools to the end of the \r\nfilenames.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 10 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseCertificate -SqlInstance sql2016 | Backup-DbaDatabaseCertificate\r\n\r\nExports all certificates found on sql2016 to the default data directory.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Backup-DbaDatabaseMasterKey", "Description": "Backs up specified database master key.", "Tags": [ "Certificate", "Databases" ], "Synopsis": "Backs up specified database master key.", "Name": "Backup-DbaDatabaseMasterKey", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseMasterKey -SqlInstance server1\\sql2016\r\n\r\nPrompts for export password, then logs into server1\\sql2016 with Windows credentials then backs up all database keys to \r\nthe default backup directory.\r\n\t\r\nComputerName : SERVER1\r\nInstanceName : SQL2016\r\nSqlInstance : SERVER1\\SQL2016\r\nDatabase : master\r\nFilename : E:\\MSSQL13.SQL2016\\MSSQL\\Backup\\server1$sql2016-master-20170614162311.key\r\nStatus : Success\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eBackup-DbaDatabaseMasterKey -SqlInstance Server1 -Database db1 -Path \\\\nas\\sqlbackups\\keys\r\n\r\nLogs into sql2016 with Windows credentials then backs up db1\u0027s keys to the \\\\nas\\sqlbackups\\keys directory.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Clear-DbaSqlConnectionPool", "Description": "This command resets (or empties) the connection pool.\n\nIf there are connections in use at the time of the call, they are marked appropriately and will be discarded (instead of being returned to the pool) when Close() is called on them.\n\nRef: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.clearallpools(v=vs.110).aspx", "Tags": "Connection", "Synopsis": "Resets (or empties) the connection pool.", "Name": "Clear-DbaSqlConnectionPool", "Links": "https://dbatools.io/Clear-DbaSqlConnectionPool", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eClear-DbaSqlConnectionPool\r\n\r\nClears all local connection pools.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eClear-DbaSqlConnectionPool -ComputerName workstation27\r\n\r\nClears all connection pools on workstation27.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Clear-DbaWaitStatistics", "Description": "Reset the aggregated statistics - basically just executes DBCC SQLPERF (N\u0027sys.dm_os_wait_stats\u0027, CLEAR)", "Tags": "WaitStatistic", "Synopsis": "Clears wait statistics", "Name": "Clear-DbaWaitStatistics", "Links": "https://dbatools.io/Clear-DbaWaitStatistics", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eClear-DbaWaitStatistics -SqlInstance sql2008, sqlserver2012\r\n\r\nClear wait stats on servers sql2008 and sqlserver2012.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Connect-DbaSqlServer", "Description": "This command is robust because it initializes properties that do not cause enumeration by default. It also supports both Windows and SQL Server authentication methods, and detects which to use based upon the provided credentials. \n\nBy default, this command also sets the connection\u0027s ApplicationName property to \"dbatools PowerShell module - dbatools.io - custom connection\". If you\u0027re doing anything that requires profiling, you can look for this client name.\n\nAlternatively, you can pass in whichever client name you\u0027d like using the -ClientName parameter. There are a ton of other parameters for you to explore as well.\n \nSee https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx\nand https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx,\nand https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx\n\nTo execute SQL commands, you can use $server.ConnectionContext.ExecuteReader($sql) or $server.Databases[\u0027master\u0027].ExecuteNonQuery($sql)", "Synopsis": "Creates a robust SMO SQL Server object.", "Name": "Connect-DbaSqlServer", "Links": "https://dbatools.io/Connect-DbaSqlServer", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eConnect-DbaSqlServer -SqlInstance sql2014\r\n\r\nCreates an SMO Server object that connects using Windows Authentication\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$wincred = Get-Credential ad\\sqladmin\r\n\r\nConnect-DbaSqlServer -SqlInstance sql2014 -Credential $wincred\r\n\r\nCreates an SMO Server object that connects using alternative Windows credentials\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$sqlcred = Get-Credential sqladmin\r\n\r\n$server = Connect-DbaSqlServer -SqlInstance sql2014 -Credential $sqlcred\r\n\r\nLogin to sql2014 as SQL login sqladmin.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$server = Connect-DbaSqlServer -SqlInstance sql2014 -ClientName \"my connection\"\r\n\r\nCreates an SMO Server object that connects using Windows Authentication and uses the client name \"my connection\". So \r\nwhen you open up profiler or use extended events, you can search for \"my connection\".\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$server = Connect-DbaSqlServer -SqlInstance sql2014 -AppendConnectionString \"Packet \r\nSize=4096;AttachDbFilename=C:\\MyFolder\\MyDataFile.mdf;User Instance=true;\"\r\n\r\nCreates an SMO Server object that connects to sql2014 using Windows Authentication, then it sets the packet size (this \r\ncan also be done via -PacketSize) and other connection attributes.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$server = Connect-DbaSqlServer -SqlInstance sql2014 -NetworkProtocol TcpIp -MultiSubnetFailover\r\n\r\nCreates an SMO Server object that connects using Windows Authentication that uses TCP/IP and has MultiSubnetFailover \r\nenabled.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e$server = Connect-DbaSqlServer sql2016 -ApplicationIntent ReadOnly\r\n\r\nConnects with ReadOnly ApplicationIntent.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaAgentAlert", "Description": "By default, all alerts are copied. The -Alert parameter is auto-populated for command-line completion and can be used to copy only specific alerts.\n\nIf the alert already exists on the destination, it will be skipped unless -Force is used.", "Tags": [ "Migration", "Agent" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaAgentAlert migrates alerts from one SQL Server to another.", "Name": "Copy-DbaAgentAlert", "Links": "https://dbatools.io/Copy-DbaAgentAlert", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentAlert -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all alerts from sqlserver2014a to sqlcluster using Windows credentials. If alerts with the same name exist on \r\nsqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentAlert -Source sqlserver2014a -Destination sqlcluster -Alert PSAlert -SourceSqlCredential $cred \r\n-Force\r\n\r\nCopies a only the alert named PSAlert from sqlserver2014a to sqlcluster using SQL credentials for sqlserver2014a and \r\nWindows credentials for sqlcluster. If a alert with the same name exists on sqlcluster, it will be dropped and \r\nrecreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentAlert -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaAgentCategory", "Description": "By default, all SQL Agent categories for Jobs, Operators and Alerts are copied.\n\nThe -OperatorCategories parameter is auto-populated for command-line completion and can be used to copy only specific operator categories.\nThe -AgentCategories parameter is auto-populated for command-line completion and can be used to copy only specific agent categories.\nThe -JobCategories parameter is auto-populated for command-line completion and can be used to copy only specific job categories.\n\nIf the category already exists on the destination, it will be skipped unless -Force is used.", "Tags": [ "Migration", "Agent" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaAgentCategory migrates SQL Agent categories from one SQL Server to another. This is similar to sp_add_category.\n\nhttps://msdn.microsoft.com/en-us/library/ms181597.aspx", "Name": "Copy-DbaAgentCategory", "Links": "https://dbatools.io/Copy-DbaAgentCategory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentCategory -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all operator categories from sqlserver2014a to sqlcluster using Windows authentication. If operator categories \r\nwith the same name exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentCategory -Source sqlserver2014a -Destination sqlcluster -OperatorCategory PSOperator \r\n-SourceSqlCredential $cred -Force\r\n\r\nCopies a single operator category, the PSOperator operator category from sqlserver2014a to sqlcluster using SQL \r\ncredentials to authenticate to sqlserver2014a and Windows credentials for sqlcluster. If a operator category with the \r\nsame name exists on sqlcluster, it will be dropped and recreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentCategory -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaAgentJob", "Description": "By default, all jobs are copied. The -Job parameter is auto-populated for command-line completion and can be used to copy only specific jobs.\n\nIf the job already exists on the destination, it will be skipped unless -Force is used.", "Tags": [ "Migration", "Agent", "Job" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaAgentJob migrates jobs from one SQL Server to another.", "Name": "Copy-DbaAgentJob", "Links": "https://dbatools.io/Copy-DbaAgentJob", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentJob -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all jobs from sqlserver2014a to sqlcluster, using Windows credentials. If jobs with the same name exist on \r\nsqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentJob -Source sqlserver2014a -Destination sqlcluster -Job PSJob -SourceSqlCredential $cred -Force\r\n\r\nCopies a single job, the PSJob job from sqlserver2014a to sqlcluster, using SQL credentials for sqlserver2014a and \r\nWindows credentials for sqlcluster. If a job with the same name exists on sqlcluster, it will be dropped and recreated \r\nbecause -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentJob -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaAgentOperator", "Description": "By default, all operators are copied. The -Operators parameter is auto-populated for command-line completion and can be used to copy only specific operators.\n\nIf the associated credentials for the operator do not exist on the destination, it will be skipped. If the operator already exists on the destination, it will be skipped unless -Force is used.", "Tags": [ "Migration", "Agent", "Operator" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaAgentOperator migrates operators from one SQL Server to another.", "Name": "Copy-DbaAgentOperator", "Links": "https://dbatools.io/Copy-DbaAgentOperator", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentOperator -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all operators from sqlserver2014a to sqlcluster using Windows credentials. If operators with the same name exist \r\non sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentOperator -Source sqlserver2014a -Destination sqlcluster -Operator PSOperator -SourceSqlCredential \r\n$cred -Force\r\n\r\nCopies only the PSOperator operator from sqlserver2014a to sqlcluster using SQL credentials for sqlserver2014a and \r\nWindows credentials for sqlcluster. If an operator with the same name exists on sqlcluster, it will be dropped and \r\nrecreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentOperator -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaAgentProxyAccount", "Description": "By default, all proxy accounts are copied. The -ProxyAccounts parameter is auto-populated for command-line completion and can be used to copy only specific proxy accounts.\n\nIf the associated credential for the account does not exist on the destination, it will be skipped. If the proxy account already exists on the destination, it will be skipped unless -Force is used.", "Tags": [ "Migration", "Agent" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaAgentProxyAccount migrates proxy accounts from one SQL Server to another.", "Name": "Copy-DbaAgentProxyAccount", "Links": "https://dbatools.io/Copy-DbaAgentProxyAccount", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentProxyAccount -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all proxy accounts from sqlserver2014a to sqlcluster using Windows credentials. If proxy accounts with the same \r\nname exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentProxyAccount -Source sqlserver2014a -Destination sqlcluster -ProxyAccount PSProxy \r\n-SourceSqlCredential $cred -Force\r\n\r\nCopies only the PSProxy proxy account from sqlserver2014a to sqlcluster using SQL credentials for sqlserver2014a and \r\nWindows credentials for sqlcluster. If a proxy account with the same name exists on sqlcluster, it will be dropped and \r\nrecreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentProxyAccount -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaAgentSharedSchedule", "Description": "All shared job schedules are copied.\n\nIf the associated credential for the account does not exist on the destination, it will be skipped. If the shared job schedule already exists on the destination, it will be skipped unless -Force is used.", "Tags": [ "Migration", "Agent" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaAgentSharedSchedule migrates shared job schedules from one SQL Server to another.", "Name": "Copy-DbaAgentSharedSchedule", "Links": "https://dbatools.io/Copy-DbaAgentSharedSchedule", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentSharedSchedule -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all shared job schedules from sqlserver2014a to sqlcluster using Windows credentials. If shared job schedules \r\nwith the same name exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaAgentSharedSchedule -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaBackupDevice", "Description": "Backups are migrated using Admin shares. If the destination directory does not exist, SQL Server\u0027s default backup directory will be used.\n\nIf a backup device with same name exists on destination, it will not be dropped and recreated unless -Force is used.", "Tags": [ "Migration", "DisasterRecovery", "Backup" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copies backup devices one by one. Copies both SQL code and the backup file itself.", "Name": "Copy-DbaBackupDevice", "Links": "https://dbatools.io/Copy-DbaBackupDevice", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaBackupDevice -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all server backup devices from sqlserver2014a to sqlcluster using Windows credentials. If backup devices with \r\nthe same name exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaBackupDevice -Source sqlserver2014a -Destination sqlcluster -BackupDevice backup01 -SourceSqlCredential \r\n$cred -Force\r\n\r\nCopies only the backup device named backup01 from sqlserver2014a to sqlcluster using SQL credentials for sqlserver2014a\t\r\nand Windows credentials for sqlcluster. If a backup device with the same name exists on sqlcluster, it will be dropped \r\nand recreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaBackupDevice -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaCentralManagementServer", "Description": "Copy-DbaCentralManagementServer copies all groups, subgroups, and server instances from one SQL Server to another.", "Tags": "Migration", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Migrates SQL Server Central Management groups and server instances from one SQL Server to another.", "Name": "Copy-DbaCentralManagementServer", "Links": "https://dbatools.io/Copy-DbaCentralManagementServer", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCentralManagementServer -Source sqlserver2014a -Destination sqlcluster\r\n\r\nAll groups, subgroups, and server instances are copied from sqlserver\u0027s Central Management Server to sqlcluster\u0027s \r\nCentral Management Server.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCentralManagementServer -Source sqlserver2014a -Destination sqlcluster -ServerGroup Group1,Group3\r\n\r\nTop-level groups Group1 and Group3 along with their subgroups and server instances are copied from sqlserver to \r\nsqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCentralManagementServer -Source sqlserver2014a -Destination sqlcluster -ServerGroup Group1,Group3 \r\n-SwitchServerName -SourceSqlCredential $SourceSqlCredential -DestinationSqlCredential $DestinationSqlCredential\r\n\r\nTop-level groups Group1 and Group3 along with their subgroups and server instances are copied from sqlserver to \r\nsqlcluster. When adding sql instances to sqlcluster, if the server name of the migrating instance is \"sqlcluster\", it \r\nwill be switched to \"sqlserver\".\r\n\r\nIf SwitchServerName is not specified, \"sqlcluster\" will be skipped.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaCredential", "Description": "By using password decryption techniques provided by Antti Rantasaari (NetSPI, 2014), this script migrates SQL Server Credentials from one server to another while maintaining username and password.\n\nCredit: https://blog.netspi.com/decrypting-mssql-database-link-server-passwords/ \nLicense: BSD 3-Clause http://opensource.org/licenses/BSD-3-Clause", "Tags": [ "WSMan", "Migration" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaCredential migrates SQL Server Credentials from one SQL Server to another while maintaining Credential passwords.", "Name": "Copy-DbaCredential", "Links": "https://dbatools.io/Copy-DbaCredential", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCredential -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all SQL Server Credentials on sqlserver2014a to sqlcluster. If Credentials exist on destination, they will be \r\nskipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCredential -Source sqlserver2014a -Destination sqlcluster -CredentialIdentity \"PowerShell Proxy Account\" \r\n-Force\r\n\r\nCopies over one SQL Server Credential (PowerShell Proxy Account) from sqlserver to sqlcluster. If the Credential \r\nalready exists on the destination, it will be dropped and recreated.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaCustomError", "Description": "By default, all custom errors are copied. The -CustomError parameter is auto-populated for command-line completion and can be used to copy only specific custom errors.\n\nIf the custom error already exists on the destination, it will be skipped unless -Force is used. The us_english version must be created first. If you drop the us_english version, all the other languages will be dropped for that specific ID as well.", "Tags": [ "Migration", "CustomError" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaCustomError migrates custom errors (user defined messages), by the custom error ID, from one SQL Server to another.", "Name": "Copy-DbaCustomError", "Links": "https://dbatools.io/Copy-DbaCustomError", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCustomError -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all server custom errors from sqlserver2014a to sqlcluster using Windows credentials. If custom errors with the \r\nsame name exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCustomError -Source sqlserver2014a -SourceSqlCredential $scred -Destination sqlcluster \r\n-DestinationSqlCredential $dcred -CustomError 60000 -Force\r\n\r\nCopies only the custom error with ID number 60000 from sqlserver2014a to sqlcluster using SQL credentials for \r\nsqlserver2014a and Windows credentials for sqlcluster. If a custom error with the same name exists on sqlcluster, it \r\nwill be updated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCustomError -Source sqlserver2014a -Destination sqlcluster -ExcludeCustomError 60000 -Force\r\n\r\nCopies all the custom errors found on sqlserver2014a except the custom error with ID number 60000 to sqlcluster. If a \r\ncustom error with the same name exists on sqlcluster, it will be updated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaCustomError -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaDatabase", "Description": "This script provides the ability to migrate databases using detach/copy/attach or backup/restore. This script works with named instances, clusters and SQL Server Express Edition.\n\nBy default, databases will be migrated to the destination SQL Server\u0027s default data and log directories. You can override this by specifying -ReuseSourceFolderStructure. Filestreams and filegroups are also migrated. Safety is emphasized.", "Tags": [ "Migration", "DisasterRecovery", "Backup", "Restore" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Migrates SQL Server databases from one SQL Server to another.", "Name": "Copy-DbaDatabase", "Links": "https://dbatools.io/Copy-DbaDatabase", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabase -Source sqlserver2014a -Destination sqlserver2014b -Database TestDB -BackupRestore \r\n-NetworkShare \\\\fileshare\\sql\\migration\r\n\r\nMigrates a single user database TestDB using Backup and restore from instance sqlserver2014a to sqlserver2014b. Backup \r\nfiles are stored in \\\\fileshare\\sql\\migration.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabase -Source sqlserver2014a -Destination sqlcluster -DetachAttach -Reattach\r\n\r\nDatabases will be migrated from sqlserver2014a to sqlcluster using the detach/copy files/attach method.The following \r\nwill be performed: kick all users out of the database, detach all data/log files, move files across the network over an \r\nadmin share (\\\\SqlSERVER\\M$\\MSSql...), attach file on destination server, reattach at source. If the database files \r\n(*.mdf, *.ndf, *.ldf) on *destination* exist and aren\u0027t in use, they will be overwritten.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabase -Source sqlserver2014a -Destination sqlcluster -ExcludeDatabase Northwind, pubs \r\n-IncludeSupportDbs -Force -BackupRestore -NetworkShare \\\\fileshare\\sql\\migration\r\n\r\nMigrates all user databases except for Northwind and pubs by using backup/restore (copy-only). Backup files are stored \r\nin \\\\fileshare\\sql\\migration. If the database exists on the destination, it will be dropped prior to attach.\r\n\r\nIt also includes the support databases (ReportServer, ReportServerTempDb, distribution).\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaDatabaseAssembly", "Description": "By default, all assemblies are copied. \n\nIf the assembly already exists on the destination, it will be skipped unless -Force is used.\n\nThis script does not yet copy dependencies or dependent objects.", "Tags": [ "Migration", "Assembly" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaDatabaseAssembly migrates assemblies from one SQL Server to another.", "Name": "Copy-DbaDatabaseAssembly", "Links": "http://dbatools.io/Get-SqlDatabaseAssembly", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabaseAssembly -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all assemblies from sqlserver2014a to sqlcluster using Windows credentials. If assemblies with the same name \r\nexist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabaseAssembly -Source sqlserver2014a -Destination sqlcluster -Assembly dbname.assemblyname, \r\ndbname3.anotherassembly -SourceSqlCredential $cred -Force\r\n\r\nCopies two assemblies, the dbname.assemblyname and dbname3.anotherassembly from sqlserver2014a to sqlcluster using SQL \r\ncredentials for sqlserver2014a and Windows credentials for sqlcluster. If an assembly with the same name exists on \r\nsqlcluster, it will be dropped and recreated because -Force was used.\r\n\r\nIn this example, anotherassembly will be copied to the dbname3 database on the server sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaThing -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaDatabaseMail", "Description": "By default, all mail configurations for Profiles, Accounts, Mail Servers and Configs are copied.", "Tags": [ "Migration", "Mail" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Migrates Mail Profiles, Accounts, Mail Servers and Mail Server Configs from one SQL Server to another.", "Name": "Copy-DbaDatabaseMail", "Links": "https://dbatools.io/Copy-DbaDatabaseMail", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabaseMail -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all database mail objects from sqlserver2014a to sqlcluster using Windows credentials. If database mail objects \r\nwith the same name exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabaseMail -Source sqlserver2014a -Destination sqlcluster -SourceSqlCredential $cred\r\n\r\nCopies all database mail objects from sqlserver2014a to sqlcluster using SQL credentials for sqlserver2014a and Windows \r\ncredentials for sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabaseMail -Source sqlserver2014a -Destination sqlcluster -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaDatabaseMail -Source sqlserver2014a -Destination sqlcluster -Silent:$true\r\n\r\nPerforms execution of function, but disables output of all messages\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaEndpoint", "Description": "By default, all endpoints are copied.\n\nIf the endpoint already exists on the destination, it will be skipped unless -Force is used.", "Tags": [ "Migration", "Endpoint" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaEndpoint migrates server endpoints from one SQL Server to another.", "Name": "Copy-DbaEndpoint", "Links": "https://dbatools.io/Copy-DbaEndpoint", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaEndpoint -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all server endpoints from sqlserver2014a to sqlcluster, using Windows credentials. If endpoints with the same \r\nname exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaEndpoint -Source sqlserver2014a -SourceSqlCredential $cred -Destination sqlcluster -Endpoint tg_noDbDrop \r\n-Force\r\n\r\nCopies only the tg_noDbDrop endpoint from sqlserver2014a to sqlcluster using SQL credentials for sqlserver2014a and \r\nWindows credentials for sqlcluster. If an endpoint with the same name exists on sqlcluster, it will be dropped and \r\nrecreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaEndpoint -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaExtendedEvent", "Description": "Migrates SQL Extended Event Sessions except the two default sessions, AlwaysOn_health and system_health.\n\nBy default, all non-system Extended Events are migrated.", "Tags": [ "Migration", "ExtendedEvent", "XEvent" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Migrates SQL Extended Event Sessions except the two default sessions, AlwaysOn_health and system_health.", "Name": "Copy-DbaExtendedEvent", "Links": "https://dbatools.io/Copy-DbaExtendedEvent", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaExtendedEvent -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all Extended Event sessions from sqlserver2014a to sqlcluster using Windows credentials.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaExtendedEvent -Source sqlserver2014a -Destination sqlcluster -SourceSqlCredential $cred\r\n\r\nCopies all Extended Event sessions from sqlserver2014a to sqlcluster using SQL credentials for sqlserver2014a and \r\nWindows credentials for sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaExtendedEvent -Source sqlserver2014a -Destination sqlcluster -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaExtendedEvent -Source sqlserver2014a -Destination sqlcluster -XeSession CheckQueries, \r\nMonitorUserDefinedException\r\n\r\nCopies only the Extended Events named CheckQueries and MonitorUserDefinedException from sqlserver2014a to sqlcluster.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaLinkedServer", "Description": "By using password decryption techniques provided by Antti Rantasaari (NetSPI, 2014), this script migrates SQL Server Linked Servers from one server to another, while maintaining username and password.\n\nCredit: https://blog.netspi.com/decrypting-mssql-database-link-server-passwords/\nLicense: BSD 3-Clause http://opensource.org/licenses/BSD-3-Clause", "Tags": [ "WSMan", "Migration", "LinkedServer" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaLinkedServer migrates Linked Servers from one SQL Server to another. Linked Server logins and passwords are migrated as well.", "Name": "Copy-DbaLinkedServer", "Links": "https://dbatools.io/Copy-DbaLinkedServer", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaLinkedServer -Source sqlserver2014a -Destination sqlcluster\r\n\r\nDescription\r\nCopies all SQL Server Linked Servers on sqlserver2014a to sqlcluster. If Linked Server exists on destination, it will \r\nbe skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaLinkedServer -Source sqlserver2014a -Destination sqlcluster -LinkedServer SQL2K5,SQL2k -Force\r\n\r\nDescription\r\nCopies over two SQL Server Linked Servers (SQL2K and SQL2K2) from sqlserver to sqlcluster. If the credential already \r\nexists on the destination, it will be dropped.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaLogin", "Description": "SQL Server 2000: Migrates logins with SIDs, passwords, server roles and database roles.\n\nSQL Server 2005 \u0026 newer: Migrates logins with SIDs, passwords, defaultdb, server roles \u0026 securables, database permissions \u0026 securables, login attributes (enforce password policy, expiration, etc.)\n\nThe login hash algorithm changed in SQL Server 2012, and is not backwards compatible with previous SQL Server versions. This means that while SQL Server 2000 logins can be migrated to SQL Server 2012, logins created in SQL Server 2012 can only be migrated to SQL Server 2012 and above.", "Tags": [ "Migration", "Login" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Migrates logins from source to destination SQL Servers. Supports SQL Server versions 2000 and newer.", "Name": "Copy-DbaLogin", "Links": "https://dbatools.io/Copy-DbaLogin", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaLogin -Source sqlserver2014a -Destination sqlcluster -Force\r\n\r\nCopies all logins from Source Destination. If a SQL Login on Source exists on the Destination, the Login on Destination \r\nwill be dropped and recreated.\r\n\r\nIf active connections are found for a login, the copy of that Login will fail as it cannot be dropped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaLogin -Source sqlserver2014a -Destination sqlcluster -Force -KillActiveConnection\r\n\r\nCopies all logins from Source Destination. If a SQL Login on Source exists on the Destination, the Login on Destination \r\nwill be dropped and recreated.\r\n\r\nIf any active connections are found they will be killed.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaLogin -Source sqlserver2014a -Destination sqlcluster -Exclude realcajun -SourceSqlCredential $scred \r\n-DestinationSqlCredential $dcred\r\n\r\nCopies all Logins from Source to Destination except for realcajun using SQL Authentication to connect to both instances.\r\n\r\nIf a Login already exists on the destination, it will not be migrated.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaLogin -Source sqlserver2014a -Destination sqlcluster -Login realcajun, netnerds -force\r\n\r\nCopies ONLY Logins netnerds and realcajun. If Login realcajun or netnerds exists on Destination, the existing Login(s) \r\nwill be dropped and recreated.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaLogin -Source sqlserver2014a -Destination sqlcluster -SyncOnly\r\n\r\nSyncs only SQL Server login permissions, roles, etc. Does not add or drop logins or users.\r\n\r\nIf a matching Login does not exist on Destination, the Login will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaLogin -LoginRenameHashtable @{ \"OldUser\" =\"newlogin\" } -Source $Sql01 -Destination Localhost \r\n-SourceSqlCredential $sqlcred\r\n\r\nCopies OldUser and then renames it to newlogin.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaQueryStoreConfig", "Description": "Copies the configuration of a Query Store enabled database and sets the copied configuration on other databases.", "Tags": "QueryStore", "Author": "Enrico van de Laar ( @evdlaar )", "Synopsis": "Copies the configuration of a Query Store enabled database and sets the copied configuration on other databases.", "Name": "Copy-DbaQueryStoreConfig", "Links": "https://dbatools.io/Copy-QueryStoreConfig", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaQueryStoreConfig -Source ServerA\\SQL -SourceDatabase AdventureWorks -Destination ServerB\\SQL \r\n-AllDatabases\r\n\r\nCopy the Query Store configuration of the AdventureWorks database in the ServerA\\SQL instance and apply it on all user \r\ndatabases in the ServerB\\SQL Instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaQueryStoreConfig -Source ServerA\\SQL -SourceDatabase AdventureWorks -Destination ServerB\\SQL \r\n-DestinationDatabase WorldWideTraders\r\n\r\nCopy the Query Store configuration of the AdventureWorks database in the ServerA\\SQL instance and apply it to the \r\nWorldWideTraders database in the ServerB\\SQL Instance.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaResourceGovernor", "Description": "By default, all non-system resource pools are migrated. If the pool already exists on the destination, it will be skipped unless -Force is used.\n\nThe -ResourcePool parameter is auto-populated for command-line completion and can be used to copy only specific objects.", "Tags": [ "Migration", "ResourceGovernor" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Migrates Resource Pools", "Name": "Copy-DbaResourceGovernor", "Links": "https://dbatools.io/Copy-DbaResourceGovernor", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaResourceGovernor -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all extended event policies from sqlserver2014a to sqlcluster using Windows credentials to connect to the SQL \r\nServer instances..\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaResourceGovernor -Source sqlserver2014a -Destination sqlcluster -SourceSqlCredential $cred\r\n\r\nCopies all extended event policies from sqlserver2014a to sqlcluster using SQL credentials to connect to sqlserver2014a \r\nand Windows credentials to connect to sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaResourceGovernor -Source sqlserver2014a -Destination sqlcluster -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaServerAudit", "Description": "By default, all audits are copied. The -Audit parameter is auto-populated for command-line completion and can be used to copy only specific audits.\n\nIf the audit already exists on the destination, it will be skipped unless -Force is used.", "Tags": "Migration", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaServerAudit migrates server audits from one SQL Server to another.", "Name": "Copy-DbaServerAudit", "Links": "https://dbatools.io/Copy-DbaServerAudit", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerAudit -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all server audits from sqlserver2014a to sqlcluster, using Windows credentials. If audits with the same name \r\nexist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerAudit -Source sqlserver2014a -Destination sqlcluster -Audit tg_noDbDrop -SourceSqlCredential $cred \r\n-Force\r\n\r\nCopies a single audit, the tg_noDbDrop audit from sqlserver2014a to sqlcluster, using SQL credentials for \r\nsqlserver2014a and Windows credentials for sqlcluster. If an audit with the same name exists on sqlcluster, it will be \r\ndropped and recreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerAudit -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaServerAuditSpecification", "Description": "By default, all audits are copied. The -AuditSpecification parameter is auto-populated for command-line completion and can be used to copy only specific audits.\n\nIf the audit specification already exists on the destination, it will be skipped unless -Force is used.", "Tags": [ "Migration", "ServerAudit", "AuditSpecification" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaServerAuditSpecification migrates server audit specifications from one SQL Server to another.", "Name": "Copy-DbaServerAuditSpecification", "Links": "https://dbatools.io/Copy-DbaServerAuditSpecification", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerAuditSpecification -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all server audits from sqlserver2014a to sqlcluster using Windows credentials to connect. If audits with the \r\nsame name exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerAuditSpecification -Source sqlserver2014a -Destination sqlcluster -ServerAuditSpecification \r\ntg_noDbDrop -SourceSqlCredential $cred -Force\r\n\r\nCopies a single audit, the tg_noDbDrop audit from sqlserver2014a to sqlcluster using SQL credentials to connect to \r\nsqlserver2014a and Windows credentials to connect to sqlcluster. If an audit specification with the same name exists on \r\nsqlcluster, it will be dropped and recreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerAuditSpecification -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaServerTrigger", "Description": "By default, all triggers are copied. The -ServerTrigger parameter is auto-populated for command-line completion and can be used to copy only specific triggers.\n\nIf the trigger already exists on the destination, it will be skipped unless -Force is used.", "Tags": "Migration", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaServerTrigger migrates server triggers from one SQL Server to another.", "Name": "Copy-DbaServerTrigger", "Links": "https://dbatools.io/Copy-DbaServerTrigger", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerTrigger -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all server triggers from sqlserver2014a to sqlcluster, using Windows credentials. If triggers with the same name \r\nexist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerTrigger -Source sqlserver2014a -Destination sqlcluster -ServerTrigger tg_noDbDrop \r\n-SourceSqlCredential $cred -Force\r\n\r\nCopies a single trigger, the tg_noDbDrop trigger from sqlserver2014a to sqlcluster, using SQL credentials for \r\nsqlserver2014a and Windows credentials for sqlcluster. If a trigger with the same name exists on sqlcluster, it will be \r\ndropped and recreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaServerTrigger -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaSpConfigure", "Description": "By default, all configuration values are copied. The -ConfigName parameter is auto-populated for command-line completion and can be used to copy only specific configs.", "Tags": [ "Migration", "Configure", "SpConfigure" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy-DbaSpConfigure migrates configuration values from one SQL Server to another.", "Name": "Copy-DbaSpConfigure", "Links": "https://dbatools.io/Copy-DbaSpConfigure", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSpConfigure -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all sp_configure settings from sqlserver2014a to sqlcluster\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSpConfigure -Source sqlserver2014a -Destination sqlcluster -ConfigName DefaultBackupCompression, \r\nIsSqlClrEnabled -SourceSqlCredential $cred -Force\r\n\r\nCopies the values for IsSqlClrEnabled and DefaultBackupCompression from sqlserver2014a to sqlcluster using SQL \r\ncredentials to authenticate to sqlserver2014a and Windows credentials to authenticate to sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSpConfigure -Source sqlserver2014a -Destination sqlcluster -ExcludeConfigName DefaultBackupCompression, \r\nIsSqlClrEnabled\r\n\r\nCopies all configs except for IsSqlClrEnabled and DefaultBackupCompression, from sqlserver2014a to sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSpConfigure -Source sqlserver2014a -Destination sqlcluster -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaSqlDataCollector", "Description": "By default, all data collector objects are migrated. If the object already exists on the destination, it will be skipped unless -Force is used.\n\nThe -CollectionSet parameter is auto-populated for command-line completion and can be used to copy only specific objects.", "Tags": [ "Migration", "DataCollection" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Migrates user SQL Data Collector collection sets. SQL Data Collector configuration is on the agenda, but it\u0027s hard.", "Name": "Copy-DbaSqlDataCollector", "Links": "https://dbatools.io/Copy-DbaSqlDataCollector", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlDataCollector -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all Data Collector Objects and Configurations from sqlserver2014a to sqlcluster, using Windows credentials.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlDataCollector -Source sqlserver2014a -Destination sqlcluster -SourceSqlCredential $cred\r\n\r\nCopies all Data Collector Objects and Configurations from sqlserver2014a to sqlcluster, using SQL credentials for \r\nsqlserver2014a and Windows credentials for sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlDataCollector -Source sqlserver2014a -Destination sqlcluster -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlDataCollector -Source sqlserver2014a -Destination sqlcluster -CollectionSet \u0027Server Activity\u0027, \u0027Table \r\nUsage Analysis\u0027\r\n\r\nCopies two Collection Sets, Server Activity and Table Usage Analysis, from sqlserver2014a to sqlcluster.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaSqlPolicyManagement", "Description": "By default, all policies and conditions are copied. If an object already exist on the destination, it will be skipped unless -Force is used.\n\nThe -Policy and -Condition parameters are auto-populated for command-line completion and can be used to copy only specific objects.", "Tags": "Migration", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Migrates SQL Policy Based Management Objects, including both policies and conditions.", "Name": "Copy-DbaSqlPolicyManagement", "Links": "https://dbatools.io/Copy-DbaSqlPolicyManagement", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlPolicyManagement -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all policies and conditions from sqlserver2014a to sqlcluster, using Windows credentials.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlPolicyManagement -Source sqlserver2014a -Destination sqlcluster -SourceSqlCredential $cred\r\n\r\nCopies all policies and conditions from sqlserver2014a to sqlcluster, using SQL credentials for sqlserver2014a and \r\nWindows credentials for sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlPolicyManagement -Source sqlserver2014a -Destination sqlcluster -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlPolicyManagement -Source sqlserver2014a -Destination sqlcluster -Policy \u0027xp_cmdshell must be disabled\u0027\r\n\r\nCopies only one policy, \u0027xp_cmdshell must be disabled\u0027 from sqlserver2014a to sqlcluster. No conditions are migrated.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaSqlServerAgent", "Description": "A wrapper function that calls the associated Copy command for each of the object types seen in SSMS under SQL Server Agent. This also copies all of the the SQL Agent properties (job history max rows, DBMail profile name, etc.).\n\nYou must have sysadmin access and server version must be SQL Server version 2000 or greater.", "Tags": [ "Migration", "SqlServerAgent", "SqlAgent" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copy SQL Server Agent from one server to another.", "Name": "Copy-DbaSqlServerAgent", "Links": "https://dbatools.io/Copy-DbaSqlServerAgent", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlServerAgent -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all job server objects from sqlserver2014a to sqlcluster using Windows credentials for authentication. If job \r\nobjects with the same name exist on sqlcluster, they will be skipped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlServerAgent -Source sqlserver2014a -Destination sqlcluster -SourceSqlCredential $cred\r\n\r\nCopies all job objects from sqlserver2014a to sqlcluster using SQL credentials to authentication to sqlserver2014a and \r\nWindows credentials to authenticate to sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSqlServerAgent -Source sqlserver2014a -Destination sqlcluster -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaSsisCatalog", "Description": "By default, all folders, projects, and environments are copied. \nThe -Project parameter can be specified to copy only one project, if desired.\nThe parameters get more granular from the Folder level. i.e. specifying folder will only deploy projects/environments from within that folder.", "Tags": [ "Migration", "SSIS" ], "Author": "Phil Schwartz (philschwartz.me, @pschwartzzz)", "Synopsis": "Copy-DbaSsisCatalog migrates Folders, SSIS projects, and environments from one SQL Server to another.", "Name": "Copy-DbaSsisCatalog", "Links": "https://dbatools.io/Copy-DbaSsisCatalog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSsisCatalog -Source sqlserver2014a -Destination sqlcluster\r\n\r\nCopies all folders, environments and all ssis Projects from sqlserver2014a to sqlcluster, using Windows credentials. If \r\nfolders with the same name exist on the destination they will be skipped, but projects will be redeployed.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSsisCatalog -Source sqlserver2014a -Destination sqlcluster -Project Archive_Tables -SourceSqlCredential \r\n$cred -Force\r\n\r\nCopies a single Project, the Archive_Tables Project from sqlserver2014a to sqlcluster, using SQL credentials for \r\nsqlserver2014a\r\nand Windows credentials for sqlcluster. If a Project with the same name exists on sqlcluster, it will be deleted and \r\nrecreated because -Force was used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSsisCatalog -Source sqlserver2014a -Destination sqlcluster -WhatIf -Force\r\n\r\nShows what would happen if the command were executed using force.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$SecurePW = Read-Host \"Enter password\" -AsSecureString\r\n\r\nCopy-DbaSsisCatalog -Source sqlserver2014a -Destination sqlcluster -CreateCatalogPassword $SecurePW\r\n\r\nDeploy entire SSIS catalog to an instance without a destination catalog. Passing -CreateCatalogPassword will bypass \r\nany user prompts for creating the destination catalog.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Copy-DbaSysDbUserObject", "Description": "Imports all user objects found in source SQL Server\u0027s master, msdb and model databases to the destination. This is useful because many DBAs store backup/maintenance procs/tables/triggers/etc (among other things) in master or msdb.\n\nIt is also useful for migrating objects within the model database.", "Tags": [ "Migration", "SystemDatabase", "UserObject" ], "Synopsis": "Imports all user objects found in source SQL Server\u0027s master, msdb and model databases to the destination.", "Name": "Copy-DbaSysDbUserObject", "Links": "https://dbatools.io/Copy-DbaSysDbUserObject", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eCopy-DbaSysDbUserObject $sourceServer $destserver\r\n\r\nCopies user objects from source to destination\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Disable-DbaAgHadr", "Description": "In order to build an AG a cluster has to be built and then the Hadr enabled for the SQL Server\nservice. This function disables that feature for the SQL Server service.", "Tags": [ "DisasterRecovery", "AG", "AvailabilityGroup" ], "Author": "Shawn Melton (@wsmelton | http://blog.wsmelton.info)", "Synopsis": "Disables the Hadr service setting on the specified SQL Server.", "Name": "Disable-DbaAgHadr", "Links": "https://dbatools.io/Disable-DbaAgHadr", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eDisable-DbaAgHadr -SqlInstance sql2016 -Force\r\n\r\nSets Hadr service to enabled for the instance sql2016, and restart the service to apply the change.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eDisable-DbaAgHadr -SqlInstance sql2012\\dev1 -Force\r\n\r\nSets Hadr service to disabled for the instance dev1 on sq2012, and restart the service to apply the change.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Disable-DbaForceNetworkEncryption", "Description": "Disables Force Encryption for a SQL Server instance. Note that this requires access to the Windows Server, not the SQL instance itself.\n\nThis setting is found in Configuration Manager.", "Tags": "Certificate", "Synopsis": "Disables Force Encryption for a SQL Server instance", "Name": "Disable-DbaForceNetworkEncryption", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eDisable-DbaForceNetworkEncryption\r\n\r\nDisables Force Encryption on the default (MSSQLSERVER) instance on localhost - requires (and checks for) RunAs admin.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eDisable-DbaForceNetworkEncryption -SqlInstance sql01\\SQL2008R2SP2\r\n\r\nDisables Force Network Encryption for the SQL2008R2SP2 on sql01. Uses Windows Credentials to both login and modify the \r\nregistry.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eDisable-DbaForceNetworkEncryption -SqlInstance sql01\\SQL2008R2SP2 -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Dismount-DbaDatabase", "Description": "This command detaches one or more SQL Server databases. If necessary, -Force can be used to break mirrors and remove databases from availability groups prior to detaching.", "Tags": "Database", "Synopsis": "Detach a SQL Server Database.", "Name": "Dismount-DbaDatabase", "Links": "https://dbatools.io/Dismount-DbaDatabase", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eDetach-DbaDatabase -SqlInstance sql2016b -Database SharePoint_Config, WSS_Logging\r\n\r\nDetaches SharePoint_Config and WSS_Logging from sql2016b\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance sql2016b -Database \u0027PerformancePoint Service \r\nApplication_10032db0fa0041df8f913f558a5dc0d4\u0027 | Detach-DbaDatabase -Force\r\n\r\nDetaches \u0027PerformancePoint Service Application_10032db0fa0041df8f913f558a5dc0d4\u0027 from sql2016b. Since Force was \r\nspecified, if the database is part of mirror, the mirror will be broken prior to detaching.\r\n\r\nIf the database is part of an Availability Group, it will first be dropped prior to detachment.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance sql2016b -Database WSS_Logging | Detach-DbaDatabase -Force -WhatIf\r\n\r\nShows what would happen if the command were to execute (without actually executing the detach/break/remove commands).\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Enable-DbaAgHadr", "Description": "In order to build an AG a cluster has to be built and then the Hadr enabled for the SQL Server\nservice. This function enables that feature for the SQL Server service.", "Tags": [ "DisasterRecovery", "AG", "AvailabilityGroup" ], "Author": "Shawn Melton (@wsmelton | http://blog.wsmelton.info)", "Synopsis": "Enables the Hadr service setting on the specified SQL Server.", "Name": "Enable-DbaAgHadr", "Links": "https://dbatools.io/Enable-DbaAgHadr", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eEnable-DbaAgHadr -SqlInstance sql2016 -Force\r\n\r\nSets Hadr service to enabled for the instance sql2016, and restart the service to apply the change.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eEnable-DbaAgHadr -SqlInstance sql2012\\dev1 -Force\r\n\r\nSets Hadr service to disabled for the instance dev1 on sq2012, and restart the service to apply the change.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Enable-DbaForceNetworkEncryption", "Description": "Enables Force Encryption for a SQL Server instance. Note that this requires access to the Windows Server, not the SQL instance itself.\n\nThis setting is found in Configuration Manager.", "Tags": "Certificate", "Synopsis": "Enables Force Encryption for a SQL Server instance.", "Name": "Enable-DbaForceNetworkEncryption", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eEnable-DbaForceNetworkEncryption\r\n\r\nEnables Force Encryption on the default (MSSQLSERVER) instance on localhost. Requires (and checks for) RunAs admin.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eEnable-DbaForceNetworkEncryption -SqlInstance sql01\\SQL2008R2SP2\r\n\r\nEnables Force Network Encryption for the SQL2008R2SP2 on sql01. Uses Windows Credentials to both connect and modify the \r\nregistry.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eEnable-DbaForceNetworkEncryption -SqlInstance sql01\\SQL2008R2SP2 -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Expand-DbaTLogResponsibly", "Description": "As you may already know, having a transaction log file with too many Virtual Log Files (VLFs) can hurt your database performance in many ways.\n\nExample:\n Too many VLFs can cause transaction log backups to slow down and can also slow down database recovery and, in extreme cases, even impact insert/update/delete performance.\n\n References:\n http://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/\n http://blogs.msdn.com/b/saponsqlserver/archive/2012/02/22/too-many-virtual-log-files-vlfs-can-cause-slow-database-recovery.aspx\n http://www.brentozar.com/blitz/high-virtual-log-file-vlf-count/\n \n In order to get rid of this fragmentation we need to grow the file taking the following into consideration:\n - How many VLFs are created when we perform a grow operation or when an auto-grow is invoked?\n \n Note: In SQL Server 2014 this algorithm has changed (http://www.sqlskills.com/blogs/paul/important-change-vlf-creation-algorithm-sql-server-2014/)\n\nAttention:\n We are growing in MB instead of GB because of known issue prior to SQL 2012:\n More detail here: \n http://www.sqlskills.com/BLOGS/PAUL/post/Bug-log-file-growth-broken-for-multiples-of-4GB.aspx\n and \n http://connect.microsoft.com/SqlInstance/feedback/details/481594/log-growth-not-working-properly-with-specific-growth-sizes-vlfs-also-not-created-appropriately\n or \n https://connect.microsoft.com/SqlInstance/feedback/details/357502/transaction-log-file-size-will-not-grow-exactly-4gb-when-filegrowth-4gb\n\nUnderstanding related problems:\n http://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/\n http://blogs.msdn.com/b/saponsqlserver/archive/2012/02/22/too-many-virtual-log-files-vlfs-can-cause-slow-database-recovery.aspx\n http://www.brentozar.com/blitz/high-virtual-log-file-vlf-count/\n \nKnown bug before SQL Server 2012\n http://www.sqlskills.com/BLOGS/PAUL/post/Bug-log-file-growth-broken-for-multiples-of-4GB.aspx\n http://connect.microsoft.com/SqlInstance/feedback/details/481594/log-growth-not-working-properly-with-specific-growth-sizes-vlfs-also-not-created-appropriately\n https://connect.microsoft.com/SqlInstance/feedback/details/357502/transaction-log-file-size-will-not-grow-exactly-4gb-when-filegrowth-4gb\n\nHow it works?\n The transaction log will grow in chunks until it reaches the desired size. \n Example: If you have a log file with 8192MB and you say that the target size is 81920MB (80GB) it will grow in chunks of 8192MB until it reaches 81920MB. 8192 -\u003e 16384 -\u003e 24576 ... 73728 -\u003e 81920", "Tags": [ "Storage", "Backup" ], "Author": "Claudio Silva (@ClaudioESSilva)", "Synopsis": "This command will help you to automatically grow your transaction log file in a responsible way (preventing the generation of too many VLFs).", "Name": "Expand-DbaTLogResponsibly", "Links": "https://dbatools.io/Expand-DbaTLogResponsibly", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExpand-DbaTLogResponsibly -SqlInstance sqlcluster -Database db1 -TargetLogSizeMB 50000\r\n\r\nGrows the transaction log for database db1 on sqlcluster to 50000 MB and calculates the increment size.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExpand-DbaTLogResponsibly -SqlInstance sqlcluster -Database db1, db2 -TargetLogSizeMB 10000 -IncrementSizeMB 200\r\n\r\nGrows the transaction logs for databases db1 and db2 on sqlcluster to 1000MB and sets the growth increment to 200MB.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eExpand-DbaTLogResponsibly -SqlInstance sqlcluster -Database db1 -TargetLogSizeMB 10000 -LogFileId 9\r\n\r\nGrows the transaction log file with FileId 9 of the db1 database on sqlcluster instance to 10000MB.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eExpand-DbaTLogResponsibly -SqlInstance sqlcluster -Database (Get-Content D:\\DBs.txt) -TargetLogSizeMB 50000\r\n\r\nGrows the transaction log of the databases specified in the file \u0027D:\\DBs.txt\u0027 on sqlcluster instance to 50000MB.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eExpand-DbaTLogResponsibly -SqlInstance SqlInstance -Database db1,db2 -TargetLogSizeMB 100 -IncrementSizeMB 10 \r\n-ShrinkLogFile -ShrinkSizeMB 10 -BackupDirectory R:\\MSSQL\\Backup\r\n\r\nGrows the transaction logs for databases db1 and db2 on SQL server SQLInstance to 100MB, sets the incremental growth to \r\n10MB, shrinks the transaction log to 10MB and uses the directory R:\\MSSQL\\Backup for the required backups.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaAvailabilityGroup", "Description": "Exports SQL Server Availability Groups creation scripts to a T-SQL file. This is a function that is not available in SSMS.", "Tags": [ "DisasterRecovery", "AG", "AvailabilityGroup" ], "Author": "Chris Sommer (@cjsommer), cjsommmer.com", "Synopsis": "Exports SQL Server Availability Groups to a T-SQL file.", "Name": "Export-DbaAvailabilityGroup", "Links": "https://dbatools.io/Export-DbaAvailabilityGroup", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaAvailabilityGroup -SqlInstance sql2012\r\n\r\nExports all Availability Groups from SQL server \"sql2012\". Output scripts are written to the Documents\\SqlAgExports \r\ndirectory by default.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaAvailabilityGroup -SqlInstance sql2012 -FilePath C:\\temp\\availability_group_exports\r\n\r\nExports all Availability Groups from SQL server \"sql2012\". Output scripts are written to the \r\nC:\\temp\\availability_group_exports directory.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaAvailabilityGroup -SqlInstance sql2012 -FilePath \u0027C:\\dir with spaces\\availability_group_exports\u0027 \r\n-AvailabilityGroups AG1,AG2\r\n\r\nExports Availability Groups AG1 and AG2 from SQL server \"sql2012\". Output scripts are written to the C:\\dir with \r\nspaces\\availability_group_exports directory.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaAvailabilityGroup -SqlInstance sql2014 -FilePath C:\\temp\\availability_group_exports -NoClobber\r\n\r\nExports all Availability Groups from SQL server \"sql2014\". Output scripts are written to the \r\nC:\\temp\\availability_group_exports directory. If the export file already exists it will not be overwritten.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaDiagnosticQuery", "Description": "The default output format of Invoke-DbaDiagnosticQuery is a custom object. It can also output to CSV and Excel. \nHowever, CSV output can generate a lot of files and Excel output depends on the ImportExcel module by Doug Fike (https://github.com/dfinke/ImportExcel)\nExport-DbaDiagnosticQuery can be used to convert from the default export type to the other available export types.", "Tags": "Query", "Author": "Andre Kamman (@AndreKamman), http://clouddba.io", "Synopsis": "Export-DbaDiagnosticQuery can convert ouput generated by Invoke-DbaDiagnosticQuery to CSV or Excel", "Name": "Export-DbaDiagnosticQuery", "Links": "https://dbatools.io/Export-DbaDiagnosticQuery", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDiagnosticQuery -SqlInstance sql2016 | Export-DbaDiagnosticQuery -Path c:\\temp\r\n\r\nConverts output from Invoke-DbaDiagnosticQuery to multiple CSV files\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$output = Invoke-DbaDiagnosticQuery -SqlInstance sql2016\r\n\r\nExport-DbaDiagnosticQuery -InputObject $output -ConvertTo Excel\r\n\r\nConverts output from Invoke-DbaDiagnosticQuery to Excel worksheet(s) in the Documents folder\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaExecutionPlan", "Description": "Exports execution plans to disk. Can pipe from Export-DbaExecutionPlan \n\t\nThanks to \n\thttps://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/\n\tand\n\thttp://www.scarydba.com/2017/02/13/export-plans-cache-sqlplan-file/\nfor the idea and query.", "Tags": "Performance", "Synopsis": "Exports execution plans to disk.", "Name": "Export-DbaExecutionPlan", "Links": "https://dbatools.io/Export-DbaExecutionPlan", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaExecutionPlan -SqlInstance sqlserver2014a\r\n\r\nExports all execution plans for sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaExecutionPlan -SqlInstance sqlserver2014a -Database db1, db2 -SinceLastExecution \u00277/1/2016 10:47:00\u0027\r\n\r\nExports all execution plans for databases db1 and db2 on sqlserve2014a since July 1, 2016 at 10:47 AM.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaLogin", "Description": "Exports Windows and SQL Logins to a T-SQL file. Export includes login, SID, password, default database, default language, server permissions, server roles, db permissions, db roles.", "Tags": [ "Export", "Login" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Exports Windows and SQL Logins to a T-SQL file. Export includes login, SID, password, default database, default language, server permissions, server roles, db permissions, db roles.", "Name": "Export-DbaLogin", "Links": "https://dbatools.io/Export-DbaLogin", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaLogin -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-logins.sql\r\n\r\nExports SQL for the logins in server \"sql2005\" and writes them to the file \"C:\\temp\\sql2005-logins.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaLogin -SqlInstance sqlserver2014a -Exclude realcajun -SqlCredential $scred -FilePath \r\nC:\\temp\\logins.sql -Append\r\n\r\nAuthenticates to sqlserver2014a using SQL Authentication. Exports all logins except for realcajun to \r\nC:\\temp\\logins.sql, and appends to the file if it exists. If not, the file will be created.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaLogin -SqlInstance sqlserver2014a -Login realcajun, netnerds -FilePath C:\\temp\\logins.sql\r\n\r\nExports ONLY logins netnerds and realcajun FROM sqlserver2014a to the file C:\\temp\\logins.sql\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaLogin -SqlInstance sqlserver2014a -Login realcajun, netnerds -Database HR, Accounting\r\n\r\nExports ONLY logins netnerds and realcajun FROM sqlserver2014a with the permissions on databases HR and Accounting\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaScript", "Description": "Exports scripts from SQL Management Objects", "Tags": [ "Migration", "Backup", "Export" ], "Synopsis": "Exports scripts from SQL Management Objects (SMO)", "Name": "Export-DbaScript", "Links": "https://dbatools.io/Export-DbaScript", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance sql2016 | Export-DbaScript\r\n\r\nExports all jobs on the SQL Server sql2016 instance using a trusted connection - automatically determines filename as \r\n.\\sql2016-Job-Export-date.sql\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance sql2016 | Export-DbaScript -Path C:\\temp\\export.sql -Append\r\n\r\nExports all jobs on the SQL Server sql2016 instance using a trusted connection - Will append the output to the file \r\nC:\\temp\\export.sql if it already exists\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance sql2016 -Job syspolicy_purge_history, \u0027Hourly Log Backups\u0027 -SqlCredential \r\n(Get-Credential sqladmin) | Export-DbaScript -Path C:\\temp\\export.sql\r\n\r\nExports only syspolicy_purge_history and \u0027Hourly Log Backups\u0027 to C:temp\\export.sql and uses the SQL login \"sqladmin\" to \r\nlogin to sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance sql2014 | Export-DbaJob -Passthru | ForEach-Object { \r\n$_.Replace(\u0027sql2014\u0027,\u0027sql2016\u0027) } | Set-Content -Path C:\\temp\\export.sql\r\n\r\nExports jobs and replaces all instances of the servername \"sql2014\" with \"sql2016\" then writes to C:\\temp\\export.sql\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$options = New-DbaScriptingOption\r\n\r\n$options.ScriptDrops = $false\r\n$options.WithDependencies = $true\r\nGet-DbaAgentJob -SqlInstance sql2016 | Export-DbaScript -ScriptingOptionsObject $options\r\n\r\nExports Agent Jobs with the Scripting Options ScriptDrops set to $false and WithDependencies set to $true.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaSpConfigure", "Description": "Exports advanced sp_configure global configuration options to sql file.", "Synopsis": "Exports advanced sp_configure global configuration options to sql file.", "Name": "Export-DbaSpConfigure", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaSpConfigure sourceserver -Path C:\\temp\\sp_configure.sql\r\n\r\nExports the SPConfigure settings on sourceserver to the file C:\\temp\\sp_configure.sql\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaUser", "Description": "Exports users creation and its permissions to a T-SQL file or host. Export includes user, create and add to role(s), database level permissions, object level permissions.", "Tags": [ "User", "Export" ], "Author": "Claudio Silva (@ClaudioESSilva)", "Synopsis": "Exports users creation and its permissions to a T-SQL file or host.", "Name": "Export-DbaUser", "Links": "https://dbatools.io/Export-DbaUser", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-users.sql\r\n\r\nExports SQL for the users in server \"sql2005\" and writes them to the file \"C:\\temp\\sql2005-users.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2014a $scred -FilePath C:\\temp\\users.sql -Append\r\n\r\nAuthenticates to sqlserver2014a using SQL Authentication. Exports all users to C:\\temp\\users.sql, and appends to the \r\nfile if it exists. If not, the file will be created.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2014a -User User1, User2 -FilePath C:\\temp\\users.sql\r\n\r\nExports ONLY users User1 and User2 fron sqlsever2014a to the file C:\\temp\\users.sql\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2008 -User User1 -FilePath C:\\temp\\users.sql -DestinationVersion \r\nSQLServer2016\r\n\r\nExports user User1 fron sqlsever2008 to the file C:\\temp\\users.sql with sintax to run on SQL Server 2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\\temp\\users.sql\r\n\r\nExpors ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\\temp\\users.sql file.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaAgentJob", "Description": "This command filters SQL Agent jobs giving the DBA a list of jobs that may need attention or could possibly be options for removal.", "Tags": [ "Agent", "Job" ], "Author": "Stephen Bennett (https://sqlnotesfromtheunderground.wordpress.com/)", "Synopsis": "Find-DbaAgentJob finds agent job/s that fit certain search filters.", "Name": "Find-DbaAgentJob", "Links": "https://dbatools.io/Find-DbaAgentJob", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -JobName backup*\r\n\r\nReturns all agent job(s) that have backup in the name\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01, Dev02 -JobName Mybackup\r\n\r\nReturns all agent job(s) that are named exactly Mybackup\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -LastUsed 10\r\n\r\nReturns all agent job(s) that have not ran in 10 days\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -IsDisabled -IsNoEmailNotification -IsNotScheduled\r\n\r\nReturns all agent job(s) that are either disabled, have no email notification or don\u0027t have a schedule. returned with \r\ndetail\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -LastUsed 10 -Exclude \"Yearly - RollUp Workload\", \"SMS - Notification\"\r\n\r\nReturns all agent jobs that havent ran in the last 10 ignoring jobs \"Yearly - RollUp Workload\" and \"SMS - Notification\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -Category \"REPL-Distribution\", \"REPL-Snapshot\" -Detailed | Format-Table \r\n-AutoSize -Wrap\r\n\r\nReturns all job/s on Dev01 that are in either category \"REPL-Distribution\" or \"REPL-Snapshot\" with detailed output\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01, Dev02 -IsFailed -Since \u00277/1/2016 10:47:00\u0027\r\n\r\nReturns all agent job(s) that have failed since July of 2016 (and still have history in msdb)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance CMSServer -Group Production | Find-DbaAgentJob -Disabled -IsNotScheduled | \r\nFormat-Table -AutoSize -Wrap\r\n\r\nQueries CMS server to return all SQL instances in the Production folder and then list out all agent jobs that have \r\neither been disabled or have no schedule.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaCommand", "Description": "Finds dbatools commands searching through the inline help text, building a consolidated json index and querying it because Get-Help is too slow", "Tags": [ "Find", "Help", "Command" ], "Author": "Simone Bizzotto", "Synopsis": "Finds dbatools commands searching through the inline help text", "Name": "Find-DbaCommand", "Links": "https://dbatools.io/Find-DbaCommand", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaCommand \"snapshot\"\r\n\r\nFor lazy typers: finds all commands searching the entire help for \"snapshot\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaCommand -Pattern \"snapshot\"\r\n\r\nFor rigorous typers: finds all commands searching the entire help for \"snapshot\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaCommand -Tag copy\r\n\r\nFinds all commands tagged with \"copy\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaCommand -Tag copy,user\r\n\r\nFinds all commands tagged with BOTH \"copy\" and \"user\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaCommand -Author chrissy\r\n\r\nFinds every command whose author contains our beloved \"chrissy\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaCommand -Author chrissy -Tag copy\r\n\r\nFinds every command whose author contains our beloved \"chrissy\" and it tagged as \"copy\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaCommand -Pattern snapshot -Rebuild\r\n\r\nFinds all commands searching the entire help for \"snapshot\", rebuilding the index (good for developers)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaDatabase", "Description": "Allows you to search SQL Server instances for database that have either the same name, owner or service broker guid.\n\nThere a several reasons for the service broker guid not matching on a restored database primarily using alter database new broker. or turn off broker to return a guid of 0000-0000-0000-0000.", "Tags": "DisasterRecovery", "Author": "Stephen Bennett: https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Find database/s on multiple servers that match critea you input", "Name": "Find-DbaDatabase", "Links": "https://dbatools.io/Find-DbaDatabase", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaDatabase -SqlInstance \"DEV01\", \"DEV02\", \"UAT01\", \"UAT02\", \"PROD01\", \"PROD02\" -Pattern Report\r\n\r\nReturns all database from the SqlInstances that have a database with Report in the name\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaDatabase -SqlInstance \"DEV01\", \"DEV02\", \"UAT01\", \"UAT02\", \"PROD01\", \"PROD02\" -Pattern TestDB -Exact \r\n-Detailed\r\n\r\nReturns all database from the SqlInstances that have a database named TestDB with a detailed output.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaDatabase -SqlInstance \"DEV01\", \"DEV02\", \"UAT01\", \"UAT02\", \"PROD01\", \"PROD02\" -Property ServiceBrokerGuid \r\n-Pattern \u0027-faeb-495a-9898-f25a782835f5\u0027 -Detailed\r\n\r\nReturns all database from the SqlInstances that have the same Service Broker GUID with a deatiled output\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaDatabaseGrowthEvent", "Description": "Finds any database AutoGrow events in the Default Trace.", "Tags": "AutoGrow", "Author": "Aaron Nelson", "Synopsis": "Finds any database AutoGrow events in the Default Trace.", "Name": "Find-DbaDatabaseGrowthEvent", "Links": "https://dbatools.io/Find-DbaDatabaseGrowthEvent", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DBADatabaseGrowthEvent -SqlInstance localhost\r\n\r\nReturns any database AutoGrow events in the Default Trace for every database on the localhost instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DBADatabaseGrowthEvent -SqlInstance ServerA\\SQL2016, ServerA\\SQL2014\r\n\r\nReturns any database AutoGrow events in the Default Traces for every database on ServerA\\sql2016 \u0026 ServerA\\SQL2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DBADatabaseGrowthEvent -SqlInstance ServerA\\SQL2016 | Format-Table -AutoSize -Wrap\r\n\r\nReturns any database AutoGrow events in the Default Trace for every database on the ServerA\\SQL2016 instance in a table \r\nformat.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaDuplicateIndex", "Description": "This command will help you to find duplicate and overlapping indexes on a database or a list of databases.\n\nOn SQL Server 2008 and higher, the IsFiltered property will also be checked\n\nAlso tells how much space you can save by dropping the index.\n\nWe show the type of compression so you can make a more considered decision.\n\nFor now only supports CLUSTERED and NONCLUSTERED indexes.\n\nYou can select the indexes you want to drop on the gridview and when clicking OK, the DROP statement will be generated.\n\nOutput:\n\tTableName\n\tIndexName\n\tKeyCols\n\tIncludedCols\n\tIndexSizeMB\n\tIndexType\n\tCompressionDesc (When 2008+)\n\tNumberRows\n\tIsDisabled\n\tIsFiltered (When 2008+)", "Author": "Claudio Silva (@ClaudioESSilva)", "Synopsis": "Find duplicate and overlapping indexes.", "Name": "Find-DbaDuplicateIndex", "Links": "https://dbatools.io/Find-DbaDuplicateIndex", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaDuplicateIndex -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-DuplicateIndexes.sql\r\n\r\nGenerates SQL statements to drop the selected duplicate indexes in server \"sql2005\" and writes them to the file \r\n\"C:\\temp\\sql2005-DuplicateIndexes.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaDuplicateIndex -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-DuplicateIndexes.sql -Append\r\n\r\nGenerates SQL statements to drop the selected duplicate indexes and writes/appends them to the file \r\n\"C:\\temp\\sql2005-DuplicateIndexes.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaDuplicateIndex -SqlInstance sqlserver2014a -SqlCredential $cred\r\n\r\nFinds exact duplicate indexes on all user databases present on sqlserver2014a, using SQL authentication.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaDuplicateIndex -SqlInstance sqlserver2014a -Database db1, db2\r\n\r\nFinds exact duplicate indexes on the db1 and db2 databases.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaDuplicateIndex -SqlInstance sqlserver2014a -IncludeOverlapping\r\n\r\nFinds both duplicate and overlapping indexes on all user databases.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaLoginInGroup", "Description": "Outputs all the active directory groups members for a server, or limits it to find a specific AD user in the groups", "Author": "Stephen Bennett, https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Finds Logins in Active Directory groups that have logins on the SQL Instance.", "Name": "Find-DbaLoginInGroup", "Links": "https://dbatools.io/Find-DbaLoginInGroup", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaLoginInGroup -SqlInstance DEV01 -Login \"MyDomain\\Stephen.Bennett\"\r\n\r\nReturns all active directory groups with logins on Sql Instance DEV01 that contain the AD user Stephen.Bennett.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaLoginInGroup -SqlInstance DEV01\r\n\r\nReturns all active directory users within all windows AD groups that have logins on the instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaLoginInGroup -SqlInstance DEV01 | Where-Object Login -like \u0027*stephen*\u0027\r\n\r\nReturns all active directory users within all windows AD groups that have logins on the instance whose login contains \r\n\u0027stephen\u0027\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaOrphanedFile", "Description": "This command searches all directories associated with SQL database files for database files that are not currently in use by the SQL Server instance.\n\nBy default, it looks for orphaned .mdf, .ldf and .ndf files in the root\\data directory, the default data path, the default log path, the system paths and any directory in use by any attached directory.\n\nYou can specify additional filetypes using the -FileType parameter, and additional paths to search using the -Path parameter.", "Tags": [ "DisasterRecovery", "Orphan" ], "Author": "Sander Stad (@sqlstad), sqlstad.nl", "Synopsis": "Find-DbaOrphanedFile finds orphaned database files. Orphaned database files are files not associated with any attached database.", "Name": "Find-DbaOrphanedFile", "Links": "https://dbatools.io/Find-DbaOrphanedFile", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaOrphanedFile -SqlInstance sqlserver2014a\r\n\r\nLogs into the SQL Server \"sqlserver2014a\" using Windows credentials and searches for orphaned files. Returns server \r\nname, local filename, and unc path to file.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaOrphanedFile -SqlInstance sqlserver2014a -SqlCredential $cred\r\n\r\nLogs into the SQL Server \"sqlserver2014a\" using alternative credentials and searches for orphaned files. Returns server \r\nname, local filename, and unc path to file.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaOrphanedFile -SqlInstance sql2014 -Path \u0027E:\\Dir1\u0027, \u0027E:\\Dir2\u0027\r\n\r\nFinds the orphaned files in \"E:\\Dir1\" and \"E:Dir2\" in addition to the default directories.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaOrphanedFile -SqlInstance sql2014 -LocalOnly\r\n\r\nReturns only the local filepath. Using LocalOnly with multiple servers is not recommended since it does not return the \r\nassociated server name.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaOrphanedFile -SqlInstance sql2014 -RemoteOnly\r\n\r\nReturns only the remote filepath. Using LocalOnly with multiple servers is not recommended since it does not return the \r\nassociated server name.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaOrphanedFile -SqlInstance sql2014, sql2016 -FileType fsf, mld\r\n\r\nFinds the orphaned ending with \".fsf\" and \".mld\" in addition to the default filetypes \".mdf\", \".ldf\", \".ndf\" for both \r\nthe servers sql2014 and sql2016.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaSimilarTable", "Description": "This function can either run against specific databases or all databases searching all/specific tables and views including in system databases.\n Typically one would use this to find for example archive version(s) of a table whose structures are similar.\n This can also be used to find tables/views that are very similar to a given table/view structure to see where a table/view might be used.\n\t\n More information can be found here: https://sqljana.wordpress.com/2017/03/31/sql-server-find-tables-with-similar-table-structure/", "Author": "Jana Sattainathan (@SQLJana - http://sqljana.wordpress.com)", "Synopsis": "Returns all tables/views that are similar in structure by comparing the column names of matching and matched tables/views", "Name": "Find-DbaSimilarTable", "Links": "https://dbatools.io/Find-DbaSimilarTable", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaSimilarTable -SqlInstance DEV01\r\n\r\nSearches all user database tables and views for each, returns all tables or views with their matching tables/views and \r\nmatch percent\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaSimilarTable -SqlInstance DEV01 -Database AdventureWorks\r\n\r\nSearches AdventureWorks database and lists tables/views and their corresponding matching tables/views with match percent\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaSimilarTable -SqlInstance DEV01 -Database AdventureWorks -SchemaName HumanResource\r\n\r\nSearches AdventureWorks database and lists tables/views in the HumanResource schema with their corresponding matching \r\ntables/views with match percent\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaSimilarTable -SqlInstance DEV01 -Database AdventureWorks -SchemaName HumanResource -Table Employee\r\n\r\nSearches AdventureWorks database and lists tables/views in the HumanResource schema and table Employee with its \r\ncorresponding matching tables/views with match percent\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaSimilarTable -SqlInstance DEV01 -Database AdventureWorks -MatchPercentThreshold 60\r\n\r\nSearches AdventureWorks database and lists all tables/views with its corresponding matching tables/views with match \r\npercent greater than or equal to 60\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaStoredProcedure", "Description": "This function can either run against specific databases or all databases searching all user or user and system stored procedures.", "Author": "Stephen Bennett, https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Returns all stored procedures that contain a specific case-insensitive string or regex pattern.", "Name": "Find-DbaStoredProcedure", "Links": "https://dbatools.io/Find-DbaStoredProcedure", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaStoredProcedure -SqlInstance DEV01 -Pattern whatever\r\n\r\nSearches all user databases stored procedures for \"whatever\" in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaStoredProcedure -SqlInstance sql2016 -Pattern \u0027\\w+@\\w+\\.\\w+\u0027\r\n\r\nSearches all databases for all stored procedures that contain a valid email pattern in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaStoredProcedure -SqlInstance DEV01 -Database MyDB -Pattern \u0027some string\u0027 -Verbose\r\n\r\nSearches in \"mydb\" database stored procedures for \"some string\" in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaStoredProcedure -SqlInstance sql2016 -Database MyDB -Pattern RUNTIME -IncludeSystemObjects\r\n\r\nSearches in \"mydb\" database stored procedures for \"runtime\" in the textbody\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaTrigger", "Description": "This function search on Instance, Database and Object level.\nIf you specify one or more databases, search on Server level will not be preformed.", "Author": "Cláudio Silva, @ClaudioESSilva", "Synopsis": "Returns all triggers that contain a specific case-insensitive string or regex pattern.", "Name": "Find-DbaTrigger", "Links": "https://dbatools.io/Find-DbaTrigger", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaTrigger -SqlInstance DEV01 -Pattern whatever\r\n\r\nSearches all user databases triggers for \"whatever\" in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaTrigger -SqlInstance sql2016 -Pattern \u0027\\w+@\\w+\\.\\w+\u0027\r\n\r\nSearches all databases for all triggers that contain a valid email pattern in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaTrigger -SqlInstance DEV01 -Database MyDB -Pattern \u0027some string\u0027 -Verbose\r\n\r\nSearches in \"mydb\" database triggers for \"some string\" in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaTrigger -SqlInstance sql2016 -Database MyDB -Pattern RUNTIME -IncludeSystemObjects\r\n\r\nSearches in \"mydb\" database triggers for \"runtime\" in the textbody\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaUnusedIndex", "Description": "This command will help you to find Unused indexes on a database or a list of databases\n\nAlso tells how much space you can save by dropping the index.\nWe show the type of compression so you can make a more considered decision.\nFor now only supported for CLUSTERED and NONCLUSTERED indexes\n\nYou can select the indexes you want to drop on the gridview and by clicking OK the drop statement will be generated.", "Tags": "Indexes", "Author": "Aaron Nelson (@SQLvariant), SQLvariant.com", "Synopsis": "Find Unused indexes", "Name": "Find-DbaUnusedIndex", "Links": "https://dbatools.io/Find-DbaUnusedIndex", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-UnusedIndexes.sql\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sql2005\". The statements are written to the \r\nfile \"C:\\temp\\sql2005-UnusedIndexes.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-UnusedIndexes.sql -Append\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sql2005\". The statements are written to the \r\nfile \"C:\\temp\\sql2005-UnusedIndexes.sql\", appending if the file already exists.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016 -SqlCredential $cred\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sqlserver2016\", using SQL Authentication to \r\nconnect to the database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016 -Database db1, db2\r\n\r\nGenerates the SQL Statement to to drop selected indexes in databases db1 \u0026 db2 on server \"sqlserver2016\".\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016\r\n\r\nGenerates the SQL statements to drop selected indexes on all user databases.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaUserObject", "Description": "Looks at the below list of objects to see if they are either owned by a user or a specific user (using the parameter -Pattern)\n Database Owner\n Agent Job Owner\n Used in Credential\n USed in Proxy\n SQL Agent Steps using a Proxy\n Endpoints\n Server Roles\n Database Schemas\n Database Roles\n Database Assembles\n Database Synonyms", "Author": "Stephen Bennett, https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Searches SQL Server to find user-owned objects (ie. not dbo or sa) or for any object owned by a specific user specified by the Pattern parameter.", "Name": "Find-DbaUserObject", "Links": "https://dbatools.io/Find-DbaUserObject", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUserObject -SqlInstance DEV01 -Pattern ad\\stephen\r\n\r\nSearches user objects for owner ad\\stephen\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUserObject -SqlInstance DEV01 -Verbose\r\n\r\nShows all user owned (non-sa, non-dbo) objects and verbose output\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaView", "Description": "This function can either run against specific databases or all databases searching all user or user and system views.", "Author": "Cláudio Silva (@ClaudioESSilva)", "Synopsis": "Returns all views that contain a specific case-insensitive string or regex pattern.", "Name": "Find-DbaView", "Links": "https://dbatools.io/Find-DbaView", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaView -SqlInstance DEV01 -Pattern whatever\r\n\r\nSearches all user databases views for \"whatever\" in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaView -SqlInstance sql2016 -Pattern \u0027\\w+@\\w+\\.\\w+\u0027\r\n\r\nSearches all databases for all views that contain a valid email pattern in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaView -SqlInstance DEV01 -Database MyDB -Pattern \u0027some string\u0027 -Verbose\r\n\r\nSearches in \"mydb\" database views for \"some string\" in the textbody\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaView -SqlInstance sql2016 -Database MyDB -Pattern RUNTIME -IncludeSystemObjects\r\n\r\nSearches in \"mydb\" database views for \"runtime\" in the textbody\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgDatabase", "Description": "Default view provides most common set of properties for information on the database in an Availability Group(s).\n\nInformation returned on the database will be specific to that replica, whether it is primary or a secondary.\n\nThis command will return an SMO object, but it is the AvailabilityDatabases object\tand not the Server.Databases object.", "Tags": [ "DisasterRecovery", "AG", "AvailabilityGroup", "Replica" ], "Author": "Shawn Melton (@wsmelton)", "Synopsis": "Outputs the databases involved in the Availability Group(s) found on the server.", "Name": "Get-DbaAgDatabase", "Links": "https://dbatools.io/Get-DbaAgDatabase", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgDatabase -SqlInstance sqlserver2014a\r\n\r\nReturns basic information on all the databases in each Availability Group found on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgDatabase -SqlInstance sqlserver2014a -AvailabilityGroup AG-a\r\n\r\nReturns basic information on all the databases in the Availability Group AG-a on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgDatabase -SqlInstance sqlserver2014a -AvailabilityGroup AG-a -Database AG-Database\r\n\r\nReturns basic information on the database AG-Database found in the Availability Group AG-a on server sqlserver2014a\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentAlert", "Description": "This function returns SQL Agent alerts.", "Tags": [ "Agent", "SMO" ], "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Returns all SQL Agent alerts on a SQL Server Agent.", "Name": "Get-DbaAgentAlert", "Links": "https://dbatools.io/Get-DbaAgentAlert", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentAlert -SqlInstance ServerA,ServerB\\instanceB\r\n\r\nReturns all SQL Agent alerts on serverA and serverB\\instanceB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027serverA\u0027,\u0027serverB\\instanceB\u0027 | Get-DbaAgentAlert\r\n\r\nReturns all SQL Agent alerts on serverA and serverB\\instanceB\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentJob", "Description": "The Get-DbaAgentJob returns connected SMO object for SQL Agent Job information for each instance(s) of SQL Server.", "Tags": [ "Job", "Agent" ], "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Agent Job information for each instance(s) of SQL Server.", "Name": "Get-DbaAgentJob", "Links": "https://dbatools.io/Get-DbaAgentJob", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost\r\n\r\nReturns all SQL Agent Jobs on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost, sql2016\r\n\r\nReturns all SQl Agent Jobs for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -Job BackupData, BackupDiff\r\n\r\nReturns all SQL Agent Jobs named BackupData and BackupDiff from the local SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -ExcludeJob BackupDiff\r\n\r\nReturns all SQl Agent Jobs for the local SQL Server instances, except the BackupDiff Job.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -NoDisabledJobs\r\n\r\nReturns all SQl Agent Jobs for the local SQL Server instances, excluding the disabled jobs.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentJobHistory", "Description": "Get-DbaAgentJobHistory returns all information on the executions still available on each instance(s) of SQL Server submitted.\n The cleanup of SQL Agent history determines how many records are kept.\n\n https://msdn.microsoft.com/en-us/library/ms201680.aspx\n https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.agent.jobhistoryfilter(v=sql.120).aspx", "Tags": [ "Job", "Agent" ], "Author": "Klaas Vandenberghe ( @PowerDbaKlaas )", "Synopsis": "Gets execution history of SQL Agent Job on instance(s) of SQL Server.", "Name": "Get-DbaAgentJobHistory", "Links": "https://dbatools.io/Get-DbaAgentJobHistory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobHistory -SqlInstance localhost\r\n\r\nReturns all SQL Agent Job execution results on the local default SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobHistory -SqlInstance localhost, sql2016\r\n\r\nReturns all SQL Agent Job execution results for the local and sql2016 SQL Server instances.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\\Inst2K17\u0027 | Get-DbaAgentJobHistory\r\n\r\nReturns all SQL Agent Job execution results for sql1 and sql2\\Inst2K17.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 | select *\r\n\r\nReturns all properties for all SQl Agent Job execution results on sql2\\Inst2K17.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 -Job \u0027Output File Cleanup\u0027\r\n\r\nReturns all properties for all SQl Agent Job execution results of the \u0027Output File Cleanup\u0027 job on sql2\\Inst2K17.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 -Job \u0027Output File Cleanup\u0027 -WithOutputFile\r\n\r\nReturns all properties for all SQl Agent Job execution results of the \u0027Output File Cleanup\u0027 job on sql2\\Inst2K17,\r\nwith additional properties that show the output filename path\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 -NoJobSteps\r\n\r\nReturns the SQL Agent Job execution results for the whole jobs on sql2\\Inst2K17, leaving out job step execution results.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobHistory -SqlInstance sql2\\Inst2K17 -StartDate \u00272017-05-22\u0027 -EndDate \u00272017-05-23 12:30:00\u0027\r\n\r\nReturns the SQL Agent Job execution results between 2017/05/22 00:00:00 and 2017/05/23 12:30:00 on sql2\\Inst2K17.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance sql2016 | Where Name -match backup | Get-DbaAgentJobHistory\r\n\r\nGets all jobs with the name that match the regex pattern \"backup\" and then gets the job history from those. You can \r\nalso use -Like *backup* in this example.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentJobOutputFile", "Description": "This function returns for one or more SQL Instances the output file value for each step of one or many agent job with the Job Names \nprovided dynamically. It will not return anything if there is no Output File", "Tags": [ "Agent", "Job" ], "Author": "Rob Sewell (https://sqldbawithabeard.com)", "Synopsis": "Returns the Output File for each step of one or many agent job with the Job Names provided dynamically if \nrequired for one or more SQL Instances", "Name": "Get-DbaAgentJobOutputFile", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobOutputFile -SqlInstance SERVERNAME -Job \u0027The Agent Job\u0027\r\n\r\nThis will return the configured paths to the output files for each of the job step of the The Agent Job Job \r\non the SERVERNAME instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobOutputFile -SqlInstance SERVERNAME\r\n\r\nThis will return the configured paths to the output files for each of the job step of all the Agent Jobs\r\non the SERVERNAME instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobOutputFile -SqlInstance SERVERNAME,SERVERNAME2 -Job \u0027The Agent Job\u0027\r\n\r\nThis will return the configured paths to the output files for each of the job step of the The Agent Job Job \r\non the SERVERNAME instance and SERVERNAME2\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$Servers = \u0027SERVER\u0027,\u0027SERVER\\INSTANCE1\u0027\r\n\r\nGet-DbaAgentJobOutputFile -SqlInstance $Servers -Job \u0027The Agent Job\u0027 -OpenFile \r\n\r\nThis will return the configured paths to the output files for each of the job step of the The Agent Job Job \r\non the SERVER instance and the SERVER\\INSTANCE1 and open the files if they are available\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobOutputFile -SqlInstance SERVERNAME | Out-GridView\r\n\r\nThis will return the configured paths to the output files for each of the job step of all the Agent Jobs\r\non the SERVERNAME instance and Pipe them to Out-GridView\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e(Get-DbaAgentJobOutputFile -SqlInstance SERVERNAME | ogv -PassThru).FileName | Invoke-Item\r\n\r\nThis will return the configured paths to the output files for each of the job step of all the Agent Jobs\r\non the SERVERNAME instance and Pipe them to Out-GridView and enable you to choose the output\r\nfile and open it\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobOutputFile -SqlInstance SERVERNAME -Verbose\r\n\r\nThis will return the configured paths to the output files for each of the job step of all the Agent Jobs\r\non the SERVERNAME instance and also show the job steps without an output file\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentLog", "Description": "Gets the \"SQL Agent Error Log\" of an instance. Returns all 10 error logs by default.", "Tags": "Logging", "Synopsis": "Gets the \"SQL Agent Error Log\" of an instance", "Name": "Get-DbaAgentLog", "Links": "https://dbatools.io/Get-DbaAgentLog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentLog -SqlInstance sql01\\sharepoint\r\n\r\nReturns the entire error log for the SQL Agent on sql01\\sharepoint\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentLog -SqlInstance sql01\\sharepoint -LogNumber 3, 6\r\n\r\nReturns log numbers 3 and 6 for the SQL Agent on sql01\\sharepoint\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$servers = \"sql2014\",\"sql2016\", \"sqlcluster\\sharepoint\"\r\n\r\n$servers | Get-DbaAgentLog -LogNumber 0\r\n\r\nReturns the most recent SQL Agent error logs for \"sql2014\",\"sql2016\" and \"sqlcluster\\sharepoint\"\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentOperator", "Description": "This function returns SQL Agent operators.", "Tags": [ "Agent", "Operator" ], "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Returns all SQL Agent operators on a SQL Server Agent.", "Name": "Get-DbaAgentOperator", "Links": "https://dbatools.io/Get-DbaAgentOperator", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentOperator -SqlInstance ServerA,ServerB\\instanceB\r\n\r\nReturns any SQL Agent operators on serverA and serverB\\instanceB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027ServerA\u0027,\u0027ServerB\\instanceB\u0027 | Get-DbaAgentOperator\r\n\r\nReturns all SQL Agent operators on serverA and serverB\\instanceB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentOperator -SqlInstance ServerA -Operator Dba1,Dba2\r\n\r\nReturns only the SQL Agent Operators Dba1 and Dba2 on ServerA.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentOperator -SqlInstance ServerA,ServerB -ExcludeOperator Dba3\r\n\r\nReturns all the SQL Agent operators on ServerA and ServerB, except the Dba3 operator.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentSchedule", "Description": "This function returns SQL Agent Shared Schedules.", "Tags": [ "Agent", "Schedule" ], "Author": "Chris McKeown (@devopsfu), http://www.devopsfu.com", "Synopsis": "Returns all SQL Agent Shared Schedules on a SQL Server Agent.", "Name": "Get-DbaAgentSchedule", "Links": "https://dbatools.io/Get-DbaAgentSchedule", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentSchedule -SqlInstance localhost\r\n\r\nReturns all SQL Agent Shared Schedules on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentSchedule -SqlInstance localhost, sql2016\r\n\r\nReturns all SQL Agent Shared Schedules for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgHadr", "Description": "Gets the Hadr setting, from the service level, and returns true or false for the specified SQL Server instance.", "Tags": [ "DisasterRecovery", "AG", "AvailabilityGroup" ], "Author": "Shawn Melton (@wsmelton | http://blog.wsmelton.info)", "Synopsis": "Gets the Hadr service setting on the specified SQL Server instance.", "Name": "Get-DbaAgHadr", "Links": "https://dbatools.io/Get-DbaAgHadr", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgHadr -SqlInstance sql2016\r\n\r\nReturns a status of the Hadr setting for sql2016 SQL Server instance.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgReplica", "Description": "Default view provides most common set of properties for information on the Availability Group(s)\u0027 Replica.", "Tags": [ "DisasterRecovery", "AG", "AvailabilityGroup", "Replica" ], "Author": "Shawn Melton (@wsmelton) | Chrissy LeMaire (@ctrlb)", "Synopsis": "Outputs the Availability Group(s)\u0027 Replica object found on the server.", "Name": "Get-DbaAgReplica", "Links": "https://dbatools.io/Get-DbaAgReplica", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgReplica -SqlInstance sqlserver2014a\r\n\r\nReturns basic information on all the Availability Group(s) replica(s) found on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgReplica -SqlInstance sqlserver2014a -AvailabilityGroup AG-a\r\n\r\nShows basic information on the replica(s) found on Availability Group AG-a on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgReplica -SqlInstance sqlserver2014a | Select *\r\n\r\nReturns full object properties on all Availability Group(s) replica(s) on sqlserver2014a\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAvailabilityGroup", "Description": "Default view provides most common set of properties for information on the Availability Group(s).", "Tags": [ "DisasterRecovery", "AG", "AvailabilityGroup" ], "Author": "Shawn Melton (@wsmelton) | Chrissy LeMaire (@ctrlb)", "Synopsis": "Outputs the Availability Group(s) object found on the server.", "Name": "Get-DbaAvailabilityGroup", "Links": "https://dbatools.io/Get-DbaAvailabilityGroup", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAvailabilityGroup -SqlInstance sqlserver2014a\r\n\r\nReturns basic information on all the Availability Group(s) found on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAvailabilityGroup -SqlInstance sqlserver2014a -AvailabilityGroup AG-a\r\n\r\nShows basic information on the Availability Group AG-a on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAvailabilityGroup -SqlInstance sqlserver2014a | Select *\r\n\r\nReturns full object properties on all Availability Group(s) on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAvailabilityGroup -SqlInstance sqlserver2014a -AvailabilityGroup AG-a -IsPrimary\r\n\r\nReturns true/false if the server, sqlserver2014a, is the primary replica for AG-a Availability Group\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAvailableCollation", "Description": "The Get-DbaAvailableCollation function returns the list of collations available on each SQL Server.\nOnly the connect permission is required to get this information.", "Author": "Bryan Hamby (@galador)", "Synopsis": "Function to get available collations for a given SQL Server", "Name": "Get-DbaAvailableCollation", "Links": "https://dbatools.io/Get-DbaAvailableCollation", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAvailableCollation -SqlInstance sql2016\r\n\r\nGets all the collations from server sql2016 using NT authentication\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaBackupDevice", "Description": "The Get-DbaBackupDevice command gets SQL Backup Device information for each instance(s) of SQL Server.", "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Backup Device information for each instance(s) of SQL Server.", "Name": "Get-DbaBackupDevice", "Links": "https://dbatools.io/Get-DbaBackupDevice", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupDevice -SqlInstance localhost\r\n\r\nReturns all Backup Devices on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupDevice -SqlInstance localhost, sql2016\r\n\r\nReturns all Backup Devices for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaBackupHistory", "Description": "Returns backup history details for some or all databases on a SQL Server.\n\nYou can even get detailed information (including file path) for latest full, differential and log files.\n\nBackups taken with the CopyOnly option will NOT be returned, unless the IncludeCopyOnly switch is present\n\nReference: http://www.sqlhub.com/2011/07/find-your-backup-history-in-sql-server.html", "Tags": [ "Storage", "DisasterRecovery", "Backup" ], "Synopsis": "Returns backup history details for databases on a SQL Server", "Name": "Get-DbaBackupHistory", "Links": "https://dbatools.io/Get-DbaBackupHistory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a\r\n\r\nReturns server name, database, username, backup type, date for all backups databases on SqlInstance2014a. This may \r\nreturn a ton of rows; consider using filters that are included in other examples.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$cred = Get-Credential sqladmin\r\n\r\nGet-DbaBackupHistory -SqlInstance SqlInstance2014a -SqlCredential $cred\r\n\r\nDoes the same as above but logs in as SQL user \"sqladmin\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a -Database db1, db2 -Since \u00277/1/2016 10:47:00\u0027\r\n\r\nReturns backup information only for databases db1 and db2 on sqlserve2014a since July 1, 2016 at 10:47 AM.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014, pubs -Force | Format-Table\r\n\r\nReturns information only for AdventureWorks2014 and pubs, and makes the output pretty\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last -DeviceType Disk\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014, only \r\nfor backups to disk\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last -DeviceType 148,107\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014, only \r\nfor backups with device_type 148 and 107\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -LastFull\r\n\r\nReturns information about the most recent full backup for AdventureWorks2014 on sql2014\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Type Full\r\n\r\nReturns information about all Full backups for AdventureWorks2014 on sql2014\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 10 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2016 | Get-DbaBackupHistory\r\n\r\nReturns database backup information for every database on every server listed in the Central Management Server on \r\nsql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 11 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a, sql2016 -Force\r\n\r\nLots of detailed information for all databases on SqlInstance2014a and sql2016.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaClientProtocol", "Description": "Gets the SQL Server related client protocols on one or more computers.\n\nRequires Local Admin rights on destination computer(s).\nThe client protocols can be enabled and disabled when retrieved via WSMan.", "Tags": "Protocol", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Gets the SQL Server related client protocols on a computer.", "Name": "Get-DbaClientProtocol", "Links": "https://dbatools.io/Get-DbaClientProtocol", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaClientProtocol -ComputerName sqlserver2014a\r\n\r\nGets the SQL Server related client protocols on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027 | Get-DbaClientProtocol\r\n\r\nGets the SQL Server related client protocols on computers sql1, sql2 and sql3.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaClientProtocol -ComputerName sql1,sql2 | Out-Gridview\r\n\r\nGets the SQL Server related client protocols on computers sql1 and sql2, and shows them in a grid view.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e(Get-DbaClientProtocol -ComputerName sql2 | Where { $_.DisplayName = \u0027via\u0027 }).Disable()\r\n\r\nDisables the VIA ClientNetworkProtocol on computer sql2.\r\nIf succesfull, returncode 0 is shown.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaClusterActiveNode", "Description": "Returns a string of the current owner. If -Detailed is specified, a datatable of details will be returned.", "Synopsis": "Returns the active node of a SQL Cluster", "Name": "Get-DbaClusterActiveNode", "Links": "https://dbatools.io/Get-DbaClusterActiveNode", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaClusterActiveNode -SqlInstance sqlcluster\r\n\r\nReturns a simple string with the ComputerNamePhysicalNetBIOS property\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaClusterActiveNode -SqlInstance sqlcluster -Detailed\r\n\r\nReturns a datatable with details\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaCmConnection", "Description": "Retrieves windows management connections from the cache", "Tags": "ComputerManagement", "Author": "Fred Winmann (@FredWeinmann)", "Synopsis": "Retrieves windows management connections from the cache", "Name": "Get-DbaCmConnection", "Links": "https://dbatools.io/Get-DbaCmConnection", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmConnection\r\n\r\nList all cached connections.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmConnection sql2014\r\n\r\nList the cached connection - if any - to the server sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmConnection -UserName \"*charles*\"\r\n\r\nList all cached connection that use a username containing \"charles\" as default or override credentials.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaCmObject", "Description": "This function centralizes all requests for information retrieved from Get-WmiObject or Get-CimInstance.\nIt uses different protocols as available in this order:\n- Cim over WinRM\n- Cim over DCOM\n- Wmi\n- Wmi over PowerShell Remoting\nIt remembers channels that didn\u0027t work and will henceforth avoid them. It remembers invalid credentials and will avoid reusing them.\nMuch of its behavior can be configured using Test-DbaWmConnection.", "Tags": "ComputerManagement", "Author": "Fred Winmann (@FredWeinmann)", "Synopsis": "Retrieves Wmi/Cim-Style information from computers.", "Name": "Get-DbaCmObject", "Links": "https://dbatools.io/Get-DbaCmObject", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmObject win32_OperatingSystem\r\n\r\nRetrieves the common operating system informations from the local computer.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmObject -Computername \"sql2014\" -ClassName Win32_OperatingSystem -Credential $cred -DoNotUse CimRM\r\n\r\nRetrieves the common operating system informations from the server sql2014.\r\nIt will use the credewntials stored in $cred to connect, unless they are known to not work, in which case they will \r\ndefault to windows credentials (unless another default has been set).\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaComputerCertificate", "Description": "Gets computer certificates on localhost that are candidates for using with SQL Server\u0027s network encryption", "Tags": "Certificate", "Synopsis": "Simplifies finding computer certificates that are candidates for using with SQL Server\u0027s network encryption", "Name": "Get-DbaComputerCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaComputerCertificate\r\n\r\nGets computer certificates on localhost that are candidates for using with SQL Server\u0027s network encryption\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaComputerCertificate -ComputerName sql2016\r\n\r\nGets computer certificates on sql2016 that are candidates for using with SQL Server\u0027s network encryption\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaComputerCertificate -ComputerName sql2016 -Thumbprint 8123472E32AB412ED4288888B83811DB8F504DED, \r\n04BFF8B3679BB01A986E097868D8D494D70A46D6\r\n\r\nGets computer certificates on sql2016 that match thumbprints 8123472E32AB412ED4288888B83811DB8F504DED or \r\n04BFF8B3679BB01A986E097868D8D494D70A46D6\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaComputerSystem", "Description": "Gets computer system information from the server and returns as an object.", "Tags": "ServerInfo", "Author": "Shawn Melton (@wsmelton | http://blog.wsmelton.info)", "Synopsis": "Gets computer system information from the server.", "Name": "Get-DbaComputerSystem", "Links": "https://dbatools.io/Get-DbaComputerSystem", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaComputerSystem\r\n\r\nReturns information about the local computer\u0027s computer system\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaComputerSystem -ComputerName sql2016\r\n\r\nReturns information about the sql2016\u0027s computer system\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaComputerSystem -ComputerName sql2016 -IncludeAws\r\n\r\nReturns information about the sql2016\u0027s computer system and includes additional properties around the EC2 instance.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaConfig", "Description": "Retrieves configuration elements by name.\nCan be used to search the existing configuration list.", "Tags": "Config", "Author": "Friedrich Weinmann", "Synopsis": "Retrieves configuration elements by name.", "Name": "Get-DbaConfig", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaConfig \u0027Mail.To\u0027\r\n\r\nRetrieves the configuration element for the key \"Mail.To\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaConfig -Force\r\n\r\nRetrieve all configuration elements from all modules, even hidden ones.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaConfigValue", "Description": "Returns the configuration value stored under the specified name.\nIt requires the full name (\u003cModule\u003e.\u003cName\u003e) and is usually only called by functions.", "Tags": "Config", "Author": "Friedrich Weinmann", "Synopsis": "Returns the configuration value stored under the specified name.", "Name": "Get-DbaConfigValue", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaConfigValue -Name \u0027System.MailServer\u0027\r\n\r\nReturns the configured value that was assigned to the key \u0027System.MailServer\u0027\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaConfigValue -Name \u0027Default.CoffeeMilk\u0027 -Fallback 0\r\n\r\nReturns the configured value for \u0027Default.CoffeeMilk\u0027. If no such value is configured, it returns \u00270\u0027 instead.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaCredential", "Description": "The Get-DbaCredential command gets SQL Credential information for each instance(s) of SQL Server.", "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Credential information for each instance(s) of SQL Server.", "Name": "Get-DbaCredential", "Links": "https://dbatools.io/Get-DbaCredential", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCredential -SqlInstance localhost\r\n\r\nReturns all SQL Credentials on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCredential -SqlInstance localhost, sql2016\r\n\r\nReturns all SQL Credentials for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaCustomError", "Description": "The Get-DbaCustomError command gets SQL Custom Error Message information for each instance(s) of SQL Server.", "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Custom Error Message information for each instance(s) of SQL Server.", "Name": "Get-DbaCustomError", "Links": "https://dbatools.io/Get-DbaCustomError", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCustomError -SqlInstance localhost\r\n\r\nReturns all Custom Error Message(s) on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCustomError -SqlInstance localhost, sql2016\r\n\r\nReturns all Custom Error Message(s) for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabase", "Description": "The Get-DbaDatabase command gets SQL database information for each database that is present on the target instance(s) of\nSQL Server. If the name of the database is provided, the command will return only the specific database information.", "Tags": "Database", "Author": "Garry Bargsley (@gbargsley | http://blog.garrybargsley.com)", "Synopsis": "Gets SQL Database information for each database that is present on the target instance(s) of SQL Server.", "Name": "Get-DbaDatabase", "Links": "https://dbatools.io/Get-DbaDatabase", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance localhost\r\n\r\nReturns all databases on the local default SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance localhost -ExcludeAllUserDb\r\n\r\nReturns only the system databases on the local default SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance localhost -ExcludeAllSystemDb\r\n\r\nReturns only the user databases on the local default SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e\u0027localhost\u0027,\u0027sql2016\u0027 | Get-DbaDatabase\r\n\r\nReturns databases on multiple instances piped into the function.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance SQL1\\SQLExpress -RecoveryModel full,Simple\r\n\r\nReturns only the user databases in Full or Simple recovery model from SQL Server instance SQL1\\SQLExpress.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance SQL1\\SQLExpress -Status Normal\r\n\r\nReturns only the user databases with status \u0027normal\u0027 from SQL Server instance SQL1\\SQLExpress.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance SQL1\\SQLExpress -IncludeLastUsed\r\n\r\nReturns the databases from SQL Server instance SQL1\\SQLExpress and includes the last used information \r\nfrom the sys.dm_db_index_usage_stats DMV.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance SQL1\\SQLExpress,SQL2 -ExcludeDatabase model,master\r\n\r\nReturns all databases except master and model from SQL Server instances SQL1\\SQLExpress and SQL2.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance SQL1\\SQLExpress,SQL2 -Encrypted\r\n\r\nReturns only databases using TDE from SQL Server instances SQL1\\SQLExpress and SQL2.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 10 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance SQL1\\SQLExpress,SQL2 -Access ReadOnly\r\n\r\nReturns only read only databases from SQL Server instances SQL1\\SQLExpress and SQL2.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 11 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance SQL2,SQL3 -Database OneDB,OtherDB\r\n\r\nReturns databases \u0027OneDb\u0027 and \u0027OtherDB\u0027 from SQL Server instances SQL2 and SQL3 if databases by those names exist on \r\nthose instances.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseAssembly", "Description": "The Get-DbaDatabaseAssembly command gets SQL Database Assembly information for each instance(s) of SQL Server.", "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Database Assembly information for each instance(s) of SQL Server.", "Name": "Get-DbaDatabaseAssembly", "Links": "https://dbatools.io/Get-DbaDatabaseAssembly", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseAssembly -SqlInstance localhost\r\n\r\nReturns all Database Assembly on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseAssembly -SqlInstance localhost, sql2016\r\n\r\nReturns all Database Assembly for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseCertificate", "Description": "Gets database certificates", "Tags": "Certificate", "Synopsis": "Gets database certificates", "Name": "Get-DbaDatabaseCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseCertificate -SqlInstance sql2016\r\n\r\nGets all certificates\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseCertificate -SqlInstance Server1 -Database db1\r\n\r\nGets the certificate for the db1 database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseCertificate -SqlInstance Server1 -Database db1 -Certificate cert1\r\n\r\nGets the cert1 certificate within the db1 database\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseEncryption", "Description": "Shows if a database has Transparent Data Encryption (TDE), any certificates, asymmetric keys or symmetric keys with details for each.", "Author": "Stephen Bennett, https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Returns a summary of encryption used on databases passed to it.", "Name": "Get-DbaDatabaseEncryption", "Links": "https://dbatools.io/Get-DbaDatabaseEncryption", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseEncryption -SqlInstance DEV01\r\n\r\nList all encrpytion found on the instance by database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseEncryption -SqlInstance DEV01 -Database MyDB\r\n\r\nList all encrption found for the MyDB database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseEncryption -SqlInstance DEV01 -ExcludeDatabase MyDB\r\n\r\nList all encrption found for all databases except MyDB.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseEncryption -SqlInstance DEV01 -IncludeSystemDBs\r\n\r\nList all encrption found for all databases including the system databases.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseFile", "Description": "Returns detailed information about database files. Does not use SMO - SMO causes enumeration and this command avoids that.", "Tags": "Database", "Author": "Stuart Moore (@napalmgram), stuart-moore.com", "Synopsis": "Returns detailed information about database files.", "Name": "Get-DbaDatabaseFile", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseFile -SqlInstance sql2016\r\n\r\nWill return an object containing all filegroups and their contained files for every database on the sql2016 SQL Server \r\ninstance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseFile -SqlInstance sql2016 -Database Impromptu\r\n\r\nWill return an object containing all filegroups and their contained files for the Impromptu Database on the sql2016 SQL \r\nServer instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseFile -SqlInstance sql2016 -Database Impromptu, Trading\r\n\r\nWill return an object containing all filegroups and their contained files for the Impromptu and Trading databases on \r\nthe sql2016 SQL Server instance\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseMasterKey", "Description": "Gets specified database master key", "Tags": [ "Certificate", "Databases" ], "Synopsis": "Gets specified database master key", "Name": "Get-DbaDatabaseMasterKey", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseMasterKey -SqlInstance sql2016\r\n\r\nGets all master database keys\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseMasterKey -SqlInstance Server1 -Database db1\r\n\r\nGets the master key for the db1 database\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabasePartitionFunction", "Description": "Gets database Partition Functions", "Tags": "Databases", "Author": "Klaas Vandenberghe ( @PowerDbaKlaas )", "Synopsis": "Gets database Partition Functions", "Name": "Get-DbaDatabasePartitionFunction", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabasePartitionFunction -SqlInstance sql2016\r\n\r\nGets all database Partition Functions\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabasePartitionFunction -SqlInstance Server1 -Database db1\r\n\r\nGets the Partition Functions for the db1 database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabasePartitionFunction -SqlInstance Server1 -ExcludeDatabase db1\r\n\r\nGets the Partition Functions for all databases except db1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e\u0027Sql1\u0027,\u0027Sql2/sqlexpress\u0027 | Get-DbaDatabasePartitionFunction\r\n\r\nGets the Partition Functions for the databases on Sql1 and Sql2/sqlexpress\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabasePartitionScheme", "Description": "Gets database Partition Schemes", "Tags": "Databases", "Author": "Klaas Vandenberghe ( @PowerDbaKlaas )", "Synopsis": "Gets database Partition Schemes", "Name": "Get-DbaDatabasePartitionScheme", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabasePartitionScheme -SqlInstance sql2016\r\n\r\nGets all database Partition Schemes\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabasePartitionScheme -SqlInstance Server1 -Database db1\r\n\r\nGets the Partition Schemes for the db1 database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabasePartitionScheme -SqlInstance Server1 -ExcludeDatabase db1\r\n\r\nGets the Partition Schemes for all databases except db1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e\u0027Sql1\u0027,\u0027Sql2/sqlexpress\u0027 | Get-DbaDatabasePartitionScheme\r\n\r\nGets the Partition Schemes for the databases on Sql1 and Sql2/sqlexpress\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseSnapshot", "Description": "Retrieves the list of database snapshot available, along with their base (the db they are the snapshot of) and creation time", "Tags": "Snapshot", "Author": "niphlod", "Synopsis": "Get database snapshots with details", "Name": "Get-DbaDatabaseSnapshot", "Links": "https://dbatools.io/Get-DbaDatabaseSnapshot", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseSnapshot -SqlInstance sqlserver2014a\r\n\r\nReturns a custom object displaying Server, Database, DatabaseCreated, SnapshotOf, SizeMB, DatabaseCreated\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting\r\n\r\nReturns information for database snapshots having HR and Accounting as base dbs\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Snapshot HR_snapshot, Accounting_snapshot\r\n\r\nReturns information for database snapshots HR_snapshot and Accounting_snapshot\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseSpace", "Description": "This function returns database file space information for a SQL Instance or group of SQL\nInstances. Information is based on a query against sys.database_files and the FILEPROPERTY\nfunction to query and return information. The function can accept a single instance or\nmultiple instances. By default, only user dbs will be shown, but using the IncludeSystemDBs\nswitch will include system databases\n\nFile free space script borrowed and modified from Glenn Berry\u0027s DMV scripts (http://www.sqlskills.com/blogs/glenn/category/dmv-queries/)", "Author": "Michael Fal (@Mike_Fal), http://mikefal.net", "Synopsis": "Returns database file space information for database files on a SQL instance.", "Name": "Get-DbaDatabaseSpace", "Links": "https://dbatools.io/Get-DbaDatabaseSpace", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseSpace -SqlInstance localhost\r\n\r\nReturns all user database files and free space information for the local host\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseSpace -SqlInstance localhost | Where-Object {$_.PercentUsed -gt 80}\r\n\r\nReturns all user database files and free space information for the local host. Filters\r\nthe output object by any files that have a percent used of greater than 80%.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e\u0027localhost\u0027,\u0027localhost\\namedinstance\u0027 | Get-DbaDatabaseSpace\r\n\r\nReturns all user database files and free space information for the localhost and\r\nlocalhost\\namedinstance SQL Server instances. Processes data via the pipeline.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseSpace -SqlInstance localhost -Database db1, db2\r\n\r\nReturns database files and free space information for the db1 and db2 on localhost.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseState", "Description": "Gets some common \"states\" on databases:\n - \"RW\" options : READ_ONLY or READ_WRITE\n - \"Status\" options : ONLINE, OFFLINE, EMERGENCY\n - \"Access\" options : SINGLE_USER, RESTRICTED_USER, MULTI_USER\n\nReturns an object with SqlInstance, Database, RW, Status, Access", "Tags": "Databases", "Author": "niphlod", "Synopsis": "Gets various options for databases, hereby called \"states\"", "Name": "Get-DbaDatabaseState", "Links": "https://dbatools.io/Get-DbaDatabaseState", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseState -SqlInstance sqlserver2014a\r\n\r\nGets options for all databases of the sqlserver2014a instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseState -SqlInstance sqlserver2014a -Database HR, Accounting\r\n\r\nGets options for both HR and Accounting database of the sqlserver2014a instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseState -SqlInstance sqlserver2014a -Exclude HR\r\n\r\nGets options for all databases of the sqlserver2014a instance except HR\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e\u0027sqlserver2014a\u0027, \u0027sqlserver2014b\u0027 | Get-DbaDatabaseState\r\n\r\nGets options for all databases of sqlserver2014a and sqlserver2014b instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseUdf", "Description": "Gets database User Defined Functions", "Tags": [ "security", "Databases" ], "Author": "Klaas Vandenberghe ( @PowerDbaKlaas )", "Synopsis": "Gets database User Defined Functions", "Name": "Get-DbaDatabaseUdf", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseUdf -SqlInstance sql2016\r\n\r\nGets all database User Defined Functions\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseUdf -SqlInstance Server1 -Database db1\r\n\r\nGets the User Defined Functions for the db1 database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseUdf -SqlInstance Server1 -ExcludeDatabase db1\r\n\r\nGets the User Defined Functions for all databases except db1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseUdf -SqlInstance Server1 -ExcludeSystemUdf\r\n\r\nGets the User Defined Functions for all databases that are not system objects (there can be 100+ system User Defined \r\nFunctions in each DB)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e\u0027Sql1\u0027,\u0027Sql2/sqlexpress\u0027 | Get-DbaDatabaseUdf\r\n\r\nGets the User Defined Functions for the databases on Sql1 and Sql2/sqlexpress\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseUser", "Description": "Gets database users", "Tags": [ "security", "Databases" ], "Author": "Klaas Vandenberghe ( @PowerDbaKlaas )", "Synopsis": "Gets database users", "Name": "Get-DbaDatabaseUser", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseUser -SqlInstance sql2016\r\n\r\nGets all database users\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseUser -SqlInstance Server1 -Database db1\r\n\r\nGets the users for the db1 database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseUser -SqlInstance Server1 -ExcludeDatabase db1\r\n\r\nGets the users for all databases except db1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseUser -SqlInstance Server1 -ExcludeSystemUser\r\n\r\nGets the users for all databases that are not system objects, like \u0027dbo\u0027, \u0027guest\u0027 or \u0027INFORMATION_SCHEMA\u0027\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e\u0027Sql1\u0027,\u0027Sql2/sqlexpress\u0027 | Get-DbaDatabaseUser\r\n\r\nGets the users for the databases on Sql1 and Sql2/sqlexpress\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDatabaseView", "Description": "Gets database views", "Tags": [ "security", "Databases" ], "Author": "Klaas Vandenberghe ( @PowerDbaKlaas )", "Synopsis": "Gets database views", "Name": "Get-DbaDatabaseView", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseView -SqlInstance sql2016\r\n\r\nGets all database views\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseView -SqlInstance Server1 -Database db1\r\n\r\nGets the views for the db1 database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseView -SqlInstance Server1 -ExcludeDatabase db1\r\n\r\nGets the views for all databases except db1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseView -SqlInstance Server1 -ExcludeSystemView\r\n\r\nGets the views for all databases that are not system objects (there can be 400+ system views in each DB)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e\u0027Sql1\u0027,\u0027Sql2/sqlexpress\u0027 | Get-DbaDatabaseView\r\n\r\nGets the views for the databases on Sql1 and Sql2/sqlexpress\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDbMailHistory", "Description": "Gets the history of mail sent from a SQL instance", "Tags": "Logging", "Synopsis": "Gets the history of mail sent from a SQL instance", "Name": "Get-DbaDbMailHistory", "Links": "https://dbatools.io/Get-DbaDbMailHistory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbMailHistory -SqlInstance sql01\\sharepoint\r\n\r\nReturns the entire dbmail history on sql01\\sharepoint\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbMailHistory -SqlInstance sql01\\sharepoint | Select *\r\n\r\nReturns the entire dbmail history on sql01\\sharepoint then return a bunch more columns\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$servers = \"sql2014\",\"sql2016\", \"sqlcluster\\sharepoint\"\r\n\r\n$servers | Get-DbaDbMailHistory\r\n\r\nReturns the all dbmail history for \"sql2014\",\"sql2016\" and \"sqlcluster\\sharepoint\"\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDbMailLog", "Description": "Gets the DBMail log from a SQL instance", "Tags": "Logging", "Synopsis": "Gets the DBMail log from a SQL instance", "Name": "Get-DbaDbMailLog", "Links": "https://dbatools.io/Get-DbaDbMailLog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbMailLog -SqlInstance sql01\\sharepoint\r\n\r\nReturns the entire dbmail log on sql01\\sharepoint\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbMailLog -SqlInstance sql01\\sharepoint | Select *\r\n\r\nReturns the entire dbmail log on sql01\\sharepoint then return a bunch more columns\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$servers = \"sql2014\",\"sql2016\", \"sqlcluster\\sharepoint\"\r\n\r\n$servers | Get-DbaDbMailLog -Type Error, Information\r\n\r\nReturns only the Error and Information dbmail log for \"sql2014\",\"sql2016\" and \"sqlcluster\\sharepoint\"\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDbQueryStoreOptions", "Description": "Retrieves and returns the Query Store configuration for every database that has the Query Store feature enabled.", "Tags": "QueryStore", "Author": "Enrico van de Laar ( @evdlaar )", "Synopsis": "Get the Query Store configuration for Query Store enabled databases.", "Name": "Get-DbaDbQueryStoreOptions", "Links": "https://dbatools.io/Get-DbaQueryStoreOptions", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbQueryStoreOptions -SqlInstance ServerA\\sql\r\n\r\nReturns Query Store configuration settings for every database on the ServerA\\sql instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbQueryStoreOptions -SqlInstance ServerA\\sql | Where-Object {$_.ActualState -eq \"ReadWrite\"}\r\n\r\nReturns the Query Store configuration for all databases on ServerA\\sql where the Query Store feature is in Read/Write \r\nmode.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbQueryStoreOptions -SqlInstance localhost | format-table -AutoSize -Wrap\r\n\r\nReturns Query Store configuration settings for every database on the ServerA\\sql instance inside a table format.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDbStoredProcedure", "Description": "Gets database Stored Procedures", "Tags": "Databases", "Author": "Klaas Vandenberghe ( @PowerDbaKlaas )", "Synopsis": "Gets database Stored Procedures", "Name": "Get-DbaDbStoredProcedure", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbStoredProcedure -SqlInstance sql2016\r\n\r\nGets all database Stored Procedures\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbStoredProcedure -SqlInstance Server1 -Database db1\r\n\r\nGets the Stored Procedures for the db1 database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbStoredProcedure -SqlInstance Server1 -ExcludeDatabase db1\r\n\r\nGets the Stored Procedures for all databases except db1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDbStoredProcedure -SqlInstance Server1 -ExcludeSystemSp\r\n\r\nGets the Stored Procedures for all databases that are not system objects\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e\u0027Sql1\u0027,\u0027Sql2/sqlexpress\u0027 | Get-DbaDbStoredProcedure\r\n\r\nGets the Stored Procedures for the databases on Sql1 and Sql2/sqlexpress\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDefaultPath", "Description": "Gets the default SQL Server paths for data, logs and backups", "Tags": "Config", "Synopsis": "Gets the default SQL Server paths for data, logs and backups", "Name": "Get-DbaDefaultPath", "Links": "https://dbatools.io/Get-DbaDefaultPath", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDefaultPath -SqlInstance sql01\\sharepoint\r\n\r\nReturns the default file paths for sql01\\sharepoint\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$servers = \"sql2014\",\"sql2016\", \"sqlcluster\\sharepoint\"\r\n\r\n$servers | Get-DbaDefaultPath\r\n\r\nReturns the default file paths for \"sql2014\",\"sql2016\" and \"sqlcluster\\sharepoint\"\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDependency", "Description": "This function recursively finds all objects that depends on the input.\nIt will then retrieve rich information from them, including their creation scripts and the order in which it should be applied.\n\nBy using the \u0027Parents\u0027 switch, the function will instead retrieve all items that the input depends on (including their creation scripts).\n\nFor more details on dependency, see:\nhttps://technet.microsoft.com/en-us/library/ms345449(v=sql.105).aspx", "Synopsis": "Finds object dependencies and their relevant creation scripts.", "Name": "Get-DbaDependency", "Links": "https://dbatools.io/Get-DbaDependency", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003e$table = (Get-DbaDatabase -SqlInstance sql2012 Northwind).tables | Where Name -eq Customers\r\n\r\n$table | Get-DbaDependency\r\n\r\nReturns everything that depends on the \"Customers\" table\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDetachedDatabaseInfo", "Description": "Gathers the following information from detached database files: database name, SQL Server version (compatibility level), collation, and file structure. \n\n\"Data files\" and \"Log file\" report the structure of the data and log files as they were when the database was detached. \"Database version\" is the compatibility level.\n\nMDF files are most easily read by using a SQL Server to interpret them. Because of this, you must specify a SQL Server and the path must be relative to the SQL Server.", "Tags": "DisasterRecovery", "Synopsis": "Get detailed information about detached SQL Server database files.", "Name": "Get-DbaDetachedDatabaseInfo", "Links": "https://dbatools.io/Get-DbaDetachedDatabaseInfo", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDetachedDatabaseInfo -SqlInstance sql2016 -Path M:\\Archive\\mydb.mdf\r\n\r\nReturns information about the detached database file M:\\Archive\\mydb.mdf using the SQL Server instance sql2016. The M \r\ndrive is relative to the SQL Server instance.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaDiskSpace", "Description": "Returns a custom object with server name, name of disk, label of disk, total size, free size, percent free, block size and filesystem.\n\nBy default, this function only shows drives of types 2 and 3 (removable disk and local disk).\n\nRequires Windows administrator access on SQL Servers", "Tags": "Storage", "Author": "Chrissy LeMaire (clemaire@gmail.com) \u0026 Jakob Bindslet (jakob@bindslet.dk)", "Synopsis": "Displays disk information for all local drives on a server.", "Name": "Get-DbaDiskSpace", "Links": "https://dbatools.io/Get-DbaDiskSpace", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDiskSpace -ComputerName srv0042 | Format-Table -AutoSize\r\n\r\nGet disk space for the server srv0042.\r\n\r\nServer Name Label SizeInGB FreeInGB PercentFree BlockSize\r\n------ ---- ----- -------- -------- ----------- ---------\r\nsrv0042 C:\\ System 126,45 114,12 90,25 4096\r\nsrv0042 E:\\ Data1 97,62 96,33 98,67 4096\r\nsrv0042 F:\\ DATA2 29,2 29,2 100 16384\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDiskSpace -ComputerName srv0042 -Unit MB | Format-Table -AutoSize\r\n\r\nGet disk space for the server srv0042 and displays in megabytes (MB).\r\n\r\nServer Name Label SizeInMB FreeInMB PercentFree BlockSize\r\n------ ---- ----- -------- -------- ----------- ---------\r\nsrv0042 C:\\ System 129481 116856,11 90,25 4096\r\nsrv0042 E:\\ Data1 99968 98637,56 98,67 4096\r\nsrv0042 F:\\ DATA2 29901 29900,92 100 16384\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDiskSpace -ComputerName srv0042, srv0007 -Unit TB | Format-Table -AutoSize\r\n\r\nGet disk space from two servers and displays in terabytes (TB).\r\n\r\nServer Name Label SizeInTB FreeInTB PercentFree BlockSize\r\n------ ---- ----- -------- -------- ----------- ---------\r\nsrv0042 C:\\ System 0,12 0,11 90,25 4096\r\nsrv0042 E:\\ Data1 0,1 0,09 98,67 4096\r\nsrv0042 F:\\ DATA2 0,03 0,03 100 16384\r\nsrv0007 C:\\ System 0,07 0,01 11,92 4096\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDiskSpace -ComputerName srv0042 -Detailed | Format-Table -AutoSize\r\n\r\nGet detailed disk space information.\r\n\r\nServer Name Label SizeInGB FreeInGB PercentFree BlockSize IsSqlDisk \r\nFileSystem DriveType\r\n------ ---- ----- -------- -------- ----------- --------- --------- \r\n---------- ---------\r\nsrv0042 C:\\ System 126,45 114,12 90,25 4096 False \r\nNTFS Local Disk\r\nsrv0042 E:\\ Data1 97,62 96,33 98,67 4096 False \r\nReFS Local Disk\r\nsrv0042 F:\\ DATA2 29,2 29,2 100 16384 False \r\nFAT32 Local Disk\r\nsrv0042 \\\\?\\Volume{7a31be94-b842-42f5-af71-e0464a1a9803}\\ Recovery 0,44 0,13 30,01 4096 False \r\nNTFS Local Disk\r\nsrv0042 D:\\ 0 0 0 False \r\n Compact Disk\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaEndpoint", "Description": "The Get-DbaEndpoint command gets SQL Endpoint(s) information for each instance(s) of SQL Server.", "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Endpoint(s) information for each instance(s) of SQL Server.", "Name": "Get-DbaEndpoint", "Links": "https://dbatools.io/Get-DbaEndpoint", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaEndpoint -SqlInstance localhost\r\n\r\nReturns all Endpoint(s) on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaEndpoint -SqlInstance localhost, sql2016\r\n\r\nReturns all Endpoint(s) for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaEstimatedCompletionTime", "Description": "Gets execution and estimated completion time information for queries\n\nPercent complete will show for the following commands\n\t\nALTER INDEX REORGANIZE\nAUTO_SHRINK option with ALTER DATABASE\nBACKUP DATABASE\nDBCC CHECKDB\nDBCC CHECKFILEGROUP\nDBCC CHECKTABLE\nDBCC INDEXDEFRAG\nDBCC SHRINKDATABASE\nDBCC SHRINKFILE\nRECOVERY\nRESTORE DATABASE\nROLLBACK\nTDE ENCRYPTION\n\t\nFor additional information, check out https://blogs.sentryone.com/loriedwards/patience-dm-exec-requests/ and https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-exec-requests-transact-sql", "Tags": "Database", "Synopsis": "Gets execution and estimated completion time information for queries", "Name": "Get-DbaEstimatedCompletionTime", "Links": "https://dbatools.io/Get-DbaEstimatedCompletionTime", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaEstimatedCompletionTime -SqlInstance sql2016\r\n\r\nGets estimated completion times for queries performed against the entire server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaEstimatedCompletionTime -SqlInstance sql2016 | Select *\r\n\r\nGets estimated completion times for queries performed against the entire server PLUS the SQL query text of each command\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaEstimatedCompletionTime -SqlInstance sql2016 | Where-Object { $_.Text -match \u0027somequerytext\u0027 }\r\n\r\nGets results for commands whose queries only match specific text (match is like LIKE but way more powerful)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaEstimatedCompletionTime -SqlInstance sql2016 -Database Northwind,pubs,Adventureworks2014\r\n\r\nGets estimated completion times for queries performed against the Northwind, pubs, and Adventureworks2014 databases\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaExecutionPlan", "Description": "Gets execution plans and metadata. Can pipe to Export-DbaExecutionPlan :D\n\t\nThanks to \n\thttps://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/\n\tand\n\thttp://www.scarydba.com/2017/02/13/export-plans-cache-sqlplan-file/\nfor the idea and query.", "Tags": "Performance", "Synopsis": "Gets execution plans and metadata", "Name": "Get-DbaExecutionPlan", "Links": "https://dbatools.io/Get-DbaExecutionPlan", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaExecutionPlan -SqlInstance sqlserver2014a\r\n\r\nGets all execution plans on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaExecutionPlan -SqlInstance sqlserver2014a -Database db1, db2 -SinceLastExecution \u00277/1/2016 10:47:00\u0027\r\n\r\nGets all execution plans for databases db1 and db2 on sqlserve2014a since July 1, 2016 at 10:47 AM.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaExecutionPlan -SqlInstance sqlserver2014a, sql2016 -Exclude db1 | Format-Table\r\n\r\nGets execution plan info for all databases except db1 on sqlserver2014a and sql2016 and makes the output pretty\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaExecutionPlan -SqlInstance sql2014 -Database AdventureWorks2014, pubs -Force\r\n\r\nGets super detailed information for execution plans on only for AdventureWorks2014 and pubs\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaFile", "Description": "This command searches all specified directories, allowing a DBA to see file information on a server without direct access\n\nYou can filter by extension using the -FileType parameter. By default, the default data directory will be returned. You can provide and additional paths to search using the -Path parameter.", "Tags": "Discovery", "Author": "Brandon Abshire, netnerds.net", "Synopsis": "Get-DbaFile finds files in any directory specified on a remote SQL Server", "Name": "Get-DbaFile", "Links": "https://dbatools.io/Get-DbaFile", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaFile -SqlInstance sqlserver2014a -Path E:\\Dir1\r\n\r\nLogs into the SQL Server \"sqlserver2014a\" using Windows credentials and searches E:\\Dir for all files\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaFile -SqlInstance sqlserver2014a -SqlCredential $cred -Path \u0027E:\\sql files\u0027\r\n\r\nLogs into the SQL Server \"sqlserver2014a\" using alternative credentials and returns all files in \u0027E:\\sql files\u0027\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$all = Get-DbaDefaultPath -SqlInstance sql2014\r\n\r\nGet-DbaFile -SqlInstance sql2014 -Path $all.Data, $all.Log, $all.Backup\r\nReturns the files in the default data, log and backup directories on sql2014\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaFile -SqlInstance sql2014 -Path \u0027E:\\Dir1\u0027, \u0027E:\\Dir2\u0027\r\n\r\nReturns the files in \"E:\\Dir1\" and \"E:Dir2\" on sql2014\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaFile -SqlInstance -Path \u0027E:\\Dir1\u0027 sql2014, sql2016 -FileType fsf, mld\r\n\r\nFinds files in E:\\Dir1 ending with \".fsf\" and \".mld\" for both the servers sql2014 and sql2016.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaFile -SqlInstance -Path \u0027E:\\Dir1\u0027 sql2014, sql2016 -FileType fsf, mld\r\n\r\nFinds files in E:\\Dir1 ending with \".fsf\" and \".mld\" for both the servers sql2014 and sql2016.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaForceNetworkEncryption", "Description": "Gets Force Encryption settings for a SQL Server instance. Note that this requires access to the Windows Server - not the SQL instance itself.\n\nThis setting is found in Configuration Manager.", "Tags": "Certificate", "Synopsis": "Gets Force Encryption settings for a SQL Server instance", "Name": "Get-DbaForceNetworkEncryption", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaForceNetworkEncryption\r\n\r\nGets Force Encryption properties on the default (MSSQLSERVER) instance on localhost - requires (and checks for) RunAs \r\nadmin.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaForceNetworkEncryption -SqlInstance sql01\\SQL2008R2SP2\r\n\r\nGets Force Network Encryption for the SQL2008R2SP2 on sql01. Uses Windows Credentials to both login and view the \r\nregistry.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaHelpIndex", "Description": "This function will return detailed information on indexes (and optionally statistics) for all indexes in a database, or a given index should one be passed along.\nAs this uses SQL Server DMVs to access the data it will only work in 2005 and up (sorry folks still running SQL Server 2000).\nFor performance reasons certain statistics information will not be returned from SQL Server 2005 if an ObjectName is not provided.\n\nThe data includes:\n\t- ObjectName: the table containing the index\n\t- IndexType: clustered/non-clustered/columnstore and whether the index is unique/primary key\n\t- KeyColumns: the key columns of the index\n\t- IncludeColumns: any include columns in the index\n\t- FilterDefinition: any filter that may have been used in the index\n\t- DataCompression: row/page/none depending upon whether or not compression has been used\n\t- IndexReads: the number of reads of the index since last restart or index rebuild\n\t- IndexUpdates: the number of writes to the index since last restart or index rebuild\n\t- SizeKB: the size the index in KB\n\t- IndexRows: the number of the rows in the index (note filtered indexes will have fewer rows than exist in the table)\n\t- IndexLookups: the number of lookups that have been performed (only applicable for the heap or clustered index)\n\t- MostRecentlyUsed: when the index was most recently queried (default to 1900 for when never read)\n\t- StatsSampleRows: the number of rows queried when the statistics were built/rebuilt (not included in SQL Server 2005 unless ObjectName is specified)\n\t- StatsRowMods: the number of changes to the statistics since the last rebuild\n\t- HistogramSteps: the number of steps in the statistics histogram (not included in SQL Server 2005 unless ObjectName is specified)\n\t- StatsLastUpdated: when the statistics were last rebuilt (not included in SQL Server 2005 unless ObjectName is specified)", "Tags": "Indexes", "Author": "Nic Cain, https://sirsql.net/", "Synopsis": "Returns size, row and configuration information for indexes in databases.", "Name": "Get-DbaHelpIndex", "Links": "https://dbatools.io/Get-DbaHelpIndex", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaHelpIndex -SqlInstance localhost -Database MyDB\r\n\r\nReturns information on all indexes on the MyDB database on the localhost.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaHelpIndex -SqlInstance localhost -Database MyDB,MyDB2\r\n\r\nReturns information on all indexes on the MyDB, MyDB2 databases\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaHelpIndex -SqlInstance localhost -Database MyDB -ObjectName dbo.Table1\r\n\r\nReturns index information on the object dbo.Table1 in the database MyDB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaHelpIndex -SqlInstance localhost -Database MyDB -ObjectName dbo.Table1 -IncludeStats\r\n\r\nReturns information on the indexes and statistics for the table dbo.Table1 in the MyDB database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaHelpIndex -SqlInstance localhost -Database MyDB -ObjectName dbo.Table1 -IncludeDataTypes\r\n\r\nReturns the index information for the table dbo.Table1 in the MyDB database, and includes the data types for the key \r\nand include columns\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaHelpIndex -SqlInstance localhost -Database MyDB -ObjectName dbo.Table1 -FormatResults\r\n\r\nReturns the index information for the table dbo.Table1 in the MyDB database, and returns the numerical data with \r\nseparators to make it more readable (ie 1234 becomes 1,234)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaHelpIndex -SqlInstance localhost -Database MyDB -IncludeStats -FormatResults\r\n\r\nReturns the index information for all index in the MyDB database, as well as statistics, and formats the numerical data \r\nto be more redable\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaJobCategory", "Description": "The Get-DbaJobCategory returns connected SMO object for SQL Agent Job Category information for each instance(s) of SQL Server.", "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Agent Job Category information for each instance(s) of SQL Server.", "Name": "Get-DbaJobCategory", "Links": "https://dbatools.io/Get-DbaJobCategory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaJobCategory -SqlInstance localhost\r\n\r\nReturns all SQL Agent Job Categories on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaJobCategory -SqlInstance localhost, sql2016\r\n\r\nReturns all SQL Agent Job Categories for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaLastBackup", "Description": "Retrieves and compares the date/time for the last known backups, as well as the creation date/time for the database.\n\nDefault output includes columns Server, Database, RecoveryModel, LastFullBackup, LastDiffBackup, LastLogBackup, SinceFull, SinceDiff, SinceLog, Status, DatabaseCreated, DaysSinceDbCreated.", "Tags": [ "DisasterRecovery", "Backup" ], "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Get date/time for last known backups", "Name": "Get-DbaLastBackup", "Links": "https://dbatools.io/Get-DbaLastBackup", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLastBackup -SqlInstance ServerA\\sql987\r\n\r\nReturns a custom object displaying Server, Database, RecoveryModel, LastFullBackup, LastDiffBackup, LastLogBackup, \r\nSinceFull, SinceDiff, SinceLog, Status, DatabaseCreated, DaysSinceDbCreated\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLastBackup -SqlInstance ServerA\\sql987\r\n\r\nReturns a custom object with Server name, Database name, and the date the last time backups were performed\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLastBackup -SqlInstance ServerA\\sql987 | Select *\r\n\r\nReturns a custom object with Server name, Database name, and the date the last time backups were performed, and also \r\nrecoverymodel and calculations on how long ago backups were taken and what the status is.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLastBackup -SqlInstance ServerA\\sql987 | Select * | Out-Gridview\r\n\r\nReturns a gridview displaying Server, Database, RecoveryModel, LastFullBackup, LastDiffBackup, LastLogBackup, \r\nSinceFull, SinceDiff, SinceLog, Status, DatabaseCreated, DaysSinceDbCreated\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaLastGoodCheckDb", "Description": "Retrieves and compares the date/time for the last known good DBCC CHECKDB, as well as the creation date/time for the database.\n\nThis function supports SQL Server 2005+\n\nPlease note that this script uses the DBCC DBINFO() WITH TABLERESULTS. DBCC DBINFO has several known weak points, such as:\n - DBCC DBINFO is an undocumented feature/command.\n - The LastKnowGood timestamp is updated when a DBCC CHECKFILEGROUP is performed.\n - The LastKnowGood timestamp is updated when a DBCC CHECKDB WITH PHYSICAL_ONLY is performed.\n - The LastKnowGood timestamp does not get updated when a database in READ_ONLY.\n\nAn empty ($null) LastGoodCheckDb result indicates that a good DBCC CHECKDB has never been performed.\n\nSQL Server 2008R2 has a \"bug\" that causes each databases to possess two dbi_dbccLastKnownGood fields, instead of the normal one.\nThis script will only display this function to only display the newest timestamp. If -Verbose is specified, the function will announce every time more than one dbi_dbccLastKnownGood fields is encountered.", "Tags": [ "CHECKDB", "Database" ], "Author": "Jakob Bindslet (jakob@bindslet.dk)", "Synopsis": "Get date/time for last known good DBCC CHECKDB", "Name": "Get-DbaLastGoodCheckDb", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLastGoodCheckDb -SqlInstance ServerA\\sql987\r\n\r\nReturns a custom object displaying Server, Database, DatabaseCreated, LastGoodCheckDb, DaysSinceDbCreated, \r\nDaysSinceLastGoodCheckDb, Status and DataPurityEnabled\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLastGoodCheckDb -SqlInstance ServerA\\sql987 -SqlCredential (Get-Credential sqladmin) | Format-Table \r\n-AutoSize\r\n\r\nReturns a formatted table displaying Server, Database, DatabaseCreated, LastGoodCheckDb, DaysSinceDbCreated, \r\nDaysSinceLastGoodCheckDb, Status and DataPurityEnabled.\r\nAuthenticates with SQL Server using alternative credentials.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaLinkedServer", "Description": "Retrieves information about each linked server on the instance", "Author": "Stephen Bennett ( https://sqlnotesfromtheunderground.wordpress.com/ )", "Synopsis": "Gets all linked servers and summary of information from the sql servers listed", "Name": "Get-DbaLinkedServer", "Links": "https://dbatools.io/Get-DbaLinkedServer", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLinkedServer -SqlInstance DEV01\r\n\r\nReturns all Linked Servers for the SQL Server instance DEV01\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaLocaleSetting", "Description": "Gets the Locale settings on one or more computers.\n\nRequires Local Admin rights on destination computer(s).", "Tags": "OS", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Gets the Locale settings on a computer.", "Name": "Get-DbaLocaleSetting", "Links": "https://dbatools.io/Get-DbaLocaleSetting", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLocaleSetting -ComputerName sqlserver2014a\r\n\r\nGets the Locale settings on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027 | Get-DbaLocaleSetting\r\n\r\nGets the Locale settings on computers sql1, sql2 and sql3.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLocaleSetting -ComputerName sql1,sql2 | Out-Gridview\r\n\r\nGets the Locale settings on computers sql1 and sql2, and shows them in a grid view.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaLogin", "Description": "The Get-DbaLogin function returns an SMO Login object for the logins passed, if there are no users passed it will return all logins.", "Author": "Mitchell Hamann (@SirCaptainMitch)", "Synopsis": "Function to get an SMO login object of the logins for a given SQL Instance. Takes a server object from the pipe", "Name": "Get-DbaLogin", "Links": "https://dbatools.io/Get-DbaLogin", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLogin -SqlInstance sql2016\r\n\r\nGets all the logins from server sql2016 using NT authentication and returns the SMO login objects\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLogin -SqlInstance sql2016 -SqlCredential $sqlcred\r\n\r\nGets all the logins for a given SQL Server using a passed credential object and returns the SMO login objects\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLogin -SqlInstance sql2016 -SqlCredential $sqlcred -Login dbatoolsuser,TheCaptain\r\n\r\nGet specific logins from server sql2016 returned as SMO login objects.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaLogin -SqlInstance sql2016 -ExcludeLogin dbatoolsuser\r\n\r\nGet all user objects from server sql2016 except the login dbatoolsuser, returned as SMO login objects.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql2016\u0027, \u0027sql2014\u0027 | Get-DbaLogin -SqlCredential $sqlcred\r\n\r\nUsing Get-DbaLogin on the pipeline, you can also specify which names you would like with -Login.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql2016\u0027, \u0027sql2014\u0027 | Get-DbaLogin -SqlCredential $sqlcred -Locked\r\n\r\nUsing Get-DbaLogin on the pipeline to get all locked logins on servers sql2016 and sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql2016\u0027, \u0027sql2014\u0027 | Get-DbaLogin -SqlCredential $sqlcred -HasAccess -Disabled\r\n\r\nUsing Get-DbaLogin on the pipeline to get all Disabled logins that have access on servers sql2016 or sql2014.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaMaintenanceSolutionLog", "Description": "Ola wrote a .sql script to get the content from the commandLog table. However, if LogToTable=\u0027N\u0027, there will be no logging in that table. This function reads the text files that are written in the SQL Instance\u0027s Log directory.", "Author": "Klaas Vandenberghe ( @powerdbaklaas )", "Synopsis": "Reads the log files generated by the IndexOptimize Agent Job from Ola Hallengren\u0027s MaintenanceSolution.", "Name": "Get-DbaMaintenanceSolutionLog", "Links": "https://dbatools.io/Get-DbaMaintenanceSolutionLog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMaintenanceSolutionLog -SqlInstance sqlserver2014a\r\n\r\nGets the outcome of the IndexOptimize job on sql instance sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMaintenanceSolutionLog -SqlInstance sqlserver2014a -SqlCredential $credential\r\n\r\nGets the outcome of the IndexOptimize job on sqlserver2014a, using SQL Authentication.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e\u0027sqlserver2014a\u0027, \u0027sqlserver2020test\u0027 | Get-DbaMaintenanceSolutionLog\r\n\r\nGets the outcome of the IndexOptimize job on sqlserver2014a and sqlserver2020test.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMaintenanceSolutionLog -SqlInstance sqlserver2014a -Path \u0027D:\\logs\\maintenancesolution\\\u0027\r\n\r\nGets the outcome of the IndexOptimize job on sqlserver2014a, reading the log files in their custom location.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMaintenanceSolutionLog -SqlInstance sqlserver2014a -Since \u00272017-07-18\u0027\r\n\r\nGets the outcome of the IndexOptimize job on sqlserver2014a, starting from july 18, 2017.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMaintenanceSolutionLog -SqlInstance sqlserver2014a -LogType IndexOptimize\r\n\r\nGets the outcome of the IndexOptimize job on sqlserver2014a, the other options are not yet available! sorry\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaMaxMemory", "Description": "This command retrieves the SQL Server \u0027Max Server Memory\u0027 configuration setting as well as the total physical installed on the server.", "Tags": "Memory", "Synopsis": "Gets the \u0027Max Server Memory\u0027 configuration setting and the memory of the server. Works on SQL Server 2000-2014.", "Name": "Get-DbaMaxMemory", "Links": "https://dbatools.io/Get-DbaMaxMemory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMaxMemory -SqlInstance sqlcluster,sqlserver2012\r\n\r\nGet memory settings for all servers within the SQL Server Central Management Server \"sqlcluster\".\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMaxMemory -SqlInstance sqlcluster | Where-Object { $_.SqlMaxMB -gt $_.TotalMB }\r\n\r\nFind all servers in Server Central Management Server that have \u0027Max Server Memory\u0027 set to higher than the total memory \r\nof the server (think 2147483647)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaMemoryUsage", "Description": "Retrieves the amount of memory per performance counter. Default output includes columns Server, counter instance, counter, number of pages, memory in KB, memory in MB\nSSAS and SSIS are included.\n\t\nSSRS does not have memory counters, only memory shrinks and memory pressure state.\n\nThis function requires local admin role on the targeted computers.", "Tags": "Memory", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Get amount of memory in use by *all* SQL Server components and instances", "Name": "Get-DbaMemoryUsage", "Links": "https://dbatools.io/Get-DbaMemoryUsage", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMemoryUsage -ComputerName ServerA\r\n\r\nReturns a custom object displaying Server, counter instance, counter, number of pages, memory in KB, memory in MB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMemoryUsage -ComputerName ServerA\\sql987 -Simple\r\n\r\nReturns a custom object with Server, counter instance, counter, number of pages, memory in KB, memory in MB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMemoryUsage -ComputerName ServerA\\sql987 | Out-Gridview\r\n\r\nReturns a gridview displaying Server, counter instance, counter, number of pages, memory in KB, memory in MB\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaMsdtc", "Description": "Returns a custom object with Computer name, state of the MSDTC Service, security settings of MSDTC and CID\u0027s\n\nRequires: Windows administrator access on Servers", "Tags": [ "WSMan", "CIM" ], "Author": "Klaas Vandenberghe ( powerdbaklaas )", "Synopsis": "Displays information about the Distributed Transactioon Coordinator (MSDTC) on a server", "Name": "Get-DbaMsdtc", "Links": "https://dbatools.io/Get-DbaMsdtc", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMsdtc -ComputerName srv0042\r\n\r\nGet DTC status for the server srv0042\r\n\r\nComputerName : srv0042\r\nDTCServiceName : Distributed Transaction Coordinator\r\nDTCServiceState : Running\r\nDTCServiceStatus : OK\r\nDTCServiceStartMode : Manual\r\nDTCServiceAccount : NT AUTHORITY\\NetworkService\r\nDTCCID_MSDTC : b2aefacb-85d1-46b8-8047-7bb88e08d38a\r\nDTCCID_MSDTCUIS : 205bd32c-b022-4d0c-aa3e-2e5dc65c6d35\r\nDTCCID_MSDTCTIPGW : 3e743aa0-ead6-4569-ba7b-fe1aaea0a1eb\r\nDTCCID_MSDTCXATM : 667fc4b8-c2f5-4c3f-ad75-728b113f36c5\r\nnetworkDTCAccess : 0\r\nnetworkDTCAccessAdmin : 0\r\nnetworkDTCAccessClients : 0\r\nnetworkDTCAccessInbound : 0\r\nnetworkDTCAccessOutBound : 0\r\nnetworkDTCAccessTip : 0\r\nnetworkDTCAccessTransactions : 0\r\nXATransactions : 0\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$Computers = (Get-Content D:\\configfiles\\SQL\\MySQLInstances.txt | % {$_.split(\u0027\\\u0027)[0]})\r\n\r\n$Computers | Get-DbaMsdtc\r\n\r\nGet DTC status for all the computers in a .txt file\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMsdtc -Computername $Computers | where { $_.dtcservicestate -ne \u0027running\u0027 }\r\n\r\nGet DTC status for all the computers where the MSDTC Service is not running\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaMsdtc -ComputerName srv0042 | Out-Gridview\r\n\r\nGet DTC status for the computer srv0042 and show in a grid view\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaNetworkActivity", "Description": "Gets the Current traffic on every Network Interface on a computer.\nSee https://msdn.microsoft.com/en-us/library/aa394293(v=vs.85).aspx\n\nRequires Local Admin rights on destination computer(s).", "Tags": "Network", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Gets the Current traffic on every Network Interface on a computer.", "Name": "Get-DbaNetworkActivity", "Links": "https://dbatools.io/Get-DbaNetworkActivity", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaNetworkActivity -ComputerName sqlserver2014a\r\n\r\nGets the Current traffic on every Network Interface on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027 | Get-DbaNetworkActivity\r\n\r\nGets the Current traffic on every Network Interface on computers sql1, sql2 and sql3.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaNetworkActivity -ComputerName sql1,sql2 | Out-Gridview\r\n\r\nGets the Current traffic on every Network Interface on computers sql1 and sql2, and shows them in a grid view.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaNetworkCertificate", "Description": "Gets computer certificates on localhost that are candidates for using with SQL Server\u0027s network encryption", "Tags": "Certificate", "Synopsis": "Simplifies finding computer certificates that are candidates for using with SQL Server\u0027s network encryption", "Name": "Get-DbaNetworkCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaNetworkCertificate\r\n\r\nGets computer certificates on localhost that are candidates for using with SQL Server\u0027s network encryption\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaNetworkCertificate -ComputerName sql2016\r\n\r\nGets computer certificates on sql2016 that are being used for SQL Server network encryption\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaOperatingSystem", "Description": "Gets operating system information from the server and returns as an object.", "Tags": [ "ServerInfo", "OperatingSystem" ], "Author": "Shawn Melton (@wsmelton | http://blog.wsmelton.info)", "Synopsis": "Gets operating system information from the server.", "Name": "Get-DbaOperatingSystem", "Links": "https://dbatools.io/Get-DbaOperatingSystem", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaOperatingSystem\r\n\r\nReturns information about the local computer\u0027s operating system\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaOperatingSystem -ComputerName sql2016\r\n\r\nReturns information about the sql2016\u0027s operating system\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaPageFileSetting", "Description": "WMI class Win32_ComputerSystem tells us if Page File is managed automatically.\nIf TRUE all other properties do not exist.\nIf FALSE classes Win32_PageFile, Win32_PageFileSetting en Win32_PageFileUsage are examined.\nCIM is used, first via WinRM, and if not successful, via DCOM.\nThis function needs to be executed as a user with local admin rights on the target computer(s).", "Tags": "CIM", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Returns information about the network connection of the target computer including NetBIOS name, IP Address, domain name and fully qualified domain name (FQDN).", "Name": "Get-DbaPageFileSetting", "Links": "https://dbatools.io/Get-DbaPageFileSetting", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPageFileSetting -ComputerName ServerA,ServerB\r\n\r\nReturns a custom object displaying ComputerName, AutoPageFile, FileName, Status, LastModified, LastAccessed, \r\nAllocatedBaseSize, InitialSize, MaximumSize, PeakUsage, CurrentUsage for ServerA and ServerB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027ServerA\u0027 | Get-DbaPageFileSetting\r\n\r\nReturns a custom object displaying ComputerName, AutoPageFile, FileName, Status, LastModified, LastAccessed, \r\nAllocatedBaseSize, InitialSize, MaximumSize, PeakUsage, CurrentUsage for ServerA\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaPermission", "Description": "Retrieves a list of permissions\n\nPermissions link principals to securables.\nPrincipals exist on Windows, Instance and Database level.\nSecurables exist on Instance and Database level.\nA permission state can be GRANT, DENY or REVOKE.\nThe permission type can be SELECT, CONNECT, EXECUTE and more.\n\nSee https://msdn.microsoft.com/en-us/library/ms191291.aspx for more information", "Tags": [ "Permissions", "Databases" ], "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Get a list of Server and Database level permissions", "Name": "Get-DbaPermission", "Links": "https://dbatools.io/Get-DbaPermission", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPermission -SqlInstance ServerA\\sql987\r\n\r\nReturns a custom object with Server name, Database name, permission state, permission type, grantee and securable\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPermission -SqlInstance ServerA\\sql987 | Format-Table -AutoSize\r\n\r\nReturns a formatted table displaying Server, Database, permission state, permission type, grantee, granteetype, \r\nsecurable and securabletype\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPermission -SqlInstance ServerA\\sql987 -NoSystemObjects -IncludeServerLevel\r\n\r\nReturns a custom object with Server name, Database name, permission state, permission type, grantee and securable\r\nin all databases and on the server level, but not on system securables\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPermission -SqlInstance sql2016 -Database master\r\n\r\nReturns a custom object with permissions for the master database\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaPolicy", "Description": "Returns details of policies with the option to filter on Category and SystemObjects.", "Tags": [ "Policy", "PoilcyBasedManagement" ], "Author": "Stephen Bennett (https://sqlnotesfromtheunderground.wordpress.com/)", "Synopsis": "Returns polices from policy based management from an instance.", "Name": "Get-DbaPolicy", "Links": "https://dbatools.io/Get-DbaPolicy", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPolicy -SqlInstance sql2016\r\n\r\nReturns all policies from sql2016 server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPolicy -SqlInstance sql2016 -SqlCredential $cred\r\n\r\nUses a credential $cred to connect and return all policies from sql2016 instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPolicy -SqlInstance sql2016 -Category MorningCheck\r\n\r\nReturns all policies from sql2016 server that part of the PolicyCategory MorningCheck\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaPrivilege", "Description": "Gets the users with local privileges \u0027Lock Pages in Memory\u0027, \u0027Instant File Initialization\u0027, \u0027Logon as Batch\u0027 on one or more computers.\n\nRequires Local Admin rights on destination computer(s).", "Tags": "Privilege", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Gets the users with local privileges on one or more computersr.", "Name": "Get-DbaPrivilege", "Links": "https://dbatools.io/Get-DbaPrivilege", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPrivilege -ComputerName sqlserver2014a\r\n\r\nGets the local privileges on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027 | Get-DbaPrivilege\r\n\r\nGets the local privileges on computers sql1, sql2 and sql3.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaPrivilege -ComputerName sql1,sql2 | Out-Gridview\r\n\r\nGets the local privileges on computers sql1 and sql2, and shows them in a grid view.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaProcess", "Description": "This command displays processes associated with a spid, login, host, program or database.\n\nThanks to Michael J Swart at https://sqlperformance.com/2017/07/sql-performance/find-database-connection-leaks for the\nquery to get the last executed SQL statement, minutesasleep and host process ID", "Synopsis": "This command displays SQL Server processes.", "Name": "Get-DbaProcess", "Links": "https://dbatools.io/Get-DbaProcess", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaProcess -SqlInstance sqlserver2014a -Login base\\ctrlb, sa\r\n\r\nShows information about the processes for base\\ctrlb and sa on sqlserver2014a. Uses Windows Authentication to login to \r\nsqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaProcess -SqlInstance sqlserver2014a -SqlCredential $credential -Spid 56, 77\r\n\r\nShows information about the processes for spid 56 and 57. Uses alternative (SQL or Windows) credentials to login to \r\nsqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaProcess -SqlInstance sqlserver2014a -Program \u0027Microsoft SQL Server Management Studio\u0027\r\n\r\nShows information about the processes that were created in Microsoft SQL Server Management Studio.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaProcess -SqlInstance sqlserver2014a -Host workstationx, server100\r\n\r\nShows information about the processes that were initiated by hosts (computers/clients) workstationx and server 1000.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaQueryExecutionTime", "Description": "Quickly find slow query executions within a database. Results will include stored procedures and individual SQL statements.", "Tags": [ "Query", "Performance" ], "Author": "Brandon Abshire, netnerds.net", "Synopsis": "Displays Stored Procedures and Ad hoc queries with the highest execution times. Works on SQL Server 2008 and above.", "Name": "Get-DbaQueryExecutionTime", "Links": "https://dbatools.io/Get-DbaQueryExecutionTime", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaQueryExecutionTime -SqlInstance sql2008, sqlserver2012\r\n\r\nReturn the top 100 slowest stored procedures or statements for servers sql2008 and sqlserver2012.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaQueryExecutionTime -SqlInstance sql2008 -Database TestDB\r\n\r\nReturn the top 100 slowest stored procedures or statements on server sql2008 for only the TestDB database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaQueryExecutionTime -SqlInstance sql2008 -Database TestDB -MaxResultsPerDb 100 -MinExecs 200 -MinExecMs \r\n1000\r\n\r\nReturn the top 100 slowest stored procedures or statements on server sql2008 for only the TestDB database,\r\nlimiting results to queries with more than 200 total executions and an execution time over 1000ms or higher.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaRegisteredServer", "Description": "Returns an array of servers found in the CMS.", "Tags": [ "RegisteredServer", "CMS" ], "Author": "Bryan Hamby (@galador)", "Synopsis": "Gets list of SQL Server objects stored in SQL Server Central Management Server (CMS).", "Name": "Get-DbaRegisteredServer", "Links": "https://dbatools.io/Get-DbaRegisteredServer", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sqlserver2014a\r\n\r\nGets a list of servers from the CMS on sqlserver2014a, using Windows Credentials.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sqlserver2014a -SqlCredential $credential | Select-Object -Unique \r\n-ExpandProperty ServerName\r\n\r\nReturns only the server names from the CMS on sqlserver2014a, using SQL Authentication\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sqlserver2014a -Group HR, Accounting\r\n\r\nGets a list of servers in the HR and Accounting groups from the CMS on sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sqlserver2014a -Group HR\\Development\r\n\r\nReturns a list of servers in the HR and sub-group Development from the CMS on sqlserver2014a\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaRegisteredServersStore", "Description": "Returns a SQL Server Registered Server Store object - useful for working with Central Management Store", "Tags": [ "RegisteredServer", "CMS" ], "Synopsis": "Returns a SQL Server Registered Server Store Object", "Name": "Get-DbaRegisteredServersStore", "Links": "https://dbatools.io/Get-DbaRegisteredServersStore", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServersStore -SqlInstance sqlserver2014a\r\n\r\nReturns a SQL Server Registered Server Store Object from sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServersStore -SqlInstance sqlserver2014a -SqlCredential (Get-Credential sqladmin)\r\n\r\nReturns a SQL Server Registered Server Store Object from sqlserver2014a by logging in with the sqladmin login\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaRestoreHistory", "Description": "By default, this command will return the server name, database, username, restore type, date, from file and to files.\n\nThanks to https://www.mssqltips.com/SqlInstancetip/1724/when-was-the-last-time-your-sql-server-database-was-restored/ for the query and https://sqlstudies.com/2016/07/27/when-was-this-database-restored/ for the idea.", "Tags": [ "DisasterRecovery", "Backup", "Restore", "Databases" ], "Synopsis": "Returns restore history details for databases on a SQL Server", "Name": "Get-DbaRestoreHistory", "Links": "https://dbatools.io/Get-DbaRestoreHistory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRestoreHistory -SqlInstance sql2016\r\n\r\nReturns server name, database, username, restore type, date for all restored databases on sql2016.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRestoreHistory -SqlInstance sql2016 -Database db1, db2 -Since \u00277/1/2016 10:47:00\u0027\r\n\r\nReturns restore information only for databases db1 and db2 on sqlserve2014a since July 1, 2016 at 10:47 AM.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRestoreHistory -SqlInstance sql2016, sql2016 -Exclude db1\r\n\r\nLots of detailed information for all databases except db1 on sql2016 and sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRestoreHistory -SqlInstance sql2014 -Database AdventureWorks2014, pubs | Format-Table\r\n\r\nAdds From and To file information to output, returns information only for AdventureWorks2014 and pubs, and makes the \r\noutput pretty\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2016 | Get-DbaRestoreHistory\r\n\r\nReturns database restore information for every database on every server listed in the Central Management Server on \r\nsql2016\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaRoleMember", "Description": "Get members of all roles on a Sql instance.\n\nDefault output includes columns SQLServer, Database, Role, Member.", "Tags": [ "Roles", "Databases" ], "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Get members of all roles on a Sql instance.", "Name": "Get-DbaRoleMember", "Links": "https://dbatools.io/Get-DbaRoleMember", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRoleMember -SqlInstance ServerA\r\n\r\nReturns a custom object displaying SQLServer, Database, Role, Member for all DatabaseRoles.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRoleMember -SqlInstance sql2016 | Out-Gridview\r\n\r\nReturns a gridview displaying SQLServer, Database, Role, Member for all DatabaseRoles.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRoleMember -SqlInstance ServerA\\sql987 -IncludeServerLevel\r\n\r\nReturns a gridview displaying SQLServer, Database, Role, Member for both ServerRoles and DatabaseRoles.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaRunningJob", "Description": "This function returns agent jobs that active on the SQL Server instance when calling the command. The information is gathered the SMO JobServer.jobs and be returned either in detailed or standard format", "Author": "Stephen Bennett, https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Returns all non idle agent jobs running on the server.", "Name": "Get-DbaRunningJob", "Links": "https://dbatools.io/Get-DbaRunningJob", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRunningJob -SqlInstance localhost\r\n\r\nReturns any active jobs on the localhost\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRunningJob -SqlInstance localhost -Detailed\r\n\r\nReturns a detailed output of any active jobs on the localhost\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e\u0027localhost\u0027,\u0027localhost\\namedinstance\u0027 | Get-DbaRunningJob\r\n\r\nReturns all active jobs on multiple instances piped into the function\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSchemaChangeHistory", "Description": "Queries the default system trace for any DDL changes in the specified timeframe\nOnly works with SQL 2005 and later, as the system trace didn\u0027t exist before then", "Tags": [ "Migration", "Backup", "Databases" ], "Author": "Stuart Moore (@napalmgram - http://stuart-moore.com)", "Synopsis": "Gets DDL changes logged in the system trace.", "Name": "Get-DbaSchemaChangeHistory", "Links": "https://dbatools.io/Get-DbaSchemaChangeHistory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSchemaChangeHistory -SqlInstance localhost\r\n\r\nReturns all DDL changes made in all databases on the SQL Server instance localhost since the system trace began\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSchemaChangeHistory -SqlInstance localhost -Since (Get-Date).AddDays(-7)\r\n\r\nReturns all DDL changes made in all databases on the SQL Server instance localhost in the last 7 days\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSchemaChangeHistory -SqlInstance localhost -Database Finance, Prod -Since (Get-Date).AddDays(-7)\r\n\r\nReturns all DDL changes made in the Prod and Finance databases on the SQL Server instance localhost in the last 7 days\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSchemaChangeHistory -SqlInstance localhost -Database Finance -Object AccountsTable -Since \r\n(Get-Date).AddDays(-7)\r\n\r\nReturns all DDL changes made to the AccountsTable object in the Finance database on the SQL Server instance localhost \r\nin the last 7 days\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaServerAudit", "Description": "The Get-DbaServerAudit command gets SQL Security Audit information for each instance(s) of SQL Server.", "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Security Audit information for each instance(s) of SQL Server.", "Name": "Get-DbaServerAudit", "Links": "https://dbatools.io/Get-DbaServerAudit", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerAudit -SqlInstance localhost\r\n\r\nReturns all Security Audits on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerAudit -SqlInstance localhost, sql2016\r\n\r\nReturns all Security Audits for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaServerAuditSpecification", "Description": "The Get-DbaServerAuditSpecification command gets SQL Security Audit Specification information for each instance(s) of SQL Server.", "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets SQL Security Audit Specification information for each instance(s) of SQL Server.", "Name": "Get-DbaServerAuditSpecification", "Links": "https://dbatools.io/Get-DbaServerAuditSpecification", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerAuditSpecification -SqlInstance localhost\r\n\r\nReturns all Security Audit Specifications on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerAuditSpecification -SqlInstance localhost, sql2016\r\n\r\nReturns all Security Audit Specifications for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaServerInstallDate", "Description": "By default, this command returns for each SQL Instance instance passed in:\nSQL Instance install date, formatted as a string\nHosting Windows server install date, formatted as a string", "Tags": "CIM", "Author": "Mitchell Hamann (@SirCaptainMitch), mitchellhamann.com", "Synopsis": "Returns the install date of a SQL Instance and Windows Server, depending on what is passed.", "Name": "Get-DbaServerInstallDate", "Links": "https://dbatools.io/Get-DbaServerInstallDate", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerInstallDate -SqlInstance SqlBox1\\Instance2\r\n\r\nReturns an object with SQL Instance Install date as a string and the Windows install date as string.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerInstallDate -SqlInstance winserver\\sqlexpress, sql2016\r\n\r\nReturns an object with SQL Instance Install date as a string and the Windows install date as a string for both \r\nSQLInstances that are passed to the cmdlet.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerInstallDate -SqlInstance sqlserver2014a, sql2016\r\n\r\nReturns an object with only the SQL Server Install date as a string.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerInstallDate -SqlInstance sqlserver2014a, sql2016 -IncludeWindows\r\n\r\nReturns an object with the Windows Install date and the SQL install date as a string.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2014 | Get-DbaServerInstallDate\r\n\r\nReturns an object with SQL Instance install date as a string for every server listed in the Central Management Server \r\non sql2014\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaServerProtocol", "Description": "Gets the SQL Server related server protocols on one or more computers.\n\nRequires Local Admin rights on destination computer(s).\nThe server protocols can be enabled and disabled when retrieved via WSMan.", "Tags": "Protocol", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Gets the SQL Server related server protocols on a computer.", "Name": "Get-DbaServerProtocol", "Links": "https://dbatools.io/Get-DbaServerProtocol", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerProtocol -ComputerName sqlserver2014a\r\n\r\nGets the SQL Server related server protocols on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027 | Get-DbaServerProtocol\r\n\r\nGets the SQL Server related server protocols on computers sql1, sql2 and sql3.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaServerProtocol -ComputerName sql1,sql2 | Out-Gridview\r\n\r\nGets the SQL Server related server protocols on computers sql1 and sql2, and shows them in a grid view.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e(Get-DbaServerProtocol -ComputerName sql1 | Where { $_.DisplayName = \u0027via\u0027 }).Disable()\r\n\r\nDisables the VIA ServerNetworkProtocol on computer sql1.\r\nIf succesfull, returncode 0 is shown.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSpConfigure", "Description": "This function returns server level system configuration (sys.configuration/sp_configure) information. The information is gathered through SMO Configuration.Properties.\nThe data includes the default value for each configuration, for quick identification of values that may have been changed.", "Author": "Nic Cain, https://sirsql.net/", "Synopsis": "Returns all server level system configuration (sys.configuration/sp_configure) information", "Name": "Get-DbaSpConfigure", "Links": "https://dbatools.io/Get-DbaSpConfigure", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSpConfigure -SqlInstance localhost\r\n\r\nReturns server level configuration data on the localhost (ServerName, ConfigName, DisplayName, Description, IsAdvanced, \r\nIsDynamic, MinValue, MaxValue, ConfiguredValue, RunningValue, DefaultValue, IsRunningDefaultValue)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027localhost\u0027,\u0027localhost\\namedinstance\u0027 | Get-DbaSpConfigure\r\n\r\nReturns system configuration information on multiple instances piped into the function\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSpConfigure -SqlInstance localhost\r\n\r\nReturns server level configuration data on the localhost (ServerName, ConfigName, DisplayName, Description, IsAdvanced, \r\nIsDynamic, MinValue, MaxValue, ConfiguredValue, RunningValue, DefaultValue, IsRunningDefaultValue)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSpConfigure -SqlInstance sql2012 -ConfigName MaxServerMemory\r\n\r\nReturns only the system configuration for MaxServerMemory. Configs is auto-populated for tabbing convenience.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSpn", "Description": "Get a list of set SPNs. SPNs are set at the AD account level. You can either retrieve set SPNs for a computer, or any SPNs set for\na given active directry account. You can query one, or both. You\u0027ll get a list of every SPN found for either search term.", "Tags": "SPN", "Author": "Drew Furgiuele (@pittfurg), http://www.port1433.com", "Synopsis": "Returns a list of set service principal names for a given computer/AD account", "Name": "Get-DbaSpn", "Links": "https://dbatools.io/Get-DbaSpn", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSpn -ServerName SQLSERVERA -Credential (Get-Credential)\r\n\r\nReturns a custom object with SearchTerm (ServerName) and the SPNs that were found\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSpn -AccountName domain\\account -Credential (Get-Credential)\r\n\r\nReturns a custom object with SearchTerm (domain account) and the SPNs that were found\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSpn -ServerName SQLSERVERA,SQLSERVERB -Credential (Get-Credential)\r\n\r\nReturns a custom object with SearchTerm (ServerName) and the SPNs that were found for multiple computers\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlBuildReference", "Description": "Returns info about the specific build of a SQL instance, including the SP, the CU and the reference KB, wherever possible.\nIt also includes End Of Support dates as specified on Microsoft Lifecycle Policy", "Tags": "SqlBuild", "Author": "niphlod", "Synopsis": "Returns SQL Server Build infos on a SQL instance", "Name": "Get-DbaSqlBuildReference", "Links": "https://dbatools.io/Get-DbaSqlBuildReference", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlBuildReference -Build \"12.00.4502\"\r\n\r\nReturns information about a build identified by \"12.00.4502\" (which is SQL 2014 with SP1 and CU11)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlBuildReference -Build \"12.00.4502\" -Update\r\n\r\nReturns information about a build trying to fetch the most up to date index online. When the online version is newer, \r\nthe local one gets overwritten\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlBuildReference -Build \"12.0.4502\",\"10.50.4260\"\r\n\r\nReturns information builds identified by these versions strings\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sqlserver2014a | Get-DbaSqlBuildReference\r\n\r\nIntegrate with other commandlets to have builds checked for all your registered servers on sqlserver2014a\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlInstanceProperty", "Description": "The Get-DbaSqlInstanceProperty command gets SQL Instance properties from the SMO object sqlserver.", "Author": "Klaas Vandenberghe (@powerdbaklaas)", "Synopsis": "Gets SQL Instance properties of one or more instance(s) of SQL Server.", "Name": "Get-DbaSqlInstanceProperty", "Links": "https://dbatools.io/Get-DbaSqlInstanceProperty", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlInstanceProperty -SqlInstance localhost\r\n\r\nReturns SQL Instance properties on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlInstanceProperty -SqlInstance sql2, sql4\\sqlexpress\r\n\r\nReturns SQL Instance properties on default instance on sql2 and sqlexpress instance on sql4\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql2\u0027,\u0027sql4\u0027 | Get-DbaSqlInstanceProperty\r\n\r\nReturns SQL Instance properties on sql2 and sql4\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlInstanceUserOption", "Description": "The Get-DbaSqlInstanceUserOption command gets SQL Instance user options from the SMO object sqlserver.", "Author": "Klaas Vandenberghe (@powerdbaklaas)", "Synopsis": "Gets SQL Instance user options of one or more instance(s) of SQL Server.", "Name": "Get-DbaSqlInstanceUserOption", "Links": "https://dbatools.io/Get-DbaSqlInstanceUserOption", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlInstanceUserOption -SqlInstance localhost\r\n\r\nReturns SQL Instance user options on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlInstanceUserOption -SqlInstance sql2, sql4\\sqlexpress\r\n\r\nReturns SQL Instance user options on default instance on sql2 and sqlexpress instance on sql4\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql2\u0027,\u0027sql4\u0027 | Get-DbaSqlInstanceUserOption\r\n\r\nReturns SQL Instance user options on sql2 and sql4\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlLog", "Description": "Gets the \"SQL Error Log\" of an instance. Returns all 10 error logs by default.", "Tags": "Logging", "Synopsis": "Gets the \"SQL Error Log\" of an instance", "Name": "Get-DbaSqlLog", "Links": "https://dbatools.io/Get-DbaSqlLog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlLog -SqlInstance sql01\\sharepoint\r\n\r\nReturns every log entry from sql01\\sharepoint SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlLog -SqlInstance sql01\\sharepoint -LogNumber 3, 6\r\n\r\nReturns all log entries for log number 3 and 6 on sql01\\sharepoint SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlLog -SqlInstance sql01\\sharepoint -Source Logon\r\n\r\nReturns every log entry, with a source of Logon, from sql01\\sharepoint SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlLog -SqlInstance sql01\\sharepoint -LogNumber 3 -Text \"login failed\"\r\n\r\nReturns every log entry for log number 3, with \"login failed\" in the text, from sql01\\sharepoint SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$servers = \"sql2014\",\"sql2016\", \"sqlcluster\\sharepoint\"\r\n\r\n$servers | Get-DbaSqlLog -LogNumber 0\r\n\r\nReturns the most recent SQL Server error logs for \"sql2014\",\"sql2016\" and \"sqlcluster\\sharepoint\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlLog -SqlInstance sql01\\sharepoint -After \u002711/14/2006 00:00\u0027\r\n\r\nReturns every log entry found after the date 11/14/2006 00:00 from sql101\\sharepoint SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlLog -SqlInstance sql01\\sharepoint -Before \u002708/16/2016 00:00\u0027\r\n\r\nReturns every log entry found before the date 08/16/2016 00:00 from sql101\\sharepoint SQL Server instance.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlManagementObject", "Description": "The Get-DbaSqlManagementObject returns an object with the Version and the \nAdd-Type Load Template for each version on the server.", "Tags": "SMO", "Author": "Ben Miller (@DBAduck - http://dbaduck.com)", "Synopsis": "Gets SQL Mangaement Object versions installed on the machine.", "Name": "Get-DbaSqlManagementObject", "Links": "https://dbatools.io/Get-DbaSqlManagementObject", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlManagementObject\r\n\r\nReturns all versions of SMO on the computer\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlManagementObject -VersionNumber 13\r\n\r\nReturns just the version specified. If the version does not exist then it will return nothing.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlModule", "Description": "Quickly find modules (Stored Procs, Functions, Views, Constraints, Rules, Triggers, etc) that have been modified in a database, or across all databases.\nResults will exclude the module definition, but can be queried explicitly.", "Tags": [ "StoredProcedure", "Trigger" ], "Author": "Brandon Abshire, netnerds.net", "Synopsis": "Displays all objects in sys.sys_modules after specified modification date. Works on SQL Server 2008 and above.", "Name": "Get-DbaSqlModule", "Links": "https://dbatools.io/Get-DbaSqlModule", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlModule -SqlServer sql2008, sqlserver2012\r\n\r\nReturn all modules for servers sql2008 and sqlserver2012 sorted by Database, Modify_Date ASC.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlModule -SqlServer sql2008, sqlserver2012 | Select *\r\n\r\nShows hidden definition column (informative wall of text).\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlModule -SqlServer sql2008 -Database TestDB -ModifiedSince \"01/01/2017 10:00:00 AM\"\r\n\r\nReturn all modules on server sql2008 for only the TestDB database with a modified date after 01/01/2017 10:00:00 AM.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlModule -SqlServer sql2008 -Type View, Trigger, ScalarFunction\r\n\r\nReturn all modules on server sql2008 for all databases that are triggers, views or scalar functions.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlProductKey", "Description": "Using a string of servers, a text file, or Central Management Server to provide a list of servers, this script will go to each server and get the product key for all installed instances. Clustered instances are supported as well. Requires regular user access to the SQL instances, SMO installed locally, Remote Registry enabled and accessible by the account running the script.\n\nUses key decoder by Jakob Bindslet (http://goo.gl/1jiwcB)", "Tags": [ "SQL", "Product Key" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Gets SQL Server Product Keys from local or destination SQL Servers. Works with SQL Server 2005-2016", "Name": "Get-DbaSqlProductKey", "Links": "https://dbatools.io/Get-DbaSqlProductKey", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlProductKey winxp, sqlservera, sqlserver2014a, win2k8\r\n\r\nGets SQL Server versions, editions and product keys for all instances within each server or workstation.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlProductKey -SqlCms sqlserver01\r\n\r\nGets SQL Server versions, editions and product keys for all instances within sqlserver01\u0027s Central Management Server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlProductKey -ServersFromFile C:\\Scripts\\servers.txt\r\n\r\nGets SQL Server versions, editions and product keys for all instances listed within C:\\Scripts\\servers.txt\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlRegistryRoot", "Description": "Uses SQL WMI to find the Registry Root of each SQL Server instance on a computer", "Tags": [ "Configuration", "Registry" ], "Synopsis": "Uses SQL WMI to find the Registry Root of each SQL Server instance on a computer", "Name": "Get-DbaSqlRegistryRoot", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlRegistryRoot\r\n\r\nGets the registry root for all instances on localhost\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlRegistryRoot -ComputerName server1\r\n\r\nGets the registry root for all instances on server1\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSqlService", "Description": "Gets the SQL Server related services on one or more computers.\n\nRequires Local Admin rights on destination computer(s).", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Gets the SQL Server related services on a computer.", "Name": "Get-DbaSqlService", "Links": "https://dbatools.io/Get-DbaSqlService", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlService -ComputerName sqlserver2014a\r\n\r\nGets the SQL Server related services on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027 | Get-DbaSqlService\r\n\r\nGets the SQL Server related services on computers sql1, sql2 and sql3.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlService -ComputerName sql1,sql2 | Out-Gridview\r\n\r\nGets the SQL Server related services on computers sql1 and sql2, and shows them in a grid view.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSqlService -ComputerName $MyServers -Type SSRS\r\n\r\nGets the SQL Server related services of type \"SSRS\" (Reporting Services) on computers in the variable MyServers.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$services = Get-DbaSqlService -ComputerName sql1 -Type Agent,Engine\r\n\r\n$services.ChangeStartMode(\u0027Manual\u0027)\r\n\r\nGets the SQL Server related services of types Sql Agent and DB Engine on computer sql1 and changes their startup mode \r\nto \u0027Manual\u0027.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e(Get-DbaSqlService sql1 -Type Engine).Restart($true)\r\n\r\nCalls a Restart method for each Engine service on computer sql1 with -Force option.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaSsisEnvironmentVariable", "Description": "This command gets all variables from specified environment from SSIS Catalog. All sensitive values are decrypted.\nThe function communicates directly with SSISDB database, \"SQL Server Integration Services\" service isn\u0027t queried there.\nEach parameter (besides SqlInstance and SqlCredential) acts as the filter to only include or exclude particular element", "Author": "Bartosz Ratajczyk ( @b_ratajczyk )", "Synopsis": "This command gets specified SSIS Environment and all its variables", "Name": "Get-DbaSsisEnvironmentVariable", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSsisEnvironmentVariable -SqlInstance localhost -Environment DEV -Folder DWH_ETL\r\n\r\nGets variables of \u0027DEV\u0027 environment located in \u0027DWH_ETL\u0027 folder on \u0027localhost\u0027 Server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSsisEnvironmentVariable -SqlInstance localhost -Environment DEV -Folder DWH_ETL, DEV2, QA\r\n\r\nGets variables of \u0027DEV\u0027 environment(s) located in folders \u0027DWH_ETL\u0027, \u0027DEV2\u0027 and \u0027QA\u0027 on \u0027localhost\u0027 server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSsisEnvironmentVariable -SqlInstance localhost -Environment DEV -FolderExclude DWH_ETL, DEV2, QA\r\n\r\nGets variables of \u0027DEV\u0027 environments located in folders other than \u0027DWH_ETL\u0027, \u0027DEV2\u0027 and \u0027QA\u0027 on \u0027localhost\u0027 server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSsisEnvironmentVariable -SqlInstance localhost -Environment DEV, PROD -Folder DWH_ETL, DEV2, QA\r\n\r\nGets variables of \u0027DEV\u0027 and \u0027PROD\u0027 environment(s) located in folders \u0027DWH_ETL\u0027, \u0027DEV2\u0027 and \u0027QA\u0027 on \u0027localhost\u0027 server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSsisEnvironmentVariable -SqlInstance localhost -EnvironmentExclude DEV, PROD -Folder DWH_ETL, DEV2, QA\r\n\r\nGets variables of environments other than \u0027DEV\u0027 and \u0027PROD\u0027 located in folders \u0027DWH_ETL\u0027, \u0027DEV2\u0027 and \u0027QA\u0027 on \u0027localhost\u0027 \r\nserver\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaSsisEnvironmentVariable -SqlInstance localhost -EnvironmentExclude DEV, PROD -FolderExclude DWH_ETL, \r\nDEV2, QA\r\n\r\nGets variables of environments other than \u0027DEV\u0027 and \u0027PROD\u0027 located in folders other than \u0027DWH_ETL\u0027, \u0027DEV2\u0027 and \u0027QA\u0027 on \r\n\u0027localhost\u0027 server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e\u0027localhost\u0027 | Get-DbaSsisEnvironmentVariable -EnvironmentExclude DEV, PROD\r\n\r\nGets all SSIS environments except \u0027DEV\u0027 and \u0027PROD\u0027 from \u0027localhost\u0027 server. The server name comes from pipeline\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003e\u0027SRV1\u0027, \u0027SRV3\u0027 | Get-DbaSsisEnvironmentVariable\r\n\r\nGets all SSIS environments from \u0027SRV1\u0027 and \u0027SRV3\u0027 servers. The server\u0027s names come from pipeline\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003e\u0027SRV1\u0027, \u0027SRV2\u0027 | Get-DbaSsisEnvironmentVariable DEV | Out-GridView\r\n\r\nGets all variables from \u0027DEV\u0027 Environment(s) on servers \u0027SRV1\u0027 and \u0027SRV2\u0027 and outputs it as the GridView. \r\nThe server names come from the pipeline.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 10 --------------------------\r\n\r\nPS C:\\\u003e\u0027localhost\u0027 | Get-DbaSsisEnvironmentVariable -EnvironmentExclude DEV, PROD | Select-Object -Property Name, Value \r\n| Where-Object {$_.Name -match \u0027^a\u0027} | Out-GridView\r\n\r\nGets all variables from Environments other than \u0027DEV\u0027 and \u0027PROD\u0027 on \u0027localhost\u0027 server, \r\nselects Name and Value properties for variables that names start with letter \u0027a\u0027 and outputs it as the GridView\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaStartupParameter", "Description": "Displays values for a detailed list of SQL Server Startup Parameters including Master Data Path, Master Log path, Error Log, Trace Flags, Parameter String and much more.\n\nThis command relies on remote Windows Server (SQL WMI/WinRm) access. You can pass alternative Windows credentials by using the -Credential parameter.\n\nSee https://msdn.microsoft.com/en-us/library/ms190737.aspx for more information.", "Tags": [ "WSMan", "SQLWMI", "Memory" ], "Synopsis": "Displays values for a detailed list of SQL Server Startup Parameters.", "Name": "Get-DbaStartupParameter", "Links": "https://dbatools.io/Get-DbaStartupParameter", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaStartupParameter -SqlInstance sql2014\r\n\r\nLogs into SQL WMI as the current user then displays the values for numerous startup parameters.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$wincred = Get-Credential ad\\sqladmin\r\n\r\nGet-DbaStartupParameter -SqlInstance sql2014 -Credential $wincred -Simple\r\n\r\nLogs in to WMI using the ad\\sqladmin credential and gathers simplified information about the SQL Server Startup \r\nParameters.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaTable", "Description": "Shows table information around table row and data sizes and if it has any table type information.", "Tags": [ "Database", "Tables" ], "Author": "Stephen Bennett, https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Returns a summary of information on the tables", "Name": "Get-DbaTable", "Links": "https://dbatools.io/Get-DbaTable", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTable -SqlInstance DEV01 -Database Test1\r\n\r\nReturn all tables in the Test1 database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTable -SqlInstance DEV01 -Database MyDB -Table MyTable\r\n\r\nReturn only information on the table MyTable from the database MyDB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTable -SqlInstance DEV01 -Table MyTable\r\n\r\nReturns information on table called MyTable if it exists in any database on the server, under any schema\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTable -SqlInstance DEV01 -Table dbo.[First.Table]\r\n\r\nReturns information on table called First.Table on schema dbo if it exists in any database on the server\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e\u0027localhost\u0027,\u0027localhost\\namedinstance\u0027 | Get-DbaTable -Database DBA -Table Commandlog\r\n\r\nReturns information on the CommandLog table in the DBA database on both instances localhost and the named instance \r\nlocalhost\\namedinstance\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaTcpPort", "Description": "By default, this command returns just the TCP port used by the specified SQL Server.\n\nIf -Detailed is specified, server name, IPAddress (ipv4 and ipv6), port number and if the port assignment is static.", "Tags": [ "SQLWMI", "tcp" ], "Synopsis": "Returns the TCP port used by the specified SQL Server.", "Name": "Get-DbaTcpPort", "Links": "https://dbatools.io/Get-DbaTcpPort", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTcpPort -SqlInstance sqlserver2014a\r\n\r\nReturns just the port number for the default instance on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTcpPort -SqlInstance winserver\\sqlexpress, sql2016\r\n\r\nReturns an object with server name and port number for the sqlexpress on winserver and the default instance on sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTcpPort -SqlInstance sqlserver2014a, sql2016 -Detailed\r\n\r\nReturns an object with server name, IPAddress (ipv4 and ipv6), port and static ($true/$false) for sqlserver2014a and \r\nsql2016\r\n\r\nRemote sqlwmi is used by default. If this doesn\u0027t work, then remoting is used. If neither work, it defaults to T-SQL \r\nwhich can provide only the port.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2014 | Get-DbaTcpPort -ExcludeIpv6 -Detailed\r\n\r\nReturns an object with server name, IPAddress (just ipv4), port and static ($true/$false) for every server listed in \r\nthe Central Management Server on sql2014\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaTempdbUsage", "Description": "This function queries DMVs for running sessions using Tempdb and returns results if those sessions have user or internal space allocated or deallocated against them.", "Synopsis": "Gets Tempdb usage for running queries.", "Name": "Get-DbaTempdbUsage", "Links": "https://dbatools.io/Get-DbaTempdbUsage", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTempdbUsage -SqlInstance localhost\\SQLDEV2K14\r\n\r\nGets tempdb usage for localhost\\SQLDEV2K14\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbatoolsLog", "Description": "Returns log entries for dbatools. Handy when debugging or developing for it. Also used when preparing a support package.", "Tags": "Debug", "Author": "Fred Weinmann (@FredWeinmann)", "Synopsis": "Returns log entries for dbatools", "Name": "Get-DbatoolsLog", "Links": "https://dbatools.io/Get-DbatoolsLog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbatoolsLog\r\n\r\nReturns all log entries currently in memory.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaTraceFile", "Description": "This function returns a list of Trace Files on a SQL Server Instance and identify the default Trace File", "Tags": [ "Security", "Trace" ], "Author": "Garry Bargsley (@gbargsley), http://blog.garrybargsley.com", "Synopsis": "Gets a list of trace file(s) from specied SQL Server Instance", "Name": "Get-DbaTraceFile", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTraceFile -SqlInstance sql2016\r\n\r\nLists all the tracefiles on the sql2016 SQL Server.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTraceFile -SqlInstance sql2016 -Default\r\n\r\nLists the default trace information on the sql2016 SQL Server.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaTraceFlag", "Description": "Returns Trace Flags that are enabled globally on each instance(s) of SQL Server as an object.", "Tags": [ "Trace", "Flag" ], "Author": "Kevin Bullen (@sqlpadawan)", "Synopsis": "Get global Trace Flag(s) information for each instance(s) of SQL Server.", "Name": "Get-DbaTraceFlag", "Links": "https://dbatools.io/Get-DbaTraceFlag", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTraceFlag -SqlInstance localhost\r\n\r\nReturns all Trace Flag information on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTraceFlag -SqlInstance localhost, sql2016\r\n\r\nReturns all Trace Flag(s) for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTraceFlag -SqlInstance localhost -TraceFlag 4199,3205\r\n\r\nReturns Trace Flag status for TF 4199 and 3205 for the local SQL Server instance if they are enabled.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaTrigger", "Description": "Get all existing triggers on one or more SQL instances.\n\nDefault output includes columns ComputerName, SqlInstance, Database, TriggerName, IsEnabled and DateLastModified.", "Tags": [ "Database", "Triggers" ], "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Get all existing triggers on one or more SQL instances.", "Name": "Get-DbaTrigger", "Links": "https://dbatools.io/Get-DbaTrigger", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTrigger -SqlInstance ComputerA\\sql987\r\n\r\nReturns a custom object displaying ComputerName, SqlInstance, Database, TriggerName, IsEnabled and DateLastModified.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTrigger -SqlInstance \u0027ComputerA\\sql987\u0027,\u0027ComputerB\u0027\r\n\r\nReturns a custom object displaying ComputerName, SqlInstance, Database, TriggerName, IsEnabled and DateLastModified \r\nfrom two instances.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaTrigger -SqlInstance ComputerA\\sql987 | Out-Gridview\r\n\r\nReturns a gridview displaying ComputerName, SqlInstance, Database, TriggerName, IsEnabled and DateLastModified.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e\u0027ComputerA\\sql987\u0027,\u0027ComputerB\u0027 | Get-DbaTrigger | Out-Gridview\r\n\r\nReturns a custom object displaying ComputerName, SqlInstance, Database, TriggerName, IsEnabled and DateLastModified \r\nfrom two instances.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaUptime", "Description": "By default, this command returns for each SQL Server instance passed in:\nSQL Instance last startup time, Uptime as a PS TimeSpan, Uptime as a formatted string\nHosting Windows server last startup time, Uptime as a PS TimeSpan, Uptime as a formatted string", "Tags": "CIM", "Author": "Stuart Moore (@napalmgram), stuart-moore.com", "Synopsis": "Returns the uptime of the SQL Server instance, and if required the hosting windows server", "Name": "Get-DbaUptime", "Links": "https://dbatools.io/Get-DbaUptime", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaUptime -SqlInstance SqlBox1\\Instance2\r\n\r\nReturns an object with SQL Server start time, uptime as TimeSpan object, uptime as a string, and Windows host boot \r\ntime, host uptime as TimeSpan objects and host uptime as a string for the sqlexpress instance on winserver\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaUptime -SqlInstance winserver\\sqlexpress, sql2016\r\n\r\nReturns an object with SQL Server start time, uptime as TimeSpan object, uptime as a string, and Windows host boot \r\ntime, host uptime as TimeSpan objects and host uptime as a string for the sqlexpress instance on host winserver and \r\nthe default instance on host sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2014 | Get-DbaUptime\r\n\r\nReturns an object with SQL Server start time, uptime as TimeSpan object, uptime as a string, and Windows host boot \r\ntime, host uptime as TimeSpan objects and host uptime as a string for every server listed in the Central Management \r\nServer on sql2014\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaUserLevelPermission", "Description": "This command will display all server logins, server level securable, database logins and database securables.\n\nDISA STIG implementators will find this command useful as it uses Permissions.sql provided by DISA.\n\nNote that if you Ctrl-C out of this command and end it prematurely, it will leave behind a STIG schema in tempdb.", "Tags": [ "Discovery", "Permissions", "Security" ], "Author": "Brandon Abshire, netnerds.net", "Synopsis": "Displays detailed permissions information for the server and database roles and securables.", "Name": "Get-DbaUserLevelPermission", "Links": "https://dbatools.io/Get-DbaUserLevelPermission", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaUserLevelPermission -SqlInstance sql2008, sqlserver2012\r\n\r\nCheck server and database permissions for servers sql2008 and sqlserver2012.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaUserLevelPermission -SqlInstance sql2008 -Database TestDB\r\n\r\nCheck server and database permissions on server sql2008 for only the TestDB database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaUserLevelPermission -SqlInstance sql2008 -Database TestDB -IncludePublicGuest -IncludeSystemObjects\r\n\r\nCheck server and database permissions on server sql2008 for only the TestDB database,\r\n including public and guest grants, and sys schema objects.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaWaitStatistic", "Description": "This command is based off of Paul Randal\u0027s post \"Wait statistics, or please tell me where it hurts\"\n\nReturns: WaitType\n\t\t\tCategory\n\t\t\tWaitSeconds\n\t\t\tResourceSeconds\n\t\t\tSignalSeconds\n\t\t\tWaitCount\n\t\t\tPercentage\n\t\t\tAverageWaitSeconds\n\t\t\tAverageResourceSeconds\n\t\t\tAverageSignalSeconds\n\t\t\tURL\n\nReference: https://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-it-hurts/", "Tags": "WaitStatistic", "Synopsis": "Displays wait statistics", "Name": "Get-DbaWaitStatistic", "Links": "https://dbatools.io/Get-DbaWaitStatistic", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaWaitStatistic -SqlInstance sql2008, sqlserver2012\r\n\r\nCheck wait statistics for servers sql2008 and sqlserver2012\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaWaitStatistic -SqlInstance sql2008 -Threshold 98\r\n\r\nCheck wait statistics on server sql2008 for thresholds above 98%\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaWaitStatistic -SqlInstance sql2008 | Select *\r\n\r\nShows detailed notes, if available, from Paul\u0027s post\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$output = Get-DbaWaitStatistic -SqlInstance sql2008\r\n\r\n$output\r\nforeach ($row in ($output | Sort-Object -Unique Url)) { Start-Process ($row).Url }\r\n\r\nDisplays the output then loads the associated sqlskills website for each result. Opens one tab per unique URL.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaWindowsLog", "Description": "Gets Windows Application events associated with an instance", "Tags": "Logging", "Author": "Drew Furgiuele", "Synopsis": "Gets Windows Application events associated with an instance", "Name": "Get-DbaWindowsLog", "Links": "https://dbatools.io/Get-DbaWindowsLog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003e$ErrorLogs = Get-DbaWindowsLog -SqlInstance sql01\\sharepoint\r\n\r\n$ErrorLogs | Where-Object ErrorNumber -eq 18456\r\n\r\nReturns all lines in the errorlogs that have event number 18456 in them\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaXEventsSession", "Description": "Retrieves a list of Extended Events Sessions", "Tags": "Memory", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Get a list of Extended Events Sessions", "Name": "Get-DbaXEventsSession", "Links": "https://dbatools.io/Get-DbaXEventsSession", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaXEventsSession -SqlInstance ServerA\\sql987\r\n\r\nReturns a custom object with ComputerName, SQLInstance, Session, StartTime, Status and other properties.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaXEventsSession -SqlInstance ServerA\\sql987 | Format-Table ComputerName, SQLInstance, Session, Status \r\n-AutoSize\r\n\r\nReturns a formatted table displaying ComputerName, SQLInstance, Session, and Status.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e\u0027ServerA\\sql987\u0027,\u0027ServerB\u0027 | Get-DbaXEventsSession\r\n\r\nReturns a custom object with ComputerName, SQLInstance, Session, StartTime, Status and other properties, from multiple \r\nSQL Instances.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Import-DbaCsvToSql", "Description": "Import-DbaCsvToSql takes advantage of .NET\u0027s super fast SqlBulkCopy class to import CSV files into SQL Server at up to 90,000 rows a second.\n\nThe entire import is contained within a transaction, so if a failure occurs or the script is aborted, no changes will persist.\n\nIf the table specified does not exist, it will be automatically created using best guessed data types. In addition, the destination table can be truncated prior to import. \n\nThe Query parameter will be used to import only the data returned from a SQL Query executed against the CSV file(s). This function supports a number of bulk copy options. Please see parameter list for details.", "Tags": "Migration", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Efficiently imports very large (and small) CSV files into SQL Server using only the .NET Framework and PowerShell.", "Name": "Import-DbaCsvToSql", "Links": "https://blog.netnerds.net/2015/09/Import-DbaCsvtosql-super-fast-csv-to-sql-server-import-powershell-module/", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eImport-DbaCsvToSql -Csv C:\\temp\\housing.csv -SqlInstance sql001 -Database markets\r\n\r\nImports the entire comma-delimited housing.csv to the SQL \"markets\" database on a SQL Server named sql001.\r\n\r\nSince a table name was not specified, the table name is automatically determined from filename as \"housing\" and a \r\nprompt will appear to confirm table name.\r\n\r\nThe first row is not skipped, as it does not contain column names.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eImport-DbaCsvToSql -Csv .\\housing.csv -SqlInstance sql001 -Database markets -Table housing -First 100000 -Safe \r\n-Delimiter \"`t\" -FirstRowColumns\r\n\r\nImports the first 100,000 rows of the tab delimited housing.csv file to the \"housing\" table in the \"markets\" database \r\non a SQL Server named sql001. Since -Safe was specified, the OleDB method will be used for the bulk import. The first \r\nrow is skipped, as it contains column names.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eImport-DbaCsvToSql -csv C:\\temp\\huge.txt -SqlInstance sqlcluster -Database locations -Table latitudes -Delimiter \r\n\"|\" -Turbo\r\n\r\nImports all records from the pipe delimited huge.txt file using the fastest method possible into the latitudes table \r\nwithin the locations database. Obtains a table lock for the duration of the bulk copy operation. This specific command \r\nhas been used \r\nto import over 10.5 million rows in 2 minutes.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eImport-DbaCsvToSql -Csv C:\\temp\\housing.csv, .\\housing2.csv -SqlInstance sql001 -Database markets -Table housing \r\n-Delimiter \"`t\" -query \"select top 100000 column1, column3 from csv\" -Truncate\r\n\r\nTruncates the \"housing\" table, then imports columns 1 and 3 of the first 100000 rows of the tab-delimited housing.csv \r\nin the C:\\temp directory, and housing2.csv in the current directory. Since the query is executed against both files, a \r\ntotal of 200,000 rows will be imported.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eImport-DbaCsvToSql -Csv C:\\temp\\housing.csv -SqlInstance sql001 -Database markets -Table housing -query \"select \r\naddress, zip from csv where state = \u0027Louisiana\u0027\" -FirstRowColumns -Truncate -FireTriggers\r\n\r\nUses the first line to determine CSV column names. Truncates the \"housing\" table on the SQL Server, then imports the \r\naddress and zip columns from all records in the housing.csv where the state equals Louisiana.\r\n\r\nTriggers are fired for all rows. Note that this does slightly slow down the import.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Import-DbaSpConfigure", "Description": "Updates sp_configure settings on destination server.", "Synopsis": "Updates sp_configure settings on destination server.", "Name": "Import-DbaSpConfigure", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eImport-DbaSpConfigure sqlserver sqlcluster $SourceSqlCredential $DestinationSqlCredential\r\n\r\nImports the sp_configure settings from the source server sqlserver and sets them on the sqlcluster server\r\nusing the SQL credentials stored in the variables\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eImport-DbaSpConfigure -SqlInstance sqlserver -Path .\\spconfig.sql -SqlCredential $SqlCredential\r\n\r\nImports the sp_configure settings from the file .\\spconfig.sql and sets them on the sqlcluster server\r\nusing the SQL credential stored in the variables\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Install-DbaFirstResponderKit", "Description": "Downloads, extracts and installs the First Responder Kit stored procedures: \nsp_Blitz, sp_BlitzWho, sp_BlitzFirst, sp_BlitzIndex, sp_BlitzCache and sp_BlitzTrace. \n\nFirst Responder Kit links:\nhttp://FirstResponderKit.org\nhttps://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit", "Author": "Tara Kizer, Brent Ozar Unlimited (https://www.brentozar.com/)", "Synopsis": "Installs or updates the First Responder Kit stored procedures.", "Name": "Install-DbaFirstResponderKit", "Links": "https://dbatools.io/Install-DbaFirstResponderKit", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaFirstResponderKit -SqlInstance server1 -Database master\r\n\r\nLogs into server1 with Windows authentication and then installs the FRK in the master database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaFirstResponderKit -SqlInstance server1\\instance1 -Database DBA\r\n\r\nLogs into server1\\instance1 with Windows authentication and then installs the FRK in the DBA database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaFirstResponderKit -SqlInstance server1\\instance1 -Database master -SqlCredential $cred\r\n\r\nLogs into server1\\instance1 with SQL authentication and then installs the FRK in the master database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaFirstResponderKit -SqlInstance sql2016\\standardrtm, sql2016\\sqlexpress, sql2014\r\n\r\nLogs into sql2016\\standardrtm, sql2016\\sqlexpress and sql2014 with Windows authentication and then installs the FRK in \r\nthe master database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$servers = \"sql2016\\standardrtm\", \"sql2016\\sqlexpress\", \"sql2014\"\r\n\r\n$servers | Install-DbaFirstResponderKit\r\n\r\nLogs into sql2016\\standardrtm, sql2016\\sqlexpress and sql2014 with Windows authentication and then installs the FRK in \r\nthe master database.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Install-DbaMaintenanceSolution", "Description": "This script will download and install the latest version of SQL Server Maintenance Solution created by Ola Hallengren", "Author": "Viorel Ciucu, viorel.ciucu@gmail.com, cviorel.com", "Synopsis": "Download and Install SQL Server Maintenance Solution created by Ola Hallengren (https://ola.hallengren.com)", "Name": "Install-DbaMaintenanceSolution", "Links": "http://dbatools.io/Install-DbaMaintenanceSolution", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -CleanupTime 72\r\n\r\nInstalls Ola Hallengren\u0027s Solution objects on RES14224 in the master database. \r\nBackups will default to the default Backup Directory. \r\nIf the Maintenance Solution already exists, the script will be halted.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -ReplaceExisting -CleanupTime 72 -LogToTable \r\n-Solution \"Backup\" -BackupLocation \"Z:\\SQLBackup\" -InstallJobs\r\n\r\n\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -BackupLocation \"Z:\\SQLBackup\" -CleanupTime 72\r\n\r\nThis will create the Ola Hallengren\u0027s Solution objects. Existing objects are not affected in any way.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -BackupLocation \"Z:\\SQLBackup\" -CleanupTime \r\n72 -ReplaceExisting\r\n\r\nThis will drop and then recreate the Ola Hallengren\u0027s Solution objects\r\nThe cleanup script will drop and recreate:\r\n - TABLE [dbo].[CommandLog]\r\n - STORED PROCEDURE [dbo].[CommandExecute]\r\n - STORED PROCEDURE [dbo].[DatabaseBackup]\r\n - STORED PROCEDURE [dbo].[DatabaseIntegrityCheck]\r\n - STORED PROCEDURE [dbo].[IndexOptimize]\r\n\r\nThe follwing SQL Agent jobs will be deleted:\r\n - \u0027Output File Cleanup\u0027\r\n - \u0027IndexOptimize - USER_DATABASES\u0027\r\n - \u0027sp_delete_backuphistory\u0027\r\n - \u0027DatabaseBackup - USER_DATABASES - LOG\u0027\r\n - \u0027DatabaseBackup - SYSTEM_DATABASES - FULL\u0027\r\n - \u0027DatabaseBackup - USER_DATABASES - FULL\u0027\r\n - \u0027sp_purge_jobhistory\u0027\r\n - \u0027DatabaseIntegrityCheck - SYSTEM_DATABASES\u0027\r\n - \u0027CommandLog Cleanup\u0027\r\n - \u0027DatabaseIntegrityCheck - USER_DATABASES\u0027\r\n - \u0027DatabaseBackup - USER_DATABASES - DIFF\u0027\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Install-DbaWatchUpdate", "Description": "Adds the scheduled task to support Watch-DbaUpdate.", "Tags": [ "JustForFun", "Module" ], "Synopsis": "Adds the scheduled task to support Watch-DbaUpdate", "Name": "Install-DbaWatchUpdate", "Links": "https://dbatools.io/Install-DbaWatchUpdate", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaWatchUpdate\r\n\r\nAdds the scheduled task needed by Watch-DbaUpdate\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Install-DbaWhoIsActive", "Description": "This command downloads, extracts and installs sp_WhoisActive with Adam\u0027s permission. To read more about sp_WhoisActive, please visit http://whoisactive.com and http://sqlblog.com/blogs/adam_machanic/archive/tags/who+is+active/default.aspx\n\nPlease consider donating to Adam if you find this stored procedure helpful: http://tinyurl.com/WhoIsActiveDonate\n\nNote that you will be prompted a bunch of times to confirm an action.", "Synopsis": "Automatically installs or updates sp_WhoisActive by Adam Machanic.", "Name": "Install-DbaWhoIsActive", "Links": "https://dbatools.io/Install-DbaWhoIsActive", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaWhoIsActive -SqlInstance sqlserver2014a -Database master\r\n\r\nDownloads sp_WhoisActive from the internet and installs to sqlserver2014a\u0027s master database. Connects to SQL Server \r\nusing Windows Authentication.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaWhoIsActive -SqlInstance sqlserver2014a -SqlCredential $cred\r\n\r\nPops up a dialog box asking which database on sqlserver2014a you want to install the procedure into. Connects to SQL \r\nServer using SQL Authentication.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInstall-DbaWhoIsActive -SqlInstance sqlserver2014a -Database master -LocalFile \r\nc:\\SQLAdmin\\whoisactive_install.sql\r\n\r\nInstalls sp_WhoisActive to sqlserver2014a\u0027s master database from the local file whoisactive_install.sql\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$instances = Get-DbaRegisteredServer sqlserver\r\n\r\nInstall-DbaWhoIsActive -SqlInstance $instances -Database master\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Invoke-DbaCycleErrorLog", "Description": "Cycles the current error log for the instance (SQL Server) and/or SQL Server Agent.", "Tags": [ "Log", "Cycle" ], "Author": "Shawn Melton (@wsmelton | http://blog.wsmelton.info)", "Synopsis": "Cycles the current instance or agent log.", "Name": "Invoke-DbaCycleErrorLog", "Links": "https://dbatools.io/Invoke-DbaCycleLog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaCycleLog -SqlInstance sql2016 -Type agent\r\n\r\nCycles the current error log for the SQL Server Agent on SQL Server instance sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaCycleLog -SqlInstance sql2016 -Type instance\r\n\r\nCycles the current error log for the SQL Server instance on SQL Server instance sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaCycleLog -SqlInstance sql2016\r\n\r\nCycles the current error log for both SQL Server instance and SQL Server Agent on SQL Server instance sql2016\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Invoke-DbaDatabaseShrink", "Description": "Shrinks all files in a database. Databases should be shrunk only when completely necessary.\n\nMany awesome SQL people have written about why you should not shrink your data files. Paul Randal and Kalen Delaney wrote great posts about this topic:\n\n\thttp://www.sqlskills.com/blogs/paul/why-you-should-not-shrink-your-data-files\n\thttp://sqlmag.com/sql-server/shrinking-data-files\n\nHowever, there are some cases where a database will need to be shrunk. In the event that you must shrink your database:\n\n1. Ensure you have plenty of space for your T-Log to grow\n2. Understand that shrinks require a lot of CPU and disk resources\n3. Consider running DBCC INDEXDEFRAG or ALTER INDEX ... REORGANIZE after the shrink is complete.", "Tags": [ "Shrink", "Databases" ], "Synopsis": "Shrinks all files in a database. This is a command that should rarely be used.\n\n- Shrinks can cause severe index fragmentation (to the tune of 99%)\n- Shrinks can cause massive growth in the database\u0027s transaction log\n- Shrinks can require a lot of time and system resources to perform data movement", "Name": "Invoke-DbaDatabaseShrink", "Links": "https://dbatools.io/Invoke-DbaDatabaseShrink", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDatabaseShrink -SqlInstance sql2016 -Database Northwind,pubs,Adventureworks2014\r\n\r\nShrinks Northwind, pubs and Adventureworks2014 to have as little free space as possible.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDatabaseShrink -SqlInstance sql2014 -Database Adventureworks2014 -PercentFreeSpace 50\r\n\r\nShrinks Adventureworks2014 to have 50% free space. So let\u0027s say Adventureworks2014 was 1GB and it\u0027s using 100MB space. \r\nThe database free space would be reduced to 50MB.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDatabaseShrink -SqlInstance sql2012 -AllUserDatabases\r\n\r\nShrinks all databases on SQL2012 (not ideal for production)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Invoke-DbaDatabaseUpgrade", "Description": "Updates compatibility level, then runs CHECKDB with data_purity, DBCC updateusage, sp_updatestats and finally sp_refreshview against all user views.", "Tags": [ "Shrink", "Databases" ], "Author": "Stephen Bennett, https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Take a database and upgrades it to compatibility of the SQL Instance its hosted on. Based on https://thomaslarock.com/2014/06/upgrading-to-sql-server-2014-a-dozen-things-to-check/", "Name": "Invoke-DbaDatabaseUpgrade", "Links": "https://dbatools.io/Invoke-DbaDatabaseUpgrade", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDatabaseUpgrade -SqlInstance PRD-SQL-MSD01 -Database Test\r\n\r\nRuns the below processes against the databases\r\n-- Puts compatibility of database to level of SQL Instance\r\n-- Runs CHECKDB DATA_PURITY\r\n-- Runs DBCC UPDATESUSAGE\r\n-- Updates all users statistics\r\n-- Runs sp_refreshview against every view in the database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDatabaseUpgrade -SqlInstance PRD-SQL-INT01 -Database Test -NoRefreshView\r\n\r\nRuns the upgrade command skipping the sp_refreshview update on all views\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDatabaseUpgrade -SqlInstance PRD-SQL-INT01 -Database Test -Force\r\n\r\nIf database Test is already at the correct compatibility, runs every necessary step\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance sql2016 | Out-GridView -Passthru | Invoke-DbaDatabaseUpgrade\r\n\r\nGet only specific databases using GridView and pass those to Invoke-DbaDatabaseUpgrade\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Invoke-DbaDiagnosticQuery", "Description": "This is the main function of the Sql Server Diagnostic Queries related functions in dbatools. \nThe diagnostic queries are developed and maintained by Glenn Berry and they can be found here along with a lot of documentation:\nhttp://www.sqlskills.com/blogs/glenn/category/dmv-queries/\n\nThe most recent version of the diagnostic queries are included in the dbatools module. \nBut it is possible to download a newer set or a specific version to an alternative location and parse and run those scripts.\nIt will run all or a selection of those scripts on one or multiple servers and return the result as a PowerShell Object", "Tags": [ "Database", "DMV" ], "Author": "André Kamman (@AndreKamman), http://clouddba.io", "Synopsis": "Invoke-DbaDiagnosticQuery runs the scripts provided by Glenn Berry\u0027s DMV scripts on specified servers", "Name": "Invoke-DbaDiagnosticQuery", "Links": "https://dbatools.io/Invoke-DbaDiagnosticQuery", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDiagnosticQuery -SqlInstance sql2016\r\n\r\nRun the selection made by the user on the Sql Server instance specified.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaDiagnosticQuery -SqlInstance sql2016 -UseSelectionHelper | Export-DbaDiagnosticQuery -Path \r\nC:\\temp\\gboutput\r\n\r\nProvides a gridview with all the queries to choose from and will run the selection made by the user on the SQL Server \r\ninstance specified. \r\n\t\r\nThen it will export the results to Export-DbaDiagnosticQuery.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Invoke-DbaLogShipping", "Description": "Invoke-DbaLogShipping helps to easily set up log shipping for one or more databases.\n\nThis function will make a lot of decisions for you assuming you want default values like a daily interval for the schedules with a 15 minute interval on the day.\nThere are some settings that cannot be made by the function and they need to be prepared before the function is executed.\n\nThe following settings need to be made before log shipping can be initiated:\n- Backup destination (the folder and the privileges)\n- Copy destination (the folder and the privileges)\n\n* Privileges\nMake sure your agent service on both the primary and the secondary instance is an Active Directory account.\nAlso have the credentials ready to set the folder permissions\n\n** Network share\nThe backup destination needs to be shared and have the share privileges of FULL CONTROL to Everyone.\n\n** NTFS permissions\nThe backup destination must have at least read/write permissions for the primary instance agent account. \nThe backup destination must have at least read permissions for the secondary instance agent account.\nThe copy destination must have at least read/write permission for the secondary instance agent acount.", "Tags": [ "Log shippin", "disaster recovery" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Invoke-DbaLogShipping sets up log shipping for one or more databases", "Name": "Invoke-DbaLogShipping", "Links": "https://dbatools.io/Invoke-DbaLogShipping", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaLogShipping -SourceSqlInstance sql1 -DestinationSqlInstance sql2 -Database db1 -BackupNetworkPath \r\n\\\\sql1\\logshipping -BackupLocalPath D:\\Data\\logshipping -BackupScheduleFrequencyType daily \r\n-BackupScheduleFrequencyInterval 1 -CompressBackup -CopyScheduleFrequencyType daily -CopyScheduleFrequencyInterval 1 \r\n-GenerateFullBackup -RestoreScheduleFrequencyType daily -RestoreScheduleFrequencyInterval 1 -SecondaryDatabaseSuffix DR \r\n-CopyDestinationFolder \\\\sql2\\logshippingdest -Force\r\n\r\nSets up log shiping for database \"db1\" with the backup path to a network share allowing local backups. \r\nIt creates daily schedules for the backup, copy and restore job with all the defaults to be executed every 15 minutes \r\ndaily.\r\nThe secondary databse will be called \"db1_LS\".\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaLogShipping -SourceSqlInstance sql1 -DestinationSqlInstance sql2 -Database db1 -BackupNetworkPath \r\n\\\\sql1\\logshipping -GenerateFullBackup -Force\r\n\r\nSets up log shipping with all defaults except that a backup file is generated.\r\nThe script will show a message that the copy destination has not been supplied and asks if you want to use the default \r\nwhich would be the backup directory of the secondary server with the folder \"logshipping\" i.e. \r\n\"D:\\SQLBackup\\Logshiping\".\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Invoke-DbaLogShippingRecovery", "Description": "By default all the databases for a particular instance are recovered.\nIf the database is in the right state, either standby or recovering, the process will try to recover the database.\n\nAt first the function will check if the backup source directory can still be reached.\nIf so it will look up the last transaction log backup for the database. If that backup file is not the last copied file the log shipping copy job will be started.\nIf the directory cannot be reached for the function will continue to the restoring process.\nAfter the copy job check is performed the job is disabled to prevent the job to run.\n\nFor the restore the log shipping status is checked in the msdb database.\nIf the last restored file is not the same as the last file name found, the log shipping restore job will be executed.\nAfter the restore job check is performed the job is disabled to prevent the job to run\n\nThe last part is to set the databse online by restoring the databases with recovery", "Author": "Sander Stad (@sqlstad), sqlstad.nl", "Synopsis": "Invoke-DbaLogShippingRecovery recovers log shipped databases to a normal state to act upon a migration or disaster.", "Name": "Invoke-DbaLogShippingRecovery", "Links": "https://dbatools.io/Invoke-DbaLogShippingRecovery", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaLogShippingRecovery -SqlServer server1\r\n\r\nRecovers all the databases on the instance that are enabled for log shiping\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaLogShippingRecovery -SqlServer server1 -SqlCredential $cred -Verbose\r\n\r\nRecovers all the databases on the instance that are enabled for log shiping using a credential\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaLogShippingRecovery -SqlServer server1 -database db_logship -Verbose\r\n\r\nRecovers the database \"db_logship\" to a normal status\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003edb1, db2, db3, db4 | Invoke-DbaLogShippingRecovery -SqlServer server1 -Verbose\r\n\r\nRecovers the database db1, db2, db3, db4 to a normal status\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaLogShippingRecovery -SqlServer server1 -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Invoke-DbaWhoisActive", "Description": "Output results of Adam Machanic\u0027s sp_WhoIsActive\n\nThis command was built with Adam\u0027s permission. To read more about sp_WhoIsActive, please visit:\n\nUpdates: http://sqlblog.com/blogs/adam_machanic/archive/tags/who+is+active/default.aspx\n\nAlso, consider donating to Adam if you find this stored procedure helpful: http://tinyurl.com/WhoIsActiveDonate", "Tags": "Memory", "Synopsis": "Outputs results of Adam Machanic\u0027s sp_WhoIsActive DataTable", "Name": "Invoke-DbaWhoisActive", "Links": "https://dbatools.io/Invoke-DbaWhoisActive", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaWhoisActive -SqlInstance sqlserver2014a\r\n\r\nExecute sp_whoisactive on sqlserver2014a. This command expects sp_WhoIsActive to be in the master database. Logs into \r\nthe SQL Server with Windows credentials.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaWhoisActive -SqlInstance sqlserver2014a -SqlCredential $credential -Database dbatools\r\n\r\nExecute sp_whoisactive on sqlserver2014a. This command expects sp_WhoIsActive to be in the dbatools database. Logs into \r\nthe SQL Server with SQL Authentication.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaWhoisActive -SqlInstance sqlserver2014a -GetAverageTime\r\n\r\nSimilar to running sp_WhoIsActive @get_avg_time\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eInvoke-DbaWhoisActive -SqlInstance sqlserver2014a -GetOuterCommand -FindBlockLeaders\r\n\r\nSimilar to running sp_WhoIsActive @get_outer_command = 1, @find_block_leaders = 1\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Invoke-Sqlcmd2", "Description": "Runs a T-SQL script. Invoke-Sqlcmd2 runs the whole script and only captures the first selected result set, such as the output of PRINT statements when -verbose parameter is specified.\nParameterized queries are supported.\n\nHelp details below borrowed from Invoke-Sqlcmd", "Synopsis": "Runs a T-SQL script.", "Name": "Invoke-Sqlcmd2", "Links": [ "https://github.com/sqlcollaborative/Invoke-SqlCmd2", "https://github.com/RamblingCookieMonster/PowerShell" ], "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eInvoke-Sqlcmd2 -ServerInstance \"MyComputer\\MyInstance\" -Query \"SELECT login_time AS \u0027StartTime\u0027 FROM \r\nsysprocesses WHERE spid = 1\"\r\n\r\nConnects to a named instance of the Database Engine on a computer and runs a basic T-SQL query.\r\n\r\nStartTime\r\n-----------\r\n2010-08-12 21:21:03.593\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eInvoke-Sqlcmd2 -ServerInstance \"MyComputer\\MyInstance\" -InputFile \"C:\\MyFolder\\tsqlscript.sql\" | Out-File \r\n-filePath \"C:\\MyFolder\\tsqlscript.rpt\"\r\n\r\nReads a file containing T-SQL statements, runs the file, and writes the output to another file.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eInvoke-Sqlcmd2 -ServerInstance \"MyComputer\\MyInstance\" -Query \"PRINT \u0027hello world\u0027\" -Verbose\r\n\r\nUses the PowerShell -Verbose parameter to return the message output of the PRINT command.\r\nVERBOSE: hello world\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eInvoke-Sqlcmd2 -ServerInstance MyServer\\MyInstance -Query \"SELECT ServerName, VCNumCPU FROM tblServerInfo\" -as \r\nPSObject | ?{$_.VCNumCPU -gt 8}\r\n\r\nInvoke-Sqlcmd2 -ServerInstance MyServer\\MyInstance -Query \"SELECT ServerName, VCNumCPU FROM tblServerInfo\" -as PSObject \r\n| ?{$_.VCNumCPU}\r\n\r\nThis example uses the PSObject output type to allow more flexibility when working with results.\r\n\r\nIf we used DataRow rather than PSObject, we would see the following behavior:\r\n Each row where VCNumCPU does not exist would produce an error in the first example\r\n Results would include rows where VCNumCPU has DBNull value in the second example\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e\u0027Instance1\u0027, \u0027Server1/Instance1\u0027, \u0027Server2\u0027 | Invoke-Sqlcmd2 -query \"Sp_databases\" -as psobject \r\n-AppendServerInstance\r\n\r\nThis example lists databases for each instance. It includes a column for the ServerInstance in question.\r\n DATABASE_NAME DATABASE_SIZE REMARKS ServerInstance\r\n ------------- ------------- ------- --------------\r\n REDACTED 88320 Instance1\r\n master 17920 Instance1\r\n ...\r\n msdb 618112 Server1/Instance1\r\n tempdb 563200 Server1/Instance1\r\n ...\r\n OperationsManager 20480000 Server2\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e#Construct a query using SQL parameters\r\n\r\n$Query = \"SELECT ServerName, VCServerClass, VCServerContact FROM tblServerInfo WHERE VCServerContact LIKE \r\n@VCServerContact AND VCServerClass LIKE @VCServerClass\"\r\n\r\n#Run the query, specifying values for SQL parameters\r\n Invoke-Sqlcmd2 -ServerInstance SomeServer\\NamedInstance -Database ServerDB -query $query -SqlParameters @{ \r\nVCServerContact=\"%cookiemonster%\"; VCServerClass=\"Prod\" }\r\n\r\n ServerName VCServerClass VCServerContact\r\n ---------- ------------- ---------------\r\n SomeServer1 Prod cookiemonster, blah\r\n SomeServer2 Prod cookiemonster\r\n SomeServer3 Prod blah, cookiemonster\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eInvoke-Sqlcmd2 -SQLConnection $Conn -Query \"SELECT login_time AS \u0027StartTime\u0027 FROM sysprocesses WHERE spid = 1\"\r\n\r\nUses an existing SQLConnection and runs a basic T-SQL query against it\r\n\r\nStartTime\r\n-----------\r\n2010-08-12 21:21:03.593\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eInvoke-SqlCmd -SQLConnection $Conn -Query \"SELECT ServerName FROM tblServerInfo WHERE ServerName LIKE \r\n@ServerName\" -SqlParameters @{\"ServerName = \"c-is-hyperv-1\"}\r\n\r\nExecutes a parameterized query against the existing SQLConnection, with a collection of one parameter to be passed to \r\nthe query when executed.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Measure-DbaBackupThroughput", "Description": "Returns backup history details for one or more databases on a SQL Server. \n\nOutput looks like this:\nSqlInstance : sql2016\nDatabase : SharePoint_Config\nAvgThroughputMB : 1.07\nAvgSizeMB : 24.17\nAvgDuration : 00:00:01.1000000\nMinThroughputMB : 0.02\nMaxThroughputMB : 2.26\nMinBackupDate : 8/6/2015 10:22:01 PM\nMaxBackupDate : 6/19/2016 12:57:45 PM\nBackupCount : 10", "Tags": [ "DisasterRecovery", "Backup", "Databases" ], "Synopsis": "Determines how quickly SQL Server is backing up databases to media.", "Name": "Measure-DbaBackupThroughput", "Links": "https://dbatools.io/Measure-DbaBackupThroughput", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eMeasure-DbaBackupThroughput -SqlInstance sql2016\r\n\r\nParses every backup in msdb\u0027s backuphistory for stats on all databases.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eMeasure-DbaBackupThroughput -SqlInstance sql2016 -Database AdventureWorks2014\r\n\r\nParses every backup in msdb\u0027s backuphistory for stats on AdventureWorks2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eMeasure-DbaBackupThroughput -SqlInstance sql2005 -Last\r\n\r\nProcesses the last full, diff and log backups every backup for all databases on sql2005.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eMeasure-DbaBackupThroughput -SqlInstance sql2005 -Last -Type Log\r\n\r\nProcesses the last log backups every backup for all databases on sql2005.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eMeasure-DbaBackupThroughput -SqlInstance sql2016 -Since (Get-Date).AddDays(-7)\r\n\r\nGets backup calculations for the last week.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eMeasure-DbaBackupThroughput -SqlInstance sql2016 -Since (Get-Date).AddDays(-365) -Database bigoldb\r\n\r\nGets backup calculations, limited to the last year and only the bigoldb database\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Mount-DbaDatabase", "Description": "This command will attach a SQL Server database.", "Tags": "Database", "Synopsis": "Attach a SQL Server Database - aliased to Attach-DbaDatabase", "Name": "Mount-DbaDatabase", "Links": "https://dbatools.io/Mount-DbaDatabase", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003e$fileStructure = New-Object System.Collections.Specialized.StringCollection\r\n\r\n$fileStructure.Add(\"E:\\archive\\example.mdf\")\r\n$filestructure.Add(\"E:\\archive\\example.ldf\")\r\n$filestructure.Add(\"E:\\archive\\example.ndf\")\r\nMount-DbaDatabase -SqlInstance sql2016 -Database example -FileStructure $fileStructure\r\n\r\nAttaches a database named \"example\" to sql2016 with the files \"E:\\archive\\example.mdf\", \"E:\\archive\\example.ldf\" and \r\n\"E:\\archive\\example.ndf\". The database owner will be set to sa and the attach option is None.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eMount-DbaDatabase -SqlInstance sql2016 -Database example\r\n\r\nSince the FileStructure was not provided, this command will attempt to determine it based on backup history. If found, \r\na database named example will be attached to sql2016.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eMount-DbaDatabase -SqlInstance sql2016 -Database example -WhatIf\r\n\r\nShows what would happen if the command were executed (without actually performing the command)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaAgentJob", "Description": "New-DbaAgentJob makes is possible to create a job in the SQL Server Agent.\nIt returns an array of the job(s) created", "Tags": [ "Agent", "Job", "Job Step" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "New-DbaAgentJob creates a new job", "Name": "New-DbaAgentJob", "Links": "https://dbatools.io/New-DbaAgentJob", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJob -SqlInstance sql1 -Job \u0027Job One\u0027 -Description \u0027Just another job\u0027\r\n\r\nCreates a job with the name \"Job1\" and a small description\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJob -SqlInstance sql1 -Job \u0027Job One\u0027 -Disabled\r\n\r\nCreates the job but sets it to disabled\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJob -SqlInstance sql1 -Job \u0027Job One\u0027 -EventLogLevel OnSuccess\r\n\r\nCreates the job and sets the notification to write to the Windows Application event log on success\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJob -SqlInstance SSTAD-PC -Job \u0027Job One\u0027 -EmailLevel OnFailure -EmailOperator dba\r\n\r\nCreates the job and sets the notification to send an e-mail to the e-mail operator\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJob -SqlInstance sql1 -Job \u0027Job One\u0027 -Description \u0027Just another job\u0027 -Whatif\r\n\r\nDoesn\u0027t create the job but shows what would happen.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job \u0027Job One\u0027\r\n\r\nCreates a job with the name \"Job One\" on multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e\"sql1\", \"sql2\", \"sql3\" | New-DbaAgentJob -Job \u0027Job One\u0027\r\n\r\nCreates a job with the name \"Job One\" on multiple servers using the pipe line\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaAgentJobStep", "Description": "New-DbaAgentJobStep creates a new job in the SQL Server Agent for a specific job", "Tags": [ "Agent", "Job", "Job Step" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "New-DbaAgentJobStep creates a new job step for a job", "Name": "New-DbaAgentJobStep", "Links": "https://dbatools.io/New-DbaAgentJobStep", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1\r\n\r\nCreate a step in \"Job1\" with the name Step1 with the default subsystem TransactSql.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1 -Database msdb\r\n\r\nCreate a step in \"Job1\" with the name Step1 where the database will the msdb\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1 -StepName Step1 -Database msdb\r\n\r\nCreate a step in \"Job1\" with the name Step1 where the database will the \"msdb\" for multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1, Job2, \u0027Job Three\u0027 -StepName Step1 -Database msdb\r\n\r\nCreate a step in \"Job1\" with the name Step1 where the database will the \"msdb\" for multiple servers for multiple jobs\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | New-DbaAgentJobStep -Job Job1 -StepName Step1 -Database msdb\r\n\r\nCreate a step in \"Job1\" with the name Step1 where the database will the \"msdb\" for multiple servers using pipeline\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaAgentSchedule", "Description": "New-DbaAgentSchedule will help create a new schedule for a job.\nIf the job parameter is not supplied the schedule will not be attached to a job.", "Tags": [ "Agent", "Job", "Job Step" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "New-DbaAgentSchedule creates a new schedule in the msdb database.", "Name": "New-DbaAgentSchedule", "Links": "https://dbatools.io/New-DbaAgentSchedule", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentSchedule -SqlInstance sql1 -Job Job1 -Schedule daily -FrequencyType Daily -FrequencyInterval 1 -Force\r\n\r\nCreates a schedule for the job with a daily frequency every day. It also assumes default values for the start date, \r\nstart time, end date and end time.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentSchedule -SqlInstance sql1 -Job Job1, Job2, Job3 -Schedule weekly -FrequencyType Weekly \r\n-FrequencyInterval Monday, Wednesday, Friday -Force\r\n\r\nCreates a schedule for the job with a daily frequency every day. It also assumes default values for the start date, \r\nstart time, end date and end time.\r\nThe force will remove any existing schedules that have the same name\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentSchedule -SqlInstance sql1 -Job Job1 -Schedule daily -StartDate 20170530 -StartTime 110000 -EndTime \r\n150000 -FrequencyType Daily -FrequencyInterval 1\r\n\r\nCreate a daily schedule that starts on the May 30th on 11 AM and ends on 3 PM.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | New-DbaAgentSchedule -Job Job1 -Schedule daily -FrequencyType Daily -FrequencyInterval 1\r\n\r\nCreates a schedule for the job with a daily frequency every day on multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | New-DbaAgentSchedule -Job Job1, Job2, Job3 -Schedule daily -FrequencyType Daily \r\n-FrequencyInterval 1\r\n\r\nCreates a schedule for the job with a daily frequency every day on multiple servers for multiple jobs using pipe line\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaAgentSchedule -SqlInstance sql1 -Schedule daily -FrequencyType Daily -FrequencyInterval 1 -Force\r\n\r\nCreates a schedule that\u0027s not connected to a job\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaCmConnection", "Description": "Generates a connection object for use in remote computer management.\nThose objects are used for the purpose of cim/wmi queries, caching which protocol worked, optimizing performance and minimizing authentication errors.\n\nNew-DbaCmConnection will create a NEW object and overwrite any existing ones for the specified computer.\nFurthermore, information stored in the input beyond the computername will be discarded in favor of the new settings.\n\nUnless the connection cache has been disabled, all connections will automatically be registered in the cache, so no further action is necessary.\nThe output is primarily for information purposes, however it may be used to pass objects and circumvent the cache with those.\n\nNOTE: Generally, this function need not be used, as a first connection to a computer using any connecting function such as \"Get-DbaCmObject\" will automatically register a new default connection for it.\n\nThis function exists to be able to preconfigure connections.", "Tags": "ComputerManagement", "Author": "Fred Winmann (@FredWeinmann)", "Synopsis": "Generates a connection object for use in remote computer management.", "Name": "New-DbaCmConnection", "Links": "https://dbatools.io/New-DbaCmConnection", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaCmConnection -ComputerName sql2014 -UseWindowsCredentials -OverrideExplicitCredential \r\n-DisabledConnectionTypes CimRM\r\n\r\nReturns a new configuration object for connecting to the computer sql2014.\r\n- The current user credentials are set as valid\r\n- The connection is configured to ignore explicit credentials (so all connections use the windows credentials)\r\n- The connections will not try using CIM over WinRM\r\n\r\nUnless caching is globally disabled, this is automatically stored in the connection cache and will be applied \r\nautomatically.\r\nIn that (the default) case, the output is for information purposes only and need not be used.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-Content computers.txt | New-DbaCmConnection -Credential $cred -CimWinRMOptions $options \r\n-DisableBadCredentialCache -OverrideExplicitCredential\r\n\r\nGathers a list of computers from a text file, then creates and registers connections for each of them, setting them to \r\n...\r\n- use the credentials stored in $cred\r\n- use the opzions stored in $options when connecting using CIM over WinRM\r\n- not store credentials that are known to not work\r\n- to ignore explicitly specified credentials\r\n\r\nEssentially, this configures all connections to those computers to prefer failure with the specified credentials over \r\nusing alternative credentials.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaComputerCertificate", "Description": "Creates a new computer certificate - self-signed or signed by an Active Directory CA, using the Web Server certificate.\n\nBy default, a key with a length of 1024 and a friendly name of the machines FQDN is generated.\n\nThis command was originally intended to help automate the process so that SSL certificates can be available for enforcing encryption on connections.\n\nIt makes a lot of assumptions - namely, that your account is allowed to auto-enroll and that you have permission to do everything it needs to do ;)\n\nReferences:\nhttp://sqlmag.com/sql-server/7-steps-ssl-encryption\nhttps://azurebi.jppp.org/2016/01/23/using-lets-encrypt-certificates-for-secure-sql-server-connections/\nhttps://blogs.msdn.microsoft.com/sqlserverfaq/2016/09/26/creating-and-registering-ssl-certificates/\n\nThe certificate is generated using AD\u0027s webserver SSL template on the client machine and pushed to the remote machine.", "Tags": "Certificate", "Synopsis": "Creates a new computer certificate useful for Forcing Encryption", "Name": "New-DbaComputerCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaComputerCertificate\r\n\r\nCreates a computer certificate signed by the local domain CA for the local machine with the keylength of 1024.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaComputerCertificate -ComputerName Server1\r\n\r\nCreates a computer certificate signed by the local domain CA _on the local machine_ for server1 with the keylength of \r\n1024.\r\n\r\nThe certificate is then copied to the new machine over WinRM and imported.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaComputerCertificate -ComputerName sqla, sqlb -ClusterInstanceName sqlcluster -KeyLength 4096\r\n\r\nCreates a computer certificate for sqlcluster, signed by the local domain CA, with the keylength of 4096.\r\n\r\nThe certificate is then copied to sqla _and_ sqlb over WinRM and imported.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaComputerCertificate -ComputerName Server1 -WhatIf\r\n\r\nShows what would happen if the command were run\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaComputerCertificate -SelfSigned\r\n\r\nCreates a self-signed certificate\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaCredential", "Description": "Creates a new credential", "Tags": "Certificate", "Synopsis": "Creates a new SQL Server credential", "Name": "New-DbaCredential", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaCredential -SqlInstance Server1\r\n\r\nYou will be prompted to securely enter your password, then a credential will be created in the master database on \r\nserver1 if it does not exist.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaCredential -SqlInstance Server1 -Database db1 -Confirm:$false\r\n\r\nSuppresses all prompts to install but prompts to securely enter your password and creates a credential in the \u0027db1\u0027 \r\ndatabase\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaDatabaseCertificate", "Description": "Creates a new database certificate. If no database is specified, the certificate will be created in master.", "Tags": "Certificate", "Synopsis": "Creates a new database certificate", "Name": "New-DbaDatabaseCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaDatabaseCertificate -SqlInstance Server1\r\n\r\nYou will be prompted to securely enter your password, then a certificate will be created in the master database on \r\nserver1 if it does not exist.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaDatabaseCertificate -SqlInstance Server1 -Database db1 -Confirm:$false\r\n\r\nSuppresses all prompts to install but prompts to securely enter your password and creates a certificate in the \u0027db1\u0027 \r\ndatabase\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaDatabaseMasterKey", "Description": "Creates a new database master key. If no database is specified, the master key will be created in master.", "Tags": "Certificate", "Synopsis": "Creates a new database master key", "Name": "New-DbaDatabaseMasterKey", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaDatabaseMasterKey -SqlInstance Server1\r\n\r\nYou will be prompted to securely enter your password, then a master key will be created in the master database on \r\nserver1 if it does not exist.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaDatabaseMasterKey -SqlInstance Server1 -Database db1 -Confirm:$false\r\n\r\nSuppresses all prompts to install but prompts to securely enter your password and creates a master key in the \u0027db1\u0027 \r\ndatabase\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaDatabaseSnapshot", "Description": "Creates database snapshots without hassles", "Tags": [ "DisasterRecovery", "Snapshot", "Restore", "Databases" ], "Author": "niphlod", "Synopsis": "Creates database snapshots", "Name": "New-DbaDatabaseSnapshot", "Links": "https://dbatools.io/New-DbaDatabaseSnapshot", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting\r\n\r\nCreates snapshot for HR and Accounting, returning a custom object displaying Server, Database, DatabaseCreated, \r\nSnapshotOf, SizeMB, DatabaseCreated, PrimaryFilePath, Status, Notes\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Database HR -Name HR_snap\r\n\r\nCreates snapshot named \"HR_snap\" for HR\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Database HR -NameSuffix \u0027fool_{0}_snap\u0027\r\n\r\nCreates snapshot named \"fool_HR_snap\" for HR\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting -Path F:\\snapshotpath\r\n\r\nCreates snapshots for HR and Accounting databases, storing files under the F:\\snapshotpath\\ dir\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaScriptingOption", "Description": "Creates a new Microsoft.SqlServer.Management.Smo.ScriptingOptions object. Basically saves you the time from remembering the SMO assembly name ;)\n\nSee https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.scriptingoptions.aspx for more information", "Tags": [ "Migration", "Backup", "DR" ], "Synopsis": "Creates a new Microsoft.SqlServer.Management.Smo.ScriptingOptions object", "Name": "New-DbaScriptingOption", "Links": "https://dbatools.io/New-DbaScriptingOption\nhttps://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.scriptingoptions.aspx", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003e$options = New-DbaScriptingOption\r\n\r\n$options.ScriptDrops = $false\r\n$options.WithDependencies = $true\r\nGet-DbaAgentJob -SqlInstance sql2016 | Export-DbaScript -ScriptingOptionObject $options\r\n\r\nExports Agent Jobs with the Scripting Options ScriptDrops set to $false and WithDependencies set to true\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaServiceMasterKey", "Description": "Creates a new service master key in the master database", "Tags": "Certificate", "Synopsis": "Creates a new service master key", "Name": "New-DbaServiceMasterKey", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaServiceMasterKey -SqlInstance Server1\r\n\r\nYou will be prompted to securely enter your Service Key Password twice, then a master key will be created in the master \r\ndatabase on server1 if it does not exist.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaSqlConnectionString", "Description": "Builds or extracts a SQL Server Connection String\n\t\nSee https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx\nand https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx\nand https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx", "Synopsis": "Builds or extracts a SQL Server Connection String", "Name": "New-DbaSqlConnectionString", "Links": "https://dbatools.io/New-DbaSqlConnectionString", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaSqlConnectionString -SqlInstance sql2014\r\n\r\nCreates a connection string that connects using Windows Authentication\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eConnect-DbaSqlServer -SqlInstance sql2016 | New-DbaSqlConnectionString\r\n\r\nBuilds a connected SMO object using Connect-DbaSqlServer then extracts and displays the connection string\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$wincred = Get-Credential ad\\sqladmin\r\n\r\nNew-DbaSqlConnectionString -SqlInstance sql2014 -Credential $wincred\r\n\r\nCreates a connection string that connects using alternative Windows credentials\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$sqlcred = Get-Credential sqladmin\r\n\r\n$server = New-DbaSqlConnectionString -SqlInstance sql2014 -Credential $sqlcred\r\n\r\nLogin to sql2014 as SQL login sqladmin.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$server = New-DbaSqlConnectionString -SqlInstance sql2014 -ClientName \"mah connection\"\r\n\r\nCreates a connection string that connects using Windows Authentication and uses the client name \"mah connection\". So \r\nwhen you open up profiler or use extended events, you can search for \"mah connection\".\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$server = New-DbaSqlConnectionString -SqlInstance sql2014 -AppendConnectionString \"Packet \r\nSize=4096;AttachDbFilename=C:\\MyFolder\\MyDataFile.mdf;User Instance=true;\"\r\n\r\nCreates a connection string that connects to sql2014 using Windows Authentication, then it sets the packet size (this \r\ncan also be done via -PacketSize) and other connection attributes.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e$server = New-DbaSqlConnectionString -SqlInstance sql2014 -NetworkProtocol TcpIp -MultiSubnetFailover\r\n\r\nCreates a connection string with Windows Authentication that uses TCPIP and has MultiSubnetFailover enabled.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003e$connstring = New-DbaSqlConnectionString sql2016 -ApplicationIntent ReadOnly\r\n\r\nCreates a connection string with ReadOnly ApplicantionIntent.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaSqlConnectionStringBuilder", "Description": "Creates a System.Data.SqlClient.SqlConnectionStringBuilder from a connection string.", "Tags": "SqlBuild", "Author": "zippy1981", "Synopsis": "Returns a System.Data.SqlClient.SqlConnectionStringBuilder with the string specified", "Name": "New-DbaSqlConnectionStringBuilder", "Links": "https://dbatools.io/New-DbaSqlConnectionStringBuilder", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaSqlConnectionStringBuilder\r\n\r\nReturns an empty ConnectionStringBuilder\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\"Data Source=localhost,1433;Initial Catalog=AlwaysEncryptedSample;UID=sa;PWD=alwaysB3Encrypt1ng;Application \r\nName=Always Encrypted Sample MVC App;Column Encryption Setting=enabled\" | New-DbaSqlConnectionStringBuilder\r\n\r\nReturns a connection string builder that can be used to connect to the local sql server instance on the default port.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaSqlDirectory", "Description": "Uses master.dbo.xp_create_subdir to create the path\nReturns $true if the path can be created, $false otherwise", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Creates new path as specified by the path variable", "Name": "New-DbaSqlDirectory", "Links": "https://dbatools.io/New-DbaSqlDirectory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaSqlDirectory -SqlInstance sqlcluster -Path L:\\MSAS12.MSSQLSERVER\\OLAP\r\n\r\nIf the SQL Server instance sqlcluster can create the path L:\\MSAS12.MSSQLSERVER\\OLAP it will do and return $true, if \r\nnot it will return $false.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$credential = Get-Credential\r\n\r\nNew-DbaSqlDirectory -SqlInstance sqlcluster -SqlCredential $credential -Path L:\\MSAS12.MSSQLSERVER\\OLAP\r\n\r\nIf the SQL Server instance sqlcluster can create the path L:\\MSAS12.MSSQLSERVER\\OLAP it will do and return $true, if \r\nnot it will return $false. Uses a SqlCredential to connect\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbaSsisCatalog", "Description": "After installing the SQL Server Engine and SSIS you still have to enable the SSIS Catalog. This function will enable the catalog and gives the option of supplying the password.", "Author": "Stephen Bennett, https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Enables the SSIS Catalog on a SQL Server 2012+", "Name": "New-DbaSsisCatalog", "Links": "https://dbatools.io/New-DbaSsisCatalog", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003e$password = ConvertTo-SecureString MyVisiblePassWord -AsPlainText -Force\r\n\r\nNew-DbaSsisCatalog -SqlInstance sql2016 -Password $password\r\n\r\nCreates the SSIS Catalog on server DEV01 with the specified password.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$password = Read-Host -AsSecureString -Prompt \"Enter password\"\r\n\r\nNew-DbaSsisCatalog -SqlInstance DEV01 -Password $password\r\n\r\nCreates the SSIS Catalog on server DEV01 with the specified password.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "New-DbatoolsSupportPackage", "Description": "This function creates an extensive debugging package that can help with reproducing and fixing issues.\n\nThe file will be created on the desktop by default and will contain quite a bit of information:\n - OS Information\n - Hardware Information (CPU, Ram, things like that)\n - .NET Information\n - PowerShell Information\n - Your input history\n - The In-Memory message log\n - The In-Memory error log\n - Screenshot of the console buffer (Basically, everything written in your current console, even if you have to scroll upwards to see it.", "Tags": "Debug", "Author": "Fred Weinmann (@FredWeinmann)", "Synopsis": "Creates a package of troubleshooting information that can be used by dbatools to help debug issues.", "Name": "New-DbatoolsSupportPackage", "Links": "https://dbatools.io/New-DbatoolsSupportPackage", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbatoolsSupportPackage\r\n\r\nCreates a large support pack in order to help us troubleshoot stuff.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Out-DbaDataTable", "Description": "Creates a DataTable based on an objects properties. This allows you to easily write to SQL Server tables.\n\nThanks to Chad Miller, this is based on his script. https://gallery.technet.microsoft.com/scriptcenter/4208a159-a52e-4b99-83d4-8048468d29dd\n\nIf the attempt to convert to datatable fails, try the -Raw parameter for less accurate datatype detection.", "Synopsis": "Creates a DataTable for an object", "Name": "Out-DbaDataTable", "Links": "https://dbatools.io/Out-DbaDataTable", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-Service | Out-DbaDataTable\r\n\r\nCreates a $datatable based off of the output of Get-Service\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eOut-DbaDataTable -InputObject $csv.cheesetypes\r\n\r\nCreates a DataTable from the CSV object, $csv.cheesetypes\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$dblist | Out-DbaDataTable\r\n\r\nSimilar to above but $dbalist gets piped in\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-Process | Out-DbaDataTable -TimeSpanType TotalSeconds\r\n\r\nCreates a DataTable with the running processes and converts any TimeSpan property to TotalSeconds.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Read-DbaBackupHeader", "Description": "Reads full, differential and transaction log backups. An online SQL Server is required to parse the backup files and the path specified must be relative to that SQL Server.", "Tags": [ "DisasterRecovery", "Backup", "Restore" ], "Synopsis": "Reads and displays detailed information about a SQL Server backup", "Name": "Read-DbaBackupHeader", "Links": "https://dbatools.io/Read-DbaBackupHeader", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRead-DbaBackupHeader -SqlInstance sql2016 -Path S:\\backups\\mydb\\mydb.bak\r\n\r\nLogs into sql2016 using Windows authentication and reads the local file on sql2016, S:\\backups\\mydb\\mydb.bak.\r\n\t\r\nIf you are running this command on a workstation and connecting remotely, remember that sql2016 cannot access files on \r\nyour own workstation.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRead-DbaBackupHeader -SqlInstance sql2016 -Path \\\\nas\\sql\\backups\\mydb\\mydb.bak, \r\n\\\\nas\\sql\\backups\\otherdb\\otherdb.bak\r\n\r\nLogs into sql2016 and reads two backup files - mydb.bak and otherdb.bak. The SQL Server service account must have \r\nrights to read this file.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRead-DbaBackupHeader -SqlInstance . -Path C:\\temp\\myfile.bak -Simple\r\n\r\nLogs into the local workstation (or computer) and shows simplified output about C:\\temp\\myfile.bak. The SQL Server \r\nservice account must have rights to read this file.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$backupinfo = Read-DbaBackupHeader -SqlInstance . -Path C:\\temp\\myfile.bak\r\n\r\n$backupinfo.FileList\r\n\t\r\nDisplays detailed information about each of the datafiles contained in the backupset.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eRead-DbaBackupHeader -SqlInstance . -Path C:\\temp\\myfile.bak -FileList\r\n\r\nAlso returns detailed information about each of the datafiles contained in the backupset.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e\"C:\\temp\\myfile.bak\", \"\\backupserver\\backups\\myotherfile.bak\" | Read-DbaBackupHeader -SqlInstance sql2016\r\n\r\nSimilar to running Read-DbaBackupHeader -SqlInstance sql2016 -Path \"C:\\temp\\myfile.bak\", \r\n\"\\backupserver\\backups\\myotherfile.bak\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-ChildItem \\\\nas\\sql\\*.bak | Read-DbaBackupHeader -SqlInstance sql2016\r\n\r\nGets a list of all .bak files on the \\\\nas\\sql share and reads the headers using the server named \"sql2016\". This means \r\nthat the server, sql2016, must have read access to the \\\\nas\\sql share.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eRead-DbaBackupHeader -Path \r\nhttps://dbatoolsaz.blob.core.windows.net/azbackups/restoretime/restoretime_201705131850.bak\r\n\r\n-AzureCredential AzureBackupUser\r\n\r\nGets the backup header information from the SQL Server backup file stored at \r\nhttps://dbatoolsaz.blob.core.windows.net/azbackups/restoretime/restoretime_201705131850.bak on Azure\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Read-DbaTraceFile", "Description": "Using the fn_trace_gettable function, a trace file is read and returned as a PowerShell object\n\nThis function returns the whole of the trace file. The information is presented in the format that the trace subsystem uses.", "Tags": [ "Security", "Trace" ], "Synopsis": "Reads a trace file from specied SQL Server Database", "Name": "Read-DbaTraceFile", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRead-DbaTraceFile -SqlInstance sql2016 -Database master, tempdb -Path C:\\traces\\big.trc\r\n\r\nReads the tracefile C:\\traces\\big.trc, stored on the sql2016 sql server. Filters only results that have master or \r\ntempdb as the DatabaseName.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRead-DbaTraceFile -SqlInstance sql2016 -Database master, tempdb -Path C:\\traces\\big.trc -TextData \u0027EXEC \r\nSP_PROCOPTION\u0027\r\n\r\nReads the tracefile C:\\traces\\big.trc, stored on the sql2016 sql server. \r\nFilters only results that have master or tempdb as the DatabaseName and that have \u0027EXEC SP_PROCOPTION\u0027 somewhere in the \r\ntext.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nRead-DbaTraceFile -SqlInstance sql2016 -Path C:\\traces\\big.trc -Where \"LinkedServerName = \u0027myls\u0027 and StartTime \r\n\u003e\u00275/30/2017 4:27:52 PM\u0027\"\r\n\r\nReads the tracefile C:\\traces\\big.trc, stored on the sql2016 sql server. \r\nFilters only results where LinkServerName = myls and StartTime is greater than \u00275/30/2017 4:27:52 PM\u0027.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Read-DbaTransactionLog", "Description": "Using the fn_dblog function, the live transaction log is read and returned as a PowerShell object\n\nThis function returns the whole of the log. The information is presented in the format that the logging subsystem uses.\n\nA soft limit of 0.5GB of log as been implemented. This is based on testing. This limit can be overidden\nat the users request, but please be aware that this may have an impact on your target databases and on the\nsystem running this function", "Tags": [ "Databases", "Logs" ], "Author": "Stuart Moore (@napalmgram), stuart-moore.com", "Synopsis": "Reads the live Transaction log from specied SQL Server Database", "Name": "Read-DbaTransactionLog", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003e$Log = Read-DbaTransactionLog -SqlInstance sql2016 -Database MyDatabase\r\n\r\nWill read the contents of the transaction log of MyDatabase on SQL Server Instance sql2016 into the local PowerShell \r\nobject $Log\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$Log = Read-DbaTransactionLog -SqlInstance sql2016 -Database MyDatabase -IgnoreLimit\r\n\r\nWill read the contents of the transaction log of MyDatabase on SQL Server Instance sql2016 into the local PowerShell \r\nobject $Log, ignoring the recommnedation of not returning more that 0.5GB of log\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaAgentJob", "Description": "Remove-DbaAgentJob removes a a job in the SQL Server Agent.", "Tags": [ "Agent", "Job" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Remove-DbaAgentJob removes a job.", "Name": "Remove-DbaAgentJob", "Links": "https://dbatools.io/Remove-DbaAgentJob", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1 -Job Job1\r\n\r\nRemoves the job from the instance with the name Job1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1 -Job Job1 -KeepHistory\r\n\r\nRemoves the job but keeps the history\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1 -Job Job1 -KeepUnusedSchedule\r\n\r\nRemoves the job but keeps the unused schedules\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job Job1\r\n\r\nRemoves the job from multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | Remove-DbaAgentJob -Job Job1\r\n\r\nRemoves the job from multiple servers using pipe line\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaAgentJobStep", "Description": "Remove-DbaAgentJobStep removes a job step in the SQL Server Agent.", "Tags": [ "Agent", "Job", "Job Step" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Remove-DbaAgentJobStep removes a job step.", "Name": "Remove-DbaAgentJobStep", "Links": "https://dbatools.io/Remove-DbaAgentJobStep", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1\r\n\r\nRemove the job step from the job\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJobStep -SqlInstance sql1 -Job Job1, Job2, Job3 -StepName Step1\r\n\r\nRemove the job step from the job for multiple jobs\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1 -StepName Step1\r\n\r\nRemove the job step from the job on multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | Remove-DbaAgentJobStep -Job Job1 -StepName Step1\r\n\r\nRemove the job step from the job on multiple servers using pipeline\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaAgentSchedule", "Description": "Remove-DbaAgentJobSchedule removes a a job in the SQL Server Agent.", "Tags": [ "Agent", "Job", "Job Step", "Schedule" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Remove-DbaAgentJobSchedule removes a job schedule.", "Name": "Remove-DbaAgentSchedule", "Links": "https://dbatools.io/Remove-DbaAgentJobSchedule", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentSchedule -SqlInstance sql1 -Schedule weekly\r\n\r\nRemove the schedule weekly\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentSchedule -SqlInstance sql1 -Schedule weekly -Force\r\n\r\nRemove the schedule weekly from the job even if the schedule is being used by another job.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentSchedule -SqlInstance sql1 -Schedule daily, weekly\r\n\r\nRemove multiple schedule\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentSchedule -SqlInstance sql1, sql2, sql3 -Schedule daily, weekly\r\n\r\nRemove the schedule on multiple servers for multiple schedules\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | Remove-DbaAgentSchedule -Schedule daily, weekly\r\n\r\nRemove the schedule on multiple servers using pipe line\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaBackup", "Description": "Provides all of the same functionality for removing SQL backups from disk as a standard maintenance plan would.\n\nAs an addition you have the ability to check the Archive bit on files before deletion. This will allow you to ensure\nbackups have been archived to your archive location before removal.\n\nAlso included is the ability to remove empty folders as part of this cleanup activity.", "Tags": [ "Storage", "DisasterRecovery", "Backup" ], "Author": "Chris Sommer, @cjsommer, www.cjsommer.com", "Synopsis": "Remove SQL Server backups from disk", "Name": "Remove-DbaBackup", "Links": "https://dbatools.io/Remove-DbaBackup", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaBackup -Path \u0027C:\\MSSQL\\SQL Backup\\\u0027 -BackupFileExtension trn -RetentionPeriod 48h\r\n\r\nThe cmdlet will remove \u0027*.trn\u0027 files from \u0027C:\\MSSQL\\SQL Backup\\\u0027 and all subdirectories that are more than 48 hours.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaBackup -Path \u0027C:\\MSSQL\\SQL Backup\\\u0027 -BackupFileExtension trn -RetentionPeriod 48h -WhatIf\r\n\r\nSame as example #1, but using the WhatIf parameter. The WhatIf parameter will allow the cmdlet show you what it will \r\ndo, without actually doing it.\r\nIn this case, no trn files will be deleted. Instead, the cmdlet will output what it will do when it runs. This is a \r\ngood preventatitive measure\r\nespecially when you are first configuring the cmdlet calls.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaBackup -Path \u0027C:\\MSSQL\\Backup\\\u0027 -BackupFileExtension bak -RetentionPeriod 7d -CheckArchiveBit\r\n\r\nThe cmdlet will remove \u0027*.bak\u0027 files from \u0027C:\\MSSQL\\Backup\\\u0027 and all subdirectories that are more than 7 days old. \r\nIt will also ensure that the bak files have been archived using the archive bit before removing them.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaBackup -Path \u0027C:\\MSSQL\\Backup\\\u0027 -BackupFileExtension bak -RetentionPeriod 1w -RemoveEmptyBackupFolder\r\n\r\nThe cmdlet will remove \u0027*.bak\u0027 files from \u0027C:\\MSSQL\\Backup\\\u0027 and all subdirectories that are more than 1 week old. \r\nIt will also remove any backup folders that no longer contain backup files.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaCmConnection", "Description": "Removes connection objects from the connection cache used for remote computer management.", "Tags": "ComputerManagement", "Author": "Fred Winmann (@FredWeinmann)", "Synopsis": "Removes connection objects from the connection cache used for remote computer management.", "Name": "Remove-DbaCmConnection", "Links": "https://dbatools.io/Remove-DbaCmConnection", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaCmConnection -ComputerName sql2014\r\n\r\nRemoves the cached connection to the server sql2014 from the cache.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmConnection | Remove-DbaCmConnection\r\n\r\nClears the entire connection cache.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaComputerCertificate", "Description": "Removes a computer certificate from a local or remote compuer", "Tags": "Certificate", "Synopsis": "Removes a computer certificate - useful for removing easily certs from remote computers", "Name": "Remove-DbaComputerCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaComputerCertificate -ComputerName Server1 -Thumbprint C2BBE81A94FEE7A26FFF86C2DFDAF6BFD28C6C94\r\n\r\nRemoves certificate with thumbprint C2BBE81A94FEE7A26FFF86C2DFDAF6BFD28C6C94 in the LocalMachine store on Server1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaComputerCertificate | Where-Object Thumbprint -eq E0A071E387396723C45E92D42B2D497C6A182340 | \r\nRemove-DbaComputerCertificate\r\n\r\nRemoves certificate using the pipeline\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaComputerCertificate -ComputerName Server1 -Thumbprint C2BBE81A94FEE7A26FFF86C2DFDAF6BFD28C6C94 -Store \r\nUser -Folder My\r\n\r\nRemoves certificate with thumbprint C2BBE81A94FEE7A26FFF86C2DFDAF6BFD28C6C94 in the User\\My (Personal) store on Server1\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaDatabase", "Description": "Tries a bunch of different ways to remove a database or two or more.", "Tags": [ "Delete", "Databases" ], "Synopsis": "Drops a database, hopefully even the really stuck ones.", "Name": "Remove-DbaDatabase", "Links": "https://dbatools.io/Remove-DbaDatabase", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabase -SqlInstance sql2016 -Database containeddb\r\n\r\nPrompts then removes the database containeddb on SQL Server sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabase -SqlInstance sql2016 -Database containeddb, mydb\r\n\r\nPrompts then removes the databases containeddb and mydb on SQL Server sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabase -SqlInstance sql2016 -Database containeddb -Confirm:$false\r\n\r\nDoes not prompt and swiftly removes containeddb on SQL Server sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance server\\instance -ExcludeAllSystemDb | Remove-DbaDatabase\r\n\r\nRemoves all the user databases from server\\instance\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaDatabaseCertificate", "Description": "Deletes specified database certificate", "Tags": "Certificate", "Synopsis": "Deletes specified database certificate", "Name": "Remove-DbaDatabaseCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseCertificate -SqlInstance Server1\r\n\r\nThe certificate in the master database on server1 will be removed if it exists.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseCertificate -SqlInstance Server1 -Database db1 -Confirm:$false\r\n\r\nSuppresses all prompts to remove the certificate in the \u0027db1\u0027 database and drops the key.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaDatabaseMasterKey", "Description": "Deletes specified database master key.", "Tags": "Certificate", "Synopsis": "Deletes specified database master key", "Name": "Remove-DbaDatabaseMasterKey", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseMasterKey -SqlInstance Server1\r\n\r\nThe master key in the master database on server1 will be removed if it exists.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseMasterKey -SqlInstance Server1 -Database db1 -Confirm:$false\r\n\r\nSuppresses all prompts to remove the master key in the \u0027db1\u0027 database and drops the key.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaDatabaseSafely", "Description": "Performs a DBCC CHECKDB on the database, backs up the database with Checksum and verify only to a final (golden) backup location, creates an Agent Job to restore from that backup, drops the database, runs the agent job to restore the database, performs a DBCC CHECKDB and drops the database.\n\nWith huge thanks to Grant Fritchey and his verify your backups video. Take a look, it\u0027s only 3 minutes long. http://sqlps.io/backuprant", "Tags": [ "DisasterRecovery", "Backup", "Restore", "Databases" ], "Author": "Rob Sewell @SQLDBAWithBeard, sqldbawithabeard.com", "Synopsis": "Safely removes a SQL Database and creates an Agent Job to restore it.", "Name": "Remove-DbaDatabaseSafely", "Links": "https://dbatools.io/Remove-DbaDatabaseSafely", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseSafely -SqlInstance \u0027Fade2Black\u0027 -Database RideTheLightning -BackupFolder \r\n\u0027C:\\MSSQL\\Backup\\Rationalised - DO NOT DELETE\u0027\r\n\r\nPerforms a DBCC CHECKDB on database RideTheLightning on server Fade2Black. If there are no errors, the database is \r\nbackup to the folder C:\\MSSQL\\Backup\\Rationalised - DO NOT DELETE. Then, an Agent job to restore the database from that \r\nbackup is created. The database is then dropped, the Agent job to restore it run, a DBCC CHECKDB run against the \r\nrestored database, and then it is dropped again.\r\n\r\nAny DBCC errors will be written to your documents folder\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$Database = \u0027DemoNCIndex\u0027,\u0027RemoveTestDatabase\u0027\r\n\r\nRemove-DbaDatabaseSafely -SqlInstance \u0027Fade2Black\u0027 -Database $Database -BackupFolder \u0027C:\\MSSQL\\Backup\\Rationalised - DO \r\nNOT DELETE\u0027\r\n\r\nPerforms a DBCC CHECKDB on two databases, \u0027DemoNCIndex\u0027 and \u0027RemoveTestDatabase\u0027 on server Fade2Black. Then, an Agent \r\njob to restore each database from those backups is created. The databases are then dropped, the Agent jobs to restore \r\nthem run, a DBCC CHECKDB run against the restored databases, and then they are dropped again.\r\n\r\nAny DBCC errors will be written to your documents folder\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseSafely -SqlInstance \u0027Fade2Black\u0027 -DestinationServer JusticeForAll -Database RideTheLightning \r\n-BackupFolder \u0027\\\\BACKUPSERVER\\BACKUPSHARE\\MSSQL\\Rationalised - DO NOT DELETE\u0027\r\n\r\nPerforms a DBCC CHECKDB on database RideTheLightning on server Fade2Black. If there are no errors, the database is \r\nbackup to the folder \\\\BACKUPSERVER\\BACKUPSHARE\\MSSQL\\Rationalised - DO NOT DELETE . Then, an Agent job is created on \r\nserver JusticeForAll to restore the database from that backup is created. The database is then dropped on Fade2Black, \r\nthe Agent job to restore it on JusticeForAll is run, a DBCC CHECKDB run against the restored database, and then it is \r\ndropped from JusticeForAll.\r\n\r\nAny DBCC errors will be written to your documents folder\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseSafely -SqlInstance IronMaiden -Database $Database -DestinationServer TheWildHearts \r\n-BackupFolder Z:\\Backups -NoDbccCheckDb -UseDefaultFilePaths -JobOwner \u0027THEBEARD\\Rob\u0027\r\n\r\nFor the databases $Database on the server IronMaiden a DBCC CHECKDB will not be performed before backing up the \r\ndatabases to the folder Z:\\Backups. Then, an Agent job is created on server TheWildHearts with a Job Owner of \r\nTHEBEARD\\Rob to restore each database from that backup using the instance\u0027s default file paths. The database(s) is(are) \r\nthen dropped on IronMaiden, the Agent job(s) run, a DBCC CHECKDB run on the restored database(s), and then the \r\ndatabase(s) is(are) dropped.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseSafely -SqlInstance IronMaiden -Database $Database -DestinationServer TheWildHearts \r\n-BackupFolder Z:\\Backups -UseDefaultFilePaths -ContinueAfterDbccError\r\n\r\nThe databases $Database on the server IronMaiden will be backed up the to the folder Z:\\Backups. Then, an Agent job is \r\ncreated on server TheWildHearts with a Job Owner of THEBEARD\\Rob to restore each database from that backup using the \r\ninstance\u0027s default file paths. The database(s) is(are) then dropped on IronMaiden, the Agent job(s) run, a DBCC CHECKDB \r\nrun on the restored database(s), and then the database(s) is(are) dropped.\r\n\r\nIf there is a DBCC Error, the function will continue to perform rest of the actions and will create an Agent job with \r\n\u0027DBCCERROR\u0027 in the name and a Backup file with \u0027DBCCError\u0027 in the name.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaDatabaseSnapshot", "Description": "Removes (drops) database snapshots from the server", "Tags": [ "Snapshot", "Database" ], "Author": "niphlod", "Synopsis": "Removes database snapshots", "Name": "Remove-DbaDatabaseSnapshot", "Links": "https://dbatools.io/Remove-DbaDatabaseSnapshot", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseSnapshot -SqlInstance sqlserver2014a\r\n\r\nRemoves all database snapshots from sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Snapshot HR_snap_20161201, HR_snap_20161101\r\n\r\nRemoves database snapshots named HR_snap_20161201 and HR_snap_20161101\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting\r\n\r\nRemoves all database snapshots having HR and Accounting as base dbs\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaDatabaseSnapshot -SqlInstance sqlserver2014a -Snapshot HR_snapshot, Accounting_snapshot\r\n\r\nRemoves HR_snapshot and Accounting_snapshot\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseSnapshot -SqlInstance sql2016 | Where SnapshotOf -like \u0027*dumpsterfire*\u0027 | \r\nRemove-DbaDatabaseSnapshot\r\n\r\nRemoves all snapshots associated with databases that have dumpsterfire in the name\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaNetworkCertificate", "Description": "Removes the network certificate for SQL Server instance. This setting is found in Configuration Manager.", "Tags": "Certificate", "Synopsis": "Removes the network certificate for SQL Server instance", "Name": "Remove-DbaNetworkCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaNetworkCertificate\r\n\r\nRemoves the Network Certificate for the default instance (MSSQLSERVER) on localhost\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaNetworkCertificate -SqlInstance sql1\\SQL2008R2SP2\r\n\r\nRemoves the Network Certificate for the SQL2008R2SP2 instance on sql1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaNetworkCertificate -SqlInstance localhost\\SQL2008R2SP2 -WhatIf\r\n\r\nShows what would happen if the command were run\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaOrphanUser", "Description": "An orphan user is defined by a user that does not have their matching login. (Login property = \"\").\n\nIf user is the owner of the schema with the same name and if if the schema does not have any underlying objects the schema will be dropped.\n\nIf user owns more than one schema, the owner of the schemas that does not have the same name as the user, will be changed to \u0027dbo\u0027. If schemas have underlying objects, you must specify the -Force parameter so the user can be dropped.\n\nIf exists a login to map the drop will not be performed unless you specify the -Force parameter (only when calling from Repair-DbaOrphanUser.", "Tags": [ "Orphan", "Databases" ], "Author": "Claudio Silva (@ClaudioESSilva)", "Synopsis": "Drop orphan users with no existing login to map", "Name": "Remove-DbaOrphanUser", "Links": "https://dbatools.io/Remove-DbaOrphanUser", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaOrphanUser -SqlInstance sql2005\r\n\r\nFinds and drops all orphan users without matching Logins in all databases present on server \u0027sql2005\u0027.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaOrphanUser -SqlInstance sqlserver2014a -SqlCredential $cred\r\n\r\nFinds and drops all orphan users without matching Logins in all databases present on server \u0027sqlserver2014a\u0027. SQL \r\nServer authentication will be used in connecting to the server.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaOrphanUser -SqlInstance sqlserver2014a -Database db1, db2 -Force\r\n\r\nFinds and drops orphan users even if they have a matching Login on both db1 and db2 databases.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaOrphanUser -SqlInstance sqlserver2014a -ExcludeDatabase db1, db2 -Force\r\n\r\nFinds and drops orphan users even if they have a matching Login from all databases except db1 and db2.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaOrphanUser -SqlInstance sqlserver2014a -User OrphanUser\r\n\r\nRemoves user OrphanUser from all databases only if there is no matching login.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaOrphanUser -SqlInstance sqlserver2014a -User OrphanUser -Force\r\n\r\nRemoves user OrphanUser from all databases even if they have a matching Login. Any schema that the user owns will \r\nchange ownership to dbo.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Remove-DbaSpn", "Description": "This function will connect to Active Directory and search for an account. If the account is found, it will attempt to remove the specified SPN. Once the SPN is removed, the function will also remove delegation to that service. \n\nIn order to run this function, the credential you provide must have write access to Active Directory.\n\nNote: This function supports -WhatIf", "Tags": "SPN", "Author": "Drew Furgiuele (@pittfurg), http://www.port1433.com", "Synopsis": "Removes an SPN for a given service account in active directory and also removes delegation to the same SPN, if found", "Name": "Remove-DbaSpn", "Links": "https://dbatools.io/Remove-DbaSpn", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account\r\n\r\nConnects to Active Directory and removes a provided SPN from the given account (and also the relative delegation)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account -Silent\r\n\r\nConnects to Active Directory and removes a provided SPN from the given account, suppressing all error messages and \r\nthrow exceptions that can be caught instead\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account -Credential \r\n(Get-Credential)\r\n\r\nConnects to Active Directory and removes a provided SPN to the given account. Uses alternative account to connect to AD.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSpn -ComputerName sql2005 | Where { $_.isSet -eq $true } | Remove-DbaSpn -WhatIf\r\n\r\nShows what would happen trying to remove all set SPNs for sql2005 and the relative delegations\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSpn -ComputerName sql2005 | Where { $_.isSet -eq $true } | Remove-DbaSpn\r\n\r\nRemoves all set SPNs for sql2005 and the relative delegations\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Rename-DbaLogin", "Description": "There are times where you might want to rename a login that was copied down, or if the name is not descriptive for what it does. \n\nIt can be a pain to update all of the mappings for a specific user, this does it for you.", "Tags": "Login", "Author": "Mitchell Hamann (@SirCaptainMitch)", "Synopsis": "Rename-DbaLogin will rename login and database mapping for a specified login.", "Name": "Rename-DbaLogin", "Links": "https://dbatools.io/Rename-DbaLogin", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRename-DbaLogin -SqlInstance localhost -Login DbaToolsUser -NewLogin captain\r\n\r\nSQL Login Example\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRename-DbaLogin -SqlInstance localhost -Login domain\\oldname -NewLogin domain\\newname\r\n\r\nChange the windowsuser login name.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRename-DbaLogin -SqlInstance localhost -Login dbatoolsuser -NewLogin captain -WhatIf\r\n\r\nWhatIf Example\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Repair-DbaOrphanUser", "Description": "An orphan user is defined by a user that does not have a matching login (Login property = \"\").\n\nIf the matching login exists it must be:\n\tEnabled\n\tNot a system object\n\tNot locked\n\tHave the same name that user\n\nYou can drop users that does not have their matching login by specifying the parameter -RemoveNotExisting.", "Tags": "Orphan", "Author": "Claudio Silva (@ClaudioESSilva)", "Synopsis": "Finds orphan users with existing login and remaps them.", "Name": "Repair-DbaOrphanUser", "Links": "https://dbatools.io/Repair-DbaOrphanUser", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaOrphanUser -SqlInstance sql2005\r\n\r\nFinds and repairs all orphan users of all databases present on server \u0027sql2005\u0027\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaOrphanUser -SqlInstance sqlserver2014a -SqlCredential $cred\r\n\r\nFinds and repair all orphan users in all databases present on server \u0027sqlserver2014a\u0027. SQL credentials are used to \r\nauthenticate to the server.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaOrphanUser -SqlInstance sqlserver2014a -Database db1, db2\r\n\r\nFinds and repairs all orphan users in both db1 and db2 databases.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaOrphanUser -SqlInstance sqlserver2014a -Database db1 -Users OrphanUser\r\n\r\nFinds and repairs user \u0027OrphanUser\u0027 in \u0027db1\u0027 database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaOrphanUser -SqlInstance sqlserver2014a -Users OrphanUser\r\n\r\nFinds and repairs user \u0027OrphanUser\u0027 on all databases\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaOrphanUser -SqlInstance sqlserver2014a -RemoveNotExisting\r\n\r\nFinds all orphan users of all databases present on server \u0027sqlserver2014a\u0027. Removes all users that do not have \r\nmatching Logins.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Repair-DbaServerName", "Description": "When a SQL Server\u0027s host OS is renamed, the SQL Server should be as well. This helps with Availability Groups and Kerberos.\n\nThis command renames @@SERVERNAME to match with the Windows name. The new name is automatically determined. It does not matter if you use an alias to connect to the SQL instance.\n\t\t\nIf the automatically determiend new name matches the old name, the command will not run.\n\t\nhttps://www.mssqltips.com/sqlservertip/2525/steps-to-change-the-server-name-for-a-sql-server-machine/", "Tags": "SPN", "Synopsis": "Renames @@SERVERNAME to match with the Windows name.", "Name": "Repair-DbaServerName", "Links": "https://dbatools.io/Repair-DbaServerName", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaServerName -SqlInstance sql2014\r\n\r\nChecks to see if the server is updatable, prompts galore, changes name.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaServerName -SqlInstance sql2014 -AutoFix\r\n\r\nEven more prompts/confirms, but removes Replication or breaks mirroring if necessary.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRepair-DbaServerName -SqlInstance sql2014 -AutoFix -Force\r\n\r\nSkips some prompts/confirms but not all of them.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Reset-DbaAdmin", "Description": "This function allows administrators to regain access to local or remote SQL Servers by either resetting the sa password, adding the sysadmin role to existing login, or adding a new login (SQL or Windows) and granting it sysadmin privileges.\n\nThis is accomplished by stopping the SQL services or SQL Clustered Resource Group, then restarting SQL via the command-line using the /mReset-DbaAdmin parameter which starts the server in Single-User mode and only allows this script to connect.\n\nOnce the service is restarted, the following tasks are performed:\n- Login is added if it doesn\u0027t exist\n- If login is a Windows User, an attempt is made to ensure it exists\n- If login is a SQL Login, password policy will be set to OFF when creating the login, and SQL Server authentication will be set to Mixed Mode.\n- Login will be enabled and unlocked\n- Login will be added to sysadmin role\n\nIf failures occur at any point, a best attempt is made to restart the SQL Server.\n\nIn order to make this script as portable as possible, System.Data.SqlClient and Get-WmiObject are used (as opposed to requiring the Failover Cluster Admin tools or SMO).\n\nIf using this function against a remote SQL Server, ensure WinRM is configured and accessible. If this is not possible, run the script locally.\n\nTested on Windows XP, 7, 8.1, Server 2012 and Windows Server Technical Preview 2.\nTested on SQL Server 2005 SP4 through 2016 CTP2.", "Tags": "WSMan", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "This function allows administrators to regain access to SQL Servers in the event that passwords or access was lost.\n\nSupports SQL Server 2005 and above. Windows administrator access is required.", "Name": "Reset-DbaAdmin", "Links": "https://dbatools.io/Reset-DbaAdmin", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eReset-DbaAdmin -SqlInstance sqlcluster\r\n\r\nPrompts for password, then resets the \"sa\" account password on sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eReset-DbaAdmin -SqlInstance sqlserver\\sqlexpress -Login ad\\administrator\r\n\r\nPrompts user to confirm that they understand the SQL Service will be restarted.\r\n\r\nAdds the domain account \"ad\\administrator\" as a sysadmin to the SQL instance.\r\nIf the account already exists, it will be added to the sysadmin role.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eReset-DbaAdmin -SqlInstance sqlserver\\sqlexpress -Login sqladmin -Force\r\n\r\nSkips restart confirmation, prompts for password, then adds a SQL Login \"sqladmin\" with sysadmin privileges.\r\nIf the account already exists, it will be added to the sysadmin role and the password will be reset.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Resolve-DbaNetworkName", "Description": "Retrieves the IPAddress, ComputerName from one computer.\nThe object can be used to take action against its name or IPAddress.\n\nFirst ICMP is used to test the connection, and get the connected IPAddress.\n\nMultiple protocols (e.g. WMI, CIM, etc) are attempted before giving up.\n\nImportant: Remember that FQDN doesn\u0027t always match \"ComputerName dot Domain\" as AD intends.\n\tThere are network setup (google \"disjoint domain\") where AD and DNS do not match.\n\t\"Full computer name\" (as reported by sysdm.cpl) is the only match between the two,\n\tand it matches the \"DNSHostName\" property of the computer object stored in AD.\n\tThis means that the notation of FQDN that matches \"ComputerName dot Domain\" is incorrect\n\tin those scenarios.\n\tIn other words, the \"suffix\" of the FQDN CAN be different from the AD Domain.\n\t\n\tThis cmdlet has been providing good results since its inception but for lack of useful\n\tnames some doubts may arise.\n\tLet this clear the doubts:\n\t- InputName: whatever has been passed in\n\t- ComputerName: hostname only\n\t- IPAddress: IP Address\n\t- DNSHostName: hostname only, coming strictly from DNS (as reported from the calling computer)\n\t- DNSDomain: domain only, coming strictly from DNS (as reported from the calling computer)\n\t- Domain: domain only, coming strictly from AD (i.e. the domain the ComputerName is joined to)\n\t- DNSHostEntry: Fully name as returned by DNS [System.Net.Dns]::GetHostEntry\n\t- FQDN: \"legacy\" notation of ComputerName \"dot\" Domain (coming from AD)\n\t- FullComputerName: Full name as configured from within the Computer (i.e. the only secure match between AD and DNS)\n\nSo, if you need to use something, go with FullComputerName, always, as it is the most correct in every scenario.", "Tags": [ "Network", "Resolve" ], "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Returns information about the network connection of the target computer including NetBIOS name, IP Address, domain name and fully qualified domain name (FQDN).", "Name": "Resolve-DbaNetworkName", "Links": "https://dbatools.io/Resolve-DbaNetworkName", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eResolve-DbaNetworkName -ComputerName ServerA\r\n\r\nReturns a custom object displaying InputName, ComputerName, IPAddress, DNSHostName, DNSDomain, Domain, DNSHostEntry, \r\nFQDN, DNSHostEntry for ServerA\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eResolve-DbaNetworkName -SqlInstance sql2016\\sqlexpress\r\n\r\nReturns a custom object displaying InputName, ComputerName, IPAddress, DNSHostName, DNSDomain, Domain, DNSHostEntry, \r\nFQDN, DNSHostEntry for the SQL instance sql2016\\sqlexpress\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eResolve-DbaNetworkName -SqlInstance sql2016\\sqlexpress, sql2014\r\n\r\nReturns a custom object displaying InputName, ComputerName, IPAddress, DNSHostName, DNSDomain, Domain, DNSHostEntry, \r\nFQDN, DNSHostEntry for the SQL instance sql2016\\sqlexpress and sql2014\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2014 | Resolve-DbaNetworkName\r\n\r\nReturns a custom object displaying InputName, ComputerName, IPAddress, DNSHostName, Domain, FQDN for all SQL Servers \r\nreturned by Get-DbaRegisteredServer\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Restart-DbaSqlService", "Description": "Restarts the SQL Server related services on one or more computers. Will follow SQL Server service dependencies.\n\nRequires Local Admin rights on destination computer(s).", "Author": "Kirill Kravtsov( @nvarscar )", "Synopsis": "Restarts SQL Server services on a computer.", "Name": "Restart-DbaSqlService", "Links": "https://dbatools.io/Restart-DbaSqlService", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRestart-DbaSqlService -ComputerName sqlserver2014a\r\n\r\nRestarts the SQL Server related services on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027| Get-DbaSqlService | Restart-DbaSqlService\r\n\r\nGets the SQL Server related services on computers sql1, sql2 and sql3 and restarts them.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRestart-DbaSqlService -ComputerName sql1,sql2 -Instance MSSQLSERVER\r\n\r\nRestarts the SQL Server services related to the default instance MSSQLSERVER on computers sql1 and sql2.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRestart-DbaSqlService -ComputerName $MyServers -Type SSRS\r\n\r\nRestarts the SQL Server related services of type \"SSRS\" (Reporting Services) on computers in the variable MyServers.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eRestart-DbaSqlService -ComputerName sql1 -Type Engine -Force\r\n\r\nRestarts SQL Server database engine services on sql1 forcing dependent SQL Server Agent services to restart as well.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Restore-DbaBackupFromDirectory", "Description": "Many SQL Server database administrators use Ola Hallengren\u0027s SQL Server Maintenance Solution which can be found at http://ola.hallengren.com\n\nHallengren uses a predictable backup structure which made it relatively easy to create a script that can restore an entire SQL Server database instance, down to the master database (next version), to a new server. This script is intended to be used in the event that the originating SQL Server becomes unavailable, thus rendering my other SQL restore script (http://goo.gl/QmfQ6s) ineffective.", "Tags": [ "DisasterRecovery", "Backup", "Restore" ], "Synopsis": "Restores SQL Server databases from the backup directory structure created by Ola Hallengren\u0027s database maintenance scripts. Different structures coming soon.", "Name": "Restore-DbaBackupFromDirectory", "Links": "https://dbatools.io/Restore-SqlBackupFromDirectory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRestore-SqlBackupFromDirectory -SqlInstance sqlcluster -Path \\\\fileserver\\share\\sqlbackups\\SQLSERVER2014A\r\n\r\nAll user databases contained within \\\\fileserver\\share\\sqlbackups\\SQLSERVERA will be restored to sqlcluster, down the \r\nmost recent full/differential/logs.\r\n\r\n\r\nRequires -Version 3.0\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Restore-DbaDatabase", "Description": "Upon bein passed a list of potential backups files this command will scan the files, select those that contain SQL Server\nbackup sets. It will then filter those files down to a set that can perform the requested restore, checking that we have a\nfull restore chain to the point in time requested by the caller.\n\nThe function defaults to working on a remote instance. This means that all paths passed in must be relative to the remote instance.\nXpDirTree will be used to perform the file scans\n\n\nVarious means can be used to pass in a list of files to be considered. The default is to non recursively scan the folder\npassed in.", "Tags": [ "DisasterRecovery", "Backup", "Restore" ], "Author": "Stuart Moore (@napalmgram), stuart-moore.com", "Synopsis": "Restores a SQL Server Database from a set of backupfiles", "Name": "Restore-DbaDatabase", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRestore-DbaDatabase -SqlInstance server1\\instance1 -Path \\\\server2\\backups\r\n\r\nScans all the backup files in \\\\server2\\backups, filters them and restores the database to server1\\instance1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRestore-DbaDatabase -SqlInstance server1\\instance1 -Path \\\\server2\\backups -MaintenanceSolutionBackup \r\n-DestinationDataDirectory c:\\restores\r\n\r\nScans all the backup files in \\\\server2\\backups$ stored in an Ola Hallengren style folder structure,\r\nfilters them and restores the database to the c:\\restores folder on server1\\instance1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-ChildItem c:\\SQLbackups1\\, \\\\server\\sqlbackups2 | Restore-DbaDatabase -SqlInstance server1\\instance1\r\n\r\nTakes the provided files from multiple directories and restores them on server1\\instance1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$RestoreTime = Get-Date(\u002711:19 23/12/2016\u0027)\r\n\r\nRestore-DbaDatabase -SqlInstance server1\\instance1 -Path \\\\server2\\backups -MaintenanceSolutionBackup \r\n-DestinationDataDirectory c:\\restores -RestoreTime $RestoreTime\r\n\r\nScans all the backup files in \\\\server2\\backups stored in an Ola Hallengren style folder structure,\r\nfilters them and restores the database to the c:\\restores folder on server1\\instance1 up to 11:19 23/12/2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eRestore-DbaDatabase -SqlInstance server1\\instance1 -Path \\\\server2\\backups -DestinationDataDirectory c:\\restores \r\n-OutputScriptOnly | Select-Object -ExpandPropert Tsql | Out-File -Filepath c:\\scripts\\restore.sql\r\n\r\nScans all the backup files in \\\\server2\\backups stored in an Ola Hallengren style folder structure,\r\nfilters them and generate the T-SQL Scripts to restore the database to the latest point in time,\r\nand then stores the output in a file for later retrieval\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eRestore-DbaDatabase -SqlInstance server1\\instance1 -Path c:\\backups -DestinationDataDirectory c:\\DataFiles \r\n-DestinationLogDirectory c:\\LogFile\r\n\r\nScans all the files in c:\\backups and then restores them onto the SQL Server Instance server1\\instance1, placing data \r\nfiles\r\nc:\\DataFiles and all the log files into c:\\LogFiles\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eRestore-DbaDatabase -SqlInstance server1\\instance1 -Path http://demo.blob.core.windows.net/backups/dbbackup.bak \r\n-AzureCredential MyAzureCredential\r\n\r\nWill restore the backup held at http://demo.blob.core.windows.net/backups/dbbackup.bak to server1\\instance1. The \r\nconnection to Azure will be made using the \r\ncredential MyAzureCredential held on instance Server1\\instance1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003e$File = Get-ChildItem c:\\backups, \\\\server1\\backups -recurse\r\n\r\n$File | Restore-DbaDatabase -SqlInstance Server1\\Instance -useDestinationDefaultDirectories\r\n\r\nThis will take all of the files found under the folders c:\\backups and \\\\server1\\backups, and pipeline them into\r\nRestore-DbaDatabase. Restore-DbaDatabase will then scan all of the files, and restore all of the databases included\r\nto the latest point in time covered by their backups. All data and log files will be moved to the default SQL Sever\r\nfolder for those file types as defined on the target instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003e$files = Get-ChildItem C:\\dbatools\\db1\r\n\r\n#Restore database to a point in time\r\n$files | Restore-DbaDatabase -SqlServer server\\instance1 `\r\n\t\t\t-DestinationFilePrefix prefix -DatabaseName Restored `\r\n\t\t\t-RestoreTime (get-date \"14:58:30 22/05/2017\") `\r\n\t\t\t-NoRecovery -WithReplace -StandbyDirectory C:\\dbatools\\standby \r\n\r\n#It\u0027s in standby so we can peek at it\r\nInvoke-Sqlcmd2 -ServerInstance server\\instance1 -Query \"select top 1 * from Restored.dbo.steps order by dt desc\"\r\n\r\n#Not quite there so let\u0027s roll on a bit:\r\n$files | Restore-DbaDatabase -SqlServer server\\instance1 `\r\n\t\t\t-DestinationFilePrefix prefix -DatabaseName Restored `\r\n\t\t\t-continue -WithReplace -RestoreTime (get-date \"15:09:30 22/05/2017\") `\r\n\t\t\t-StandbyDirectory C:\\dbatools\\standby\r\n\r\nInvoke-Sqlcmd2 -ServerInstance server\\instance1 -Query \"select top 1 * from restored.dbo.steps order by dt desc\"\r\n\r\nRestore-DbaDatabase -SqlServer server\\instance1 `\r\n\t\t\t-DestinationFilePrefix prefix -DatabaseName Restored `\r\n\t\t\t-continue -WithReplace \r\n\r\nIn this example we step through the backup files held in c:\\dbatools\\db1 folder.\r\nFirst we restore the database to a point in time in standby mode. This means we can check some details in the databases\r\nWe then roll it on a further 9 minutes to perform some more checks\r\nAnd finally we continue by rolling it all the way forward to the latest point in the backup.\r\nAt each step, only the log files needed to roll the database forward are restored.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Restore-DbaDatabaseCertificate", "Description": "Imports certificates from.cer files using SMO.", "Tags": [ "Migration", "Certificate" ], "Author": "Jess Pomfret (@jpomfret)", "Synopsis": "Imports certificates from .cer files using SMO.", "Name": "Restore-DbaDatabaseCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRestore-DbaDatabaseCertificate -SqlInstance Server1 -Path \\\\Server1\\Certificates -password \r\n(ConvertTo-SecureString -force -AsPlainText GoodPass1234!!)\r\n\r\nImports all the certificates in the specified path.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Restore-DbaFromDatabaseSnapshot", "Description": "Restores the database from the snapshot, discarding every modification made to the database\nNB: Restoring to a snapshot will result in every other snapshot of the same database to be dropped\nIt also fixes some long-standing bugs in SQL Server when restoring from snapshots", "Tags": [ "DisasterRecovery", "Snapshot", "Backup", "Restore", "Database" ], "Author": "niphlod", "Synopsis": "Restores databases from snapshots", "Name": "Restore-DbaFromDatabaseSnapshot", "Links": "https://dbatools.io/Restore-DbaFromDatabaseSnapshot", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRestore-DbaFromDatabaseSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting\r\n\r\nRestores HR and Accounting databases using the latest snapshot available\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRestore-DbaFromDatabaseSnapshot -SqlInstance sqlserver2014a -Snapshot HR_snap_20161201, Accounting_snap_20161101\r\n\r\nRestores databases from snapshots named HR_snap_20161201 and Accounting_snap_20161101\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Save-DbaDiagnosticQueryScript", "Description": "The dbatools module will have the diagnostic queries pre-installed. Use this only to update to a more recent version or specific versions.\n\nThis function is mainly used by Invoke-DbaDiagnosticQuery, but can also be used independently to download the Glenn Berry DMV scripts.\n\nUse this function to pre-download the scripts from a device with an Internet connection.\n\t\nThe function Invoke-DbaDiagnosticQuery will try to download these scripts automatically, but it obviously needs an internet connection to do that.", "Tags": [ "Diagnostic", "DMV", "Troubleshooting" ], "Author": "André Kamman (@AndreKamman), http://clouddba.io", "Synopsis": "Save-DbaDiagnosticQueryScript downloads the most recent version of all Glenn Berry DMV scripts", "Name": "Save-DbaDiagnosticQueryScript", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSave-DbaDiagnosticQueryScript -Path c:\\temp\r\n\r\nDownloads the most recent version of all Glenn Berry DMV scripts to the specified location.\r\nIf Path is not specified, the \"My Documents\" location will be used.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaAgentJob", "Description": "Set-DbaAgentJob updates a job in the SQL Server Agent with parameters supplied.", "Tags": [ "Agent", "Job" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Set-DbaAgentJob updates a job.", "Name": "Set-DbaAgentJob", "Links": "https://dbatools.io/Set-DbaAgentJob", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJob sql1 -Job Job1 -Disabled\r\n\r\nChanges the job to disabled\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJob sql1 -Job Job1 -OwnerLogin user1\r\n\r\nChanges the owner of the job\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJob -SqlInstance sql1 -Job Job1 -EventLogLevel OnSuccess\r\n\r\nChanges the job and sets the notification to write to the Windows Application event log on success\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJob -SqlInstance sql1 -Job Job1 -EmailLevel OnFailure -EmailOperator dba\r\n\r\nChanges the job and sets the notification to send an e-mail to the e-mail operator\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJob -SqlInstance sql1 -Job Job1, Job2, Job3 -Enabled\r\n\r\nChanges multiple jobs to enabled\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job Job1, Job2, Job3 -Enabled\r\n\r\nChanges multiple jobs to enabled on multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJob -SqlInstance sql1 -Job Job1 -Description \u0027Just another job\u0027 -Whatif\r\n\r\nDoesn\u0027t Change the job but shows what would happen.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job \u0027Job One\u0027 -Description \u0027Job One\u0027\r\n\r\nChanges a job with the name \"Job1\" on multiple servers to have another description\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | Set-DbaAgentJob -Job Job1 -Description \u0027Job One\u0027\r\n\r\nChanges a job with the name \"Job1\" on multiple servers to have another description using pipe line\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaAgentJobOutputFile", "Description": "Sets the Output File for a step of an agent job with the Job Names and steps provided dynamically if required", "Synopsis": "Set the output file for a step within an Agent job.", "Name": "Set-DbaAgentJobOutputFile", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJobOutputFile -SqlInstance SERVERNAME -JobName \u0027The Agent Job\u0027 -OutPutFile \r\nE:\\Logs\\AgentJobStepOutput.txt\r\n\r\nSets the Job step for The Agent job on SERVERNAME to E:\\Logs\\AgentJobStepOutput.txt\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaAgentJobStep", "Description": "Set-DbaAgentJobStep updates a job step in the SQL Server Agent with parameters supplied.", "Tags": [ "Agent", "Job", "Job Step" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Set-DbaAgentJobStep updates a job step.", "Name": "Set-DbaAgentJobStep", "Links": "https://dbatools.io/Set-DbaAgentJobStep", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1 -NewName Step2\r\n\r\nChanges the name of the step in \"Job1\" with the name Step1 to Step2\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1 -Database msdb\r\n\r\nChanges the database of the step in \"Job1\" with the name Step1 to msdb\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJobStep -SqlInstance sql1 -Job Job1, Job2 -StepName Step1 -Database msdb\r\n\r\nChanges job steps in multiple jobs with the name Step1 to msdb\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1, Job2 -StepName Step1 -Database msdb\r\n\r\nChanges job steps in multiple jobs on multiple servers with the name Step1 to msdb\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1 -StepName Step1 -Database msdb\r\n\r\nChanges the database of the step in \"Job1\" with the name Step1 to msdb for multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | Set-DbaAgentJobStep -Job Job1 -StepName Step1 -Database msdb\r\n\r\nChanges the database of the step in \"Job1\" with the name Step1 to msdb for multiple servers using pipeline\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaAgentSchedule", "Description": "Set-DbaAgentSchedule will help update a schedule for a job. It does not attach the schedule to a job.", "Tags": [ "Agent", "Job", "Job Step" ], "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Set-DbaAgentSchedule updates a schedule in the msdb database.", "Name": "Set-DbaAgentSchedule", "Links": "https://dbatools.io/Set-DbaAgentSchedule", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentSchedule -SqlInstance sql1 -Job Job1 -ScheduleName daily -Enabled\r\n\r\nChanges the schedule for Job1 with the name \u0027daily\u0027 to enabled\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentSchedule -SqlInstance sql1 -Job Job1 -ScheduleName daily -NewName weekly -FrequencyType Weekly \r\n-FrequencyInterval Monday, Wednesday, Friday\r\n\r\nChanges the schedule for Job1 with the name daily to have a new name weekly\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentSchedule -SqlInstance sql1 -Job Job1, Job2, Job3 -ScheduleName daily -StartTime \u0027230000\u0027\r\n\r\nChanges the start time of the schedule for Job1 to 11 PM for multiple jobs\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaAgentSchedule -SqlInstance sql1, sql2, sql3 -Job Job1 -ScheduleName daily -Enabled\r\n\r\nChanges the schedule for Job1 with the name daily to enabled on multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | Set-DbaAgentSchedule -Job Job1 -ScheduleName \u0027daily\u0027 -Enabled\r\n\r\nChanges the schedule for Job1 with the name \u0027daily\u0027 to enabled on multiple servers using pipe line\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaCmConnection", "Description": "Configures a connection object for use in remote computer management.\nThis function will either create new records for computers that have no connection registered so far, or it will configure existing connections if already present.\n\nAs such it can be handy in making bulk-edits on connections or manually adjusting some settings.", "Synopsis": "Configures a connection object for use in remote computer management.", "Name": "Set-DbaCmConnection", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmConnection sql2014 | Set-DbaCmConnection -ClearBadCredential -UseWindowsCredentials\r\n\r\nRetrieves the already existing connection to sql2014, removes the list of not working credentials and configures it to \r\ndefault to the credentials of the logged on user.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmConnection | Set-DbaCmConnection -RemoveBadCredential $cred\r\n\r\nRemoves the credentials stored in $cred from all connections\u0027 list of \"known to not work\" credentials.\r\nHandy to update changes in privilege.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaCmConnection | Export-Clixml .\\connections.xml\r\n\r\nImport-Clixml .\\connections.xml | Set-DbaCmConnection -ResetConfiguration\r\n\r\nAt first, the current cached connections are stored in an xml file. At a later time - possibly in the profile when \r\nstarting the console again - those connections are imported again and applied again to the connection cache.\r\n\r\nIn this example, the configuration settings will also be reset, since after reimport those will be set to explicit, \r\nrather than deriving them from the global settings.\r\nIn many cases, using the default settings is desirable. For specific settings, use New-DbaCmConnection as part of the \r\nprofile in order to explicitly configure a connection.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaConfig", "Description": "This function creates or changes configuration values.\nThese are used in a larger framework to provide dynamic configuration information outside the PowerShell variable system.", "Tags": "Config", "Author": "Friedrich Weinmann", "Synopsis": "Sets configuration entries.", "Name": "Set-DbaConfig", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaConfig -Name \u0027User\u0027 -Value \"Friedrich\" -Description \"The user under which the show must go on.\"\r\n\r\nCreates a configuration entry named \"User\" with the value \"Friedrich\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaConfig \u0027ConfigLink\u0027 \u0027https://www.example.com/config.xml\u0027 \u0027Company\u0027 -Hidden\r\n\r\nCreates a configuration entry named \"ConfigLink\" in the \"Company\" module with the value \r\n\u0027https://www.example.com/config.xml\u0027.\r\nThis entry is hidden from casual discovery using Get-Config.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaConfig \u0027Network.Firewall\u0027 \u002710.0.0.2\u0027 -Default\r\n\r\nCreates a configuration entry named \"Firewall\" in the \"Network\" module with the value \u002710.0.0.2\u0027\r\nThis is only set, if the setting does not exist yet. If it does, this command will apply no changes.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaDatabaseOwner", "Description": "This function will alter database ownershipt to match a specified login if their current owner does not match the target login. By default, the target login will be \u0027sa\u0027, but the fuction will allow the user to specify a different login for ownership. The user can also apply this to all databases or only to a select list of databases (passed as either a comma separated list or a string array).\n\nBest Practice reference: http://weblogs.sqlteam.com/dang/archive/2008/01/13/Database-Owner-Troubles.aspx", "Author": "Michael Fal (@Mike_Fal), http://mikefal.net", "Synopsis": "Sets database owners with a desired login if databases do not match that owner.", "Name": "Set-DbaDatabaseOwner", "Links": "https://dbatools.io/Set-DbaDatabaseOwner", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDatabaseOwner -SqlInstance localhost\r\n\r\nSets database owner to \u0027sa\u0027 on all databases where the owner does not match \u0027sa\u0027.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDatabaseOwner -SqlInstance localhost -TargetLogin DOMAIN\\account\r\n\r\nTo set the database owner to DOMAIN\\account on all databases where the owner does not match DOMAIN\\account. Note that \r\nTargetLogin must be a valid security principal that exists on the target server.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDatabaseOwner -SqlInstance sqlserver -Database db1, db2\r\n\r\nSets database owner to \u0027sa\u0027 on the db1 and db2 databases if their current owner does not match \u0027sa\u0027.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaDatabaseState", "Description": "Sets some common \"states\" on databases:\n - \"RW\" options (ReadOnly, ReadWrite)\n - \"Status\" options (Online, Offline, Emergency, plus a special \"Detached\")\n - \"Access\" options (SingleUser, RestrictedUser, MultiUser)\n\nReturns an object with SqlInstance, Database, RW, Status, Access, Notes\n\nNotes gets filled when something went wrong setting the state", "Author": "niphlod", "Synopsis": "Sets various options for databases, hereby called \"states\"", "Name": "Set-DbaDatabaseState", "Links": "https://dbatools.io/Set-DbaDatabaseState", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDatabaseState -SqlInstance sqlserver2014a -Database HR -Offline\r\n\r\nSets the HR database as OFFLINE\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDatabaseState -SqlInstance sqlserver2014a -AllDatabases -Exclude HR -Readonly -Force\r\n\r\nSets all databases of the sqlserver2014a instance, except for HR, as READ_ONLY\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabaseState -SqlInstance sql2016 | Where-Object Status -eq \u0027Offline\u0027 | Set-DbaDatabaseState -Online\r\n\r\nFinds all offline databases and sets them to online\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDatabaseState -SqlInstance sqlserver2014a -Database HR -SingleUser\r\n\r\nSets the HR database as SINGLE_USER\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDatabaseState -SqlInstance sqlserver2014a -Database HR -SingleUser -Force\r\n\r\nSets the HR database as SINGLE_USER, dropping all other connections (and rolling back open transactions)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaDatabase -SqlInstance sqlserver2014a -Database HR | Set-DbaDatabaseState -SingleUser -Force\r\n\r\nGets the databases from Get-DbaDatabase, and sets them as SINGLE_USER, dropping all other connections (and rolling back \r\nopen transactions)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaDbCompression", "Description": "This function set the appropriate compression recommendation.\n Remember Uptime is critical, the longer uptime, the more accurate the analysis is.\n You would probably be best if you utilized Get-DbaUptime first, before running this command.\n\nSet-DbaDbCompression script derived from GitHub and the tigertoolbox \n (https://github.com/Microsoft/tigertoolbox/tree/master/Evaluate-Compression-Gains)", "Tags": [ "Compression", "Table", "Database" ], "Author": "Jason Squires (@js_0505, jstexasdba@gmail.com)", "Synopsis": "Sets tables and indexes with preferred compression setting.", "Name": "Set-DbaDbCompression", "Links": "https://dbatools.io/Set-DbaDbCompression", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDbCompression -SqlInstance localhost -MaxRunTime 60 -PercentCompression 25\r\n\r\nSet the compression run time to 60 minutes and will start the compression of tables/indexes\r\n that have a difference of 25% or higher between current and recommended.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDbCompression -SqlInstance ServerA -Database DBName -MaxRunTime 60 -PercentCompression 25 | Out-GridView\r\n\r\nSet the compression run time to 60 minutes and will start the compression of tables/indexes\r\n that have a difference of 25% or higher between current and recommended and the results into a nicely formated \r\nGridView.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$cred = Get-Credential sqladmin\r\n\r\nSet-DbaDbCompression -SqlInstance ServerA -ExcludeDatabase Database -SqlCredential $cred -MaxRunTime 60 \r\n-PercentCompression 25\r\nReturns results of all potential compression options for all databases\r\n with the recommendation of either Page or Row\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$servers = \u0027Server1\u0027,\u0027Server2\u0027\r\n\r\nforeach ($svr in $servers)\r\n{\r\nSet-DbaDbCompression -SqlInstance $svr -MaxRunTime 60 -PercentCompression 25 | Export-Csv -Path \r\nC:\\temp\\CompressionAnalysisPAC.csv -Append\r\n}\r\n\r\nThis produces a full list of all your servers listed and is pushed to a csv for you to analyize.\r\nSet the compression run time to 60 minutes and will start the compression of tables/indexes; across all listed servers;\r\nthat have a difference of 25% or higher between current and recommended.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaDbQueryStoreOptions", "Description": "Configure Query Store settings for a specific or multiple databases.", "Tags": "QueryStore", "Author": "Enrico van de Laar ( @evdlaar )", "Synopsis": "Configure Query Store settings for a specific or multiple databases.", "Name": "Set-DbaDbQueryStoreOptions", "Links": "https://dbatools.io/Set-DbaQueryStoreOptions", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDbQueryStoreOptions -SqlInstance ServerA\\SQL -State ReadWrite -FlushInterval 600 -CollectionInterval 10 \r\n-MaxSize 100 -CaptureMode All -CleanupMode Auto -StaleQueryThreshold 100 -AllDatabases\r\n\r\nConfigure the Query Store settings for all user databases in the ServerA\\SQL Instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDbQueryStoreOptions -SqlInstance ServerA\\SQL -FlushInterval 600\r\n\r\nOnly configure the FlushInterval setting for all Query Store databases in the ServerA\\SQL Instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDbQueryStoreOptions -SqlInstance ServerA\\SQL -Database AdventureWorks -State ReadWrite -FlushInterval 600 \r\n-CollectionInterval 10 -MaxSize 100 -CaptureMode all -CleanupMode Auto -StaleQueryThreshold 100\r\n\r\nConfigure the Query Store settings for the AdventureWorks database in the ServerA\\SQL Instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaDbQueryStoreOptions -SqlInstance ServerA\\SQL -Exclude AdventureWorks -State ReadWrite -FlushInterval 600 \r\n-CollectionInterval 10 -MaxSize 100 -CaptureMode all -CleanupMode Auto -StaleQueryThreshold 100\r\n\r\nConfigure the Query Store settings for all user databases except the AdventureWorks database in the ServerA\\SQL \r\nInstance.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaJobOwner", "Description": "This function will alter SQL Agent Job ownership to match a specified login if their\ncurrent owner does not match the target login. By default, the target login will\nbe \u0027sa\u0027, but the function will allow the user to specify a different login for\nownership. The user can also apply this to all jobs or only to a select list\nof jobs (passed as either a comma separated list or a string array).\n\nBest practice reference: http://sqlmag.com/blog/sql-server-tip-assign-ownership-jobs-sysadmin-account", "Tags": [ "Agent", "Job" ], "Author": "Michael Fal (@Mike_Fal), http://mikefal.net", "Synopsis": "Sets SQL Agent job owners with a desired login if jobs do not match that owner.", "Name": "Set-DbaJobOwner", "Links": "https://dbatools.io/Set-DbaJobOwner", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaJobOwner -SqlInstance localhost\r\n\r\nSets SQL Agent Job owner to sa on all jobs where the owner does not match sa.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaJobOwner -SqlInstance localhost -Login DOMAIN\\account\r\n\r\nSets SQL Agent Job owner to sa on all jobs where the owner does not match \u0027DOMAIN\\account\u0027. Note\r\nthat Login must be a valid security principal that exists on the target server.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaJobOwner -SqlInstance localhost -Job job1, job2\r\n\r\nSets SQL Agent Job owner to \u0027sa\u0027 on the job1 and job2 jobs if their current owner does not match \u0027sa\u0027.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e\u0027sqlserver\u0027,\u0027sql2016\u0027 | Set-DbaJobOwner\r\n\r\nSets SQL Agent Job owner to sa on all jobs where the owner does not match sa on both sqlserver and sql2016.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaMaxDop", "Description": "Uses the Test-DbaMaxDop command to get the recommended value if -MaxDop parameter is not specified.\n\nThese are just general recommendations for SQL Server and are a good starting point for setting the \"max degree of parallelism\" option.\nYou can set MaxDop database scoped configurations if the server is version 2016.\n\nTHIS CODE IS PROVIDED \"AS IS\", WITH NO WARRANTIES.", "Author": "Claudio Silva (@claudioessilva)", "Synopsis": "Sets SQL Server max dop then displays information relating to SQL Server Max DOP configuration settings. Works on SQL Server 2005-2016.", "Name": "Set-DbaMaxDop", "Links": "https://dbatools.io/Set-DbaMaxDop", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaMaxDop -SqlInstance sql2008, sql2012\r\n\r\nSet recommended Max DOP setting for servers sql2008 and sql2012.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaMaxDop -SqlInstance sql2014 -MaxDop 4\r\n\r\nSet Max DOP setting to 4 for server sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMaxDop -SqlInstance sql2008 | Set-DbaMaxDop\r\n\r\nGet Max DOP recommended setting from Test-DbaMaxDop and applies to sql2008 instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaMaxDop -SqlInstance sql2016 -Database db1\r\n\r\nSet recommended Max DOP setting database db1 on server sql2016.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaMaxDop -SqlInstance sql2016 -AllDatabases\r\n\r\nSet recommended Max DOP setting for all databases on server sql2016.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaMaxMemory", "Description": "Sets SQL Server max memory then displays information relating to SQL Server Max Memory configuration settings. \n\nInspired by Jonathan Kehayias\u0027s post about SQL Server Max memory (http://bit.ly/sqlmemcalc), this uses a formula to \ndetermine the default optimum RAM to use, then sets the SQL max value to that number.\n\nJonathan notes that the formula used provides a *general recommendation* that doesn\u0027t account for everything that may \nbe going on in your specific environment.", "Synopsis": "Sets SQL Server \u0027Max Server Memory\u0027 configuration setting to a new value then displays information this setting.", "Name": "Set-DbaMaxMemory", "Links": "https://dbatools.io/Set-DbaMaxMemory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaMaxMemory sqlserver1\r\n\r\nSet max memory to the recommended MB on just one server named \"sqlserver1\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaMaxMemory -SqlInstance sqlserver1 -MaxMB 2048\r\n\r\nExplicitly max memory to 2048 MB on just one server, \"sqlserver1\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sqlserver | Test-DbaMaxMemory | Where-Object { $_.SqlMaxMB -gt $_.TotalMB } \r\n| Set-DbaMaxMemory\r\n\r\nFind all servers in SQL Server Central Management server that have Max SQL memory set to higher than the total memory \r\nof the server (think 2147483647), then pipe those to Set-DbaMaxMemory and use the default recommendation.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaNetworkCertificate", "Description": "Sets the network certificate for SQL Server instance. This setting is found in Configuration Manager.\n\nThis command also grants read permissions for the service account on the certificate\u0027s private key.\n\nReferences:\nhttp://sqlmag.com/sql-server/7-steps-ssl-encryption\nhttps://azurebi.jppp.org/2016/01/23/using-lets-encrypt-certificates-for-secure-sql-server-connections/\nhttps://blogs.msdn.microsoft.com/sqlserverfaq/2016/09/26/creating-and-registering-ssl-certificates/", "Tags": "Certificate", "Synopsis": "Sets the network certificate for SQL Server instance", "Name": "Set-DbaNetworkCertificate", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eNew-DbaComputerCertificate | Set-DbaNetworkCertificate -SqlInstance localhost\\SQL2008R2SP2\r\n\r\nCreates and imports a new certificate signed by an Active Directory CA on localhost then sets the network certificate \r\nfor the SQL2008R2SP2 to that newly created certificate.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaNetworkCertificate -SqlInstance sql1\\SQL2008R2SP2 -Thumbprint 1223FB1ACBCA44D3EE9640F81B6BA14A92F3D6E2\r\n\r\nSets the network certificate for the SQL2008R2SP2 instance to the certificate with the thumbprint of \r\n1223FB1ACBCA44D3EE9640F81B6BA14A92F3D6E2 in LocalMachine\\My on sql1\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaPowerPlan", "Description": "Sets the SQL Server OS\u0027s Power Plan. Defaults to High Performance which is best practice.\n\t\nIf your organization uses a custom power plan that is considered best practice, specify -CustomPowerPlan.\n\t\nReferences:\nhttps://support.microsoft.com/en-us/kb/2207548\nhttp://www.sqlskills.com/blogs/glenn/windows-power-plan-effects-on-newer-intel-processors/", "Synopsis": "Sets the SQL Server OS\u0027s Power Plan.", "Name": "Set-DbaPowerPlan", "Links": "https://dbatools.io/Set-DbaPowerPlan", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaPowerPlan -ComputerName sqlserver2014a\r\n\r\nSets the Power Plan to High Performance. Skips it if its already set.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaPowerPlan -ComputerName sqlcluster -CustomPowerPlan \u0027Maximum Performance\u0027\r\n\r\nSets the Power Plan to the custom power plan called \"Maximum Performance\". Skips it if its already set.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaPrivilege", "Description": "Adds the SQL Service account to local privileges \u0027Lock Pages in Memory\u0027, \u0027Instant File Initialization\u0027, \u0027Logon as Batch\u0027 on one or more computers.\n\nRequires Local Admin rights on destination computer(s).", "Tags": "Privilege", "Author": "Klaas Vandenberghe ( @PowerDBAKlaas )", "Synopsis": "Adds the SQL Service account to local privileges on one or more computers.", "Name": "Set-DbaPrivilege", "Links": "https://dbatools.io/Set-DbaPrivilege", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaPrivilege -ComputerName sqlserver2014a -Type LPIM,IFI\r\n\r\nAdds the SQL Service account(s) on computer sqlserver2014a to the local privileges \u0027SeManageVolumePrivilege\u0027 and \r\n\u0027SeLockMemoryPrivilege\u0027.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027 | Set-DbaPrivilege -Type IFI\r\n\r\nAdds the SQL Service account(s) on computers sql1, sql2 and sql3 to the local privilege \u0027SeManageVolumePrivilege\u0027.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaSpConfigure", "Description": "This function changes the configured value for sp_configure settings. If the setting is dynamic this setting will be used, otherwise the user will be warned that a restart of SQL is required.\nThis is designed to be safe and will not allow for configurations to be set outside of the defined configuration min and max values. \nWhile it is possible to set below the min, or above the max this can cause serious problems with SQL Server (including startup failures), and so is not permitted.", "Tags": "SpConfigure", "Author": "Nic Cain, https://sirsql.net/", "Synopsis": "Changes the server level system configuration (sys.configuration/sp_configure) value for a given configuration", "Name": "Set-DbaSpConfigure", "Links": "https://dbatools.io/Set-DbaSpConfigure", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaSpConfigure -SqlInstance localhost -ConfigName ScanForStartupProcedures -value 1\r\n\r\nAdjusts the Scan for startup stored procedures configuration value to 1 and notifies the user that this requires a SQL \r\nrestart to take effect\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaSpConfigure -SqlInstance localhost -ConfigName XPCmdShellEnabled -value 1\r\n\r\nAdjusts the xp_cmdshell configuation value to 1.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaSpConfigure -SqlInstance localhost -ConfigName XPCmdShellEnabled -value 1 -WhatIf\r\n\r\nReturns information on the action that would be performed. No actual change will be made.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaSpn", "Description": "This function will connect to Active Directory and search for an account. If the account is found, it will attempt to add an SPN. Once the SPN\nis added, the function will also set delegation to that service, unless -NoDelegation is specified. In order to run this function, the credential you provide must have write\naccess to Active Directory.\n\nNote: This function supports -WhatIf", "Tags": "SPN", "Author": "Drew Furgiuele (@pittfurg), http://www.port1433.com", "Synopsis": "Sets an SPN for a given service account in active directory (and also enables delegation to the same SPN by default)", "Name": "Set-DbaSpn", "Links": "https://dbatools.io/Set-DbaSpn", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account\r\n\r\nConnects to Active Directory and adds a provided SPN to the given account.\r\n\r\nSet-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account -Silent\r\n\r\nConnects to Active Directory and adds a provided SPN to the given account, suppressing all error messages and throw \r\nexceptions that can be caught instead\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account -Credential (Get-Credential)\r\n\r\nConnects to Active Directory and adds a provided SPN to the given account. Uses alternative account to connect to AD.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account -NoDelegation\r\n\r\nConnects to Active Directory and adds a provided SPN to the given account, without the delegation.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSpn -ComputerName sql2016 | Where { $_.isSet -eq $false } | Set-DbaSpn\r\n\r\nSets all missing SPNs for sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSpn -ComputerName sql2016 | Where { $_.isSet -eq $false } | Set-DbaSpn -WhatIf\r\n\r\nDisplays what would happen trying to set all missing SPNs for sql2016\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaStartupParameter", "Description": "Modifies the startup parameters for a specified SQL Server Instance\n\nFor full details of what each parameter does, please refer to this MSDN article - https://msdn.microsoft.com/en-us/library/ms190737(v=sql.105).aspx", "Author": "Stuart Moore (@napalmgram), stuart-moore.com", "Synopsis": "Sets the Startup Parameters for a SQL Server instance", "Name": "Set-DbaStartupParameter", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaStartupParameter -SqlInstance server1\\instance1 -SingleUser\r\n\r\nWill configure the SQL Instance server1\\instance1 to startup up in Single User mode at next startup\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaStartupParameter -SqlInstance sql2016 -IncreasedExtents\r\n\r\nWill configure the SQL Instance sql2016 to IncreasedExtents = True (-E)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaStartupParameter -SqlInstance sql2016 -IncreasedExtents:$false -WhatIf\r\n\r\nShows what would happen if you attempted to configure the SQL Instance sql2016 to IncreasedExtents = False (no -E)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaStartupParameter -SqlInstance server1\\instance1 -SingleUser -TraceFlags 8032,8048\r\n\r\nThis will appened Trace Flags 8032 and 8048 to the startup parameters\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaStartupParameter -SqlInstance sql2016 -SingleUser:$false -TraceFlagsOverride\r\n\r\nThis will remove all trace flags and set SinguleUser to false\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaStartupParameter -SqlInstance server1\\instance1 -SingleUser -TraceFlags 8032,8048 -TraceFlagsOverride\r\n\r\nThis will set Trace Flags 8032 and 8048 to the startup parameters, removing any existing Trace Flags\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e$StartupConfig = Get-DbaStartupParameter -SqlInstance server1\\instance1\r\n\r\nSet-DbaStartupParameter -SqlInstance server1\\instance1 -SingleUser -NoLoggingToWinEvents\r\n#Restart your SQL instance with the tool of choice\r\n#Do Some work\r\nSet-DbaStartupParameter -SqlInstance server1\\instance1 -StartUpConfig $StartUpConfig\r\n#Restart your SQL instance with the tool of choice and you\u0027re back to normal\r\n\r\nIn this example we take a copy of the existing startup configuration of server1\\instance1\r\n\r\nWe then change the startup parameters ahead of some work\r\n\r\nAfter the work has been completed, we can push the original startup parameters back to server1\\instance1 and resume \r\nnormal operation\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaTcpPort", "Description": "This function changes the TCP port used by the specified SQL Server.", "Author": "Hansson7707@gmail.com, @H0s0n77", "Synopsis": "Changes the TCP port used by the specified SQL Server.", "Name": "Set-DbaTcpPort", "Links": "https://dbatools.io/Set-DbaTcpPort", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaTcpPort -SqlInstance SqlInstance2014a -Port 1433\r\n\r\nSets the port number 1433 for allips on the default instance on SqlInstance2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaTcpPort -SqlInstance winserver\\sqlexpress -IpAddress 192.168.1.22 -Port 1433\r\n\r\nSets the port number 1433 for IP 192.168.1.22 on the sqlexpress instance on winserver\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaTcpPort -SqlInstance \u0027SQLDB2014A\u0027 ,\u0027SQLDB2016B\u0027 -port 1337\r\n\r\nSets the port number 1337 for ALLIP\u0027s on SqlInstance SQLDB2014A and SQLDB2016B\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Set-DbaTempDbConfiguration", "Description": "Calculates tempdb size and file configurations based on passed parameters, calculated values, and Microsoft best practices. User must declare SQL Server to be configured and total data file size as mandatory values. Function then calculates the number of data files based on logical cores on the target host and create evenly sized data files based on the total data size declared by the user, with a log file 25% of the total data file size.\n\nOther parameters can adjust the settings as the user desires (such as different file paths, number of data files, and log file size). No functions that shrink or delete data files are performed. If you wish to do this, you will need to resize tempdb so that it is \"smaller\" than what the function will size it to before running the function.", "Author": "Michael Fal (@Mike_Fal), http://mikefal.net", "Synopsis": "Sets tempdb data and log files according to best practices.", "Name": "Set-DbaTempDbConfiguration", "Links": "https://dbatools.io/Set-DbaTempDbConfiguration", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaTempDbConfiguration -SqlInstance localhost -DataFileSizeMB 1000\r\n\r\nCreates tempdb with a number of data files equal to the logical cores where each file is equal to 1000MB divided by the \r\nnumber of logical cores, with a log file of 250MB.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaTempDbConfiguration -SqlInstance localhost -DataFileSizeMB 1000 -DataFileCount 8\r\n\r\nCreates tempdb with 8 data files, each one sized at 125MB, with a log file of 250MB.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaTempDbConfiguration -SqlInstance localhost -DataFileSizeMB 1000 -OutputScriptOnly\r\n\r\nProvides a SQL script output to configure tempdb according to the passed parameters.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaTempDbConfiguration -SqlInstance localhost -DataFileSizeMB 1000 -DisableGrowth\r\n\r\nDisables the growth for the data and log files.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eSet-DbaTempDbConfiguration -SqlInstance localhost -DataFileSizeMB 1000 -OutputScriptOnly\r\n\r\nReturns the T-SQL script representing tempdb configuration.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Show-DbaDatabaseList", "Description": "Shows a list of databases in a GUI. Returns a string holding the name of the selected database. Hitting cancel returns null.", "Synopsis": "Shows a list of databases in a GUI.", "Name": "Show-DbaDatabaseList", "Links": "https://dbatools.io/Show-DbaDatabaseList", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eShow-DbaDatabaseList -SqlInstance sqlserver2014a\r\n\r\nShows a GUI list of databases using Windows Authentication to connect to the SQL Server. Returns a string of the \r\nselected database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eShow-DbaDatabaseList -Source sqlserver2014a -SqlCredential $cred\r\n\r\nShows a GUI list of databases using SQL credentials to connect to the SQL Server. Returns a string of the selected \r\ndatabase.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Show-DbaServerFileSystem", "Description": "Similar to the remote file system popup you see when browsing a remote SQL Server in SQL Server Management Studio, this function allows you to traverse the remote SQL Server\u0027s file structure.\n\nShow-DbaServerFileSystem uses SQL Management Objects to browse the directories and what you see is limited to the permissions of the account running the command.", "Tags": "Storage", "Synopsis": "Shows file system on remote SQL Server in a local GUI and returns the selected directory name", "Name": "Show-DbaServerFileSystem", "Links": "https://dbatools.io/Show-DbaServerFileSystem", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eShow-DbaServerFileSystem -SqlInstance sqlserver2014a\r\n\r\nShows a list of databases using Windows Authentication to connect to the SQL Server. Returns a string of the selected \r\npath.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eShow-DbaServerFileSystem -Source sqlserver2014a -SqlCredential $cred\r\n\r\nShows a list of databases using SQL credentials to connect to the SQL Server. Returns a string of the selected path.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Start-DbaMigration", "Description": "Start-DbaMigration consolidates most of the migration tools in dbatools into one command. This is useful when you\u0027re looking to migrate entire instances. It less flexible than using the underlying functions. Think of it as an easy button. It migrates:\n\nAll user databases to exclude support databases such as ReportServerTempDB (Use -IncludeSupportDbs for this). Use -NoDatabases to skip.\nAll logins. Use -NoLogins to skip.\nAll database mail objects. Use -NoDatabaseMail\nAll credentials. Use -NoCredentials to skip.\nAll objects within the Job Server (SQL Agent). Use -NoAgentServer to skip.\nAll linked servers. Use -NoLinkedServers to skip.\nAll groups and servers within Central Management Server. Use -NoCentralManagementServer to skip.\nAll SQL Server configuration objects (everything in sp_configure). Use -NoSpConfigure to skip.\nAll user objects in system databases. Use -NoSysDbUserObjects to skip.\nAll system triggers. Use -NoSystemTriggers to skip.\nAll system backup devices. Use -NoBackupDevices to skip.\nAll Audits. Use -NoAudits to skip.\nAll Endpoints. Use -NoEndpoints to skip.\nAll Extended Events. Use -NoExtendedEvents to skip.\nAll Policy Management objects. Use -NoPolicyManagement to skip.\nAll Resource Governor objects. Use -NoResourceGovernor to skip.\nAll Server Audit Specifications. Use -NoServerAuditSpecifications to skip.\nAll Custom Errors (User Defined Messages). Use -NoCustomErrors to skip.\nCopies All Data Collector collection sets. Does not configure the server. Use -NoDataCollector to skip.\n\nThis script provides the ability to migrate databases using detach/copy/attach or backup/restore. SQL Server logins, including passwords, SID and database/server roles can also be migrated. In addition, job server objects can be migrated and server configuration settings can be exported or migrated. This script works with named instances, clusters and SQL Express.\n\nBy default, databases will be migrated to the destination SQL Server\u0027s default data and log directories. You can override this by specifying -ReuseSourceFolderStructure. Filestreams and filegroups are also migrated. Safety is emphasized.", "Tags": [ "Migration", "DisasterRecovery", "Backup", "Restore" ], "Author": "Chrissy LeMaire", "Synopsis": "Migrates SQL Server *ALL* databases, logins, database mail profiles/accounts, credentials, SQL Agent objects, linked servers, \nCentral Management Server objects, server configuration settings (sp_configure), user objects in systems databases,\nsystem triggers and backup devices from one SQL Server to another. \n\nFor more granular control, please use one of the -No parameters and use the other functions available within the dbatools module.\n\nAutomatically outputs a transcript to disk.", "Name": "Start-DbaMigration", "Links": "https://dbatools.io/Start-DbaMigration", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eStart-DbaMigration -Source sqlserver\\instance -Destination sqlcluster -DetachAttach\r\n\r\nAll databases, logins, job objects and sp_configure options will be migrated from sqlserver\\instance to sqlcluster. \r\nDatabases will be migrated using the detach/copy files/attach method. Dbowner will be updated. User passwords, SIDs, \r\ndatabase roles and server roles will be migrated along with the login.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eStart-DbaMigration -Verbose -Source sqlcluster -Destination sql2016 -SourceSqlCredential $scred \r\n-ReuseSourceFolderStructure -DestinationSqlCredential $cred -Force -NetworkShare \r\n\\\\fileserver\\share\\sqlbackups\\Migration -BackupRestore\r\n\r\nMigrate databases uses backup/restore. Also migrate logins, database mail, credentials, SQL Agent, Central Management \r\nServer, SQL global configuration.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eStart-DbaMigration -Verbose -Source sqlcluster -Destination sql2016 -NoDatabases -NoLogins\r\n\r\nMigrates everything but logins and databases.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eStart-DbaMigration -Verbose -Source sqlcluster -Destination sql2016 -DetachAttach -Reattach -SetSourceReadonly\r\n\r\nMigrate databases using detach/copy/attach. Reattach at source and set source databases read-only. Also migrates \r\neverything else.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Start-DbaSqlService", "Description": "Starts the SQL Server related services on one or more computers. Will follow SQL Server service dependencies.\n\nRequires Local Admin rights on destination computer(s).", "Author": "Kirill Kravtsov( @nvarscar )", "Synopsis": "Starts SQL Server services on a computer.", "Name": "Start-DbaSqlService", "Links": "https://dbatools.io/Start-DbaSqlService", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eStart-DbaSqlService -ComputerName sqlserver2014a\r\n\r\nStarts the SQL Server related services on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027| Get-DbaSqlService | Start-DbaSqlService\r\n\r\nGets the SQL Server related services on computers sql1, sql2 and sql3 and starts them.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eStart-DbaSqlService -ComputerName sql1,sql2 -Instance MSSQLSERVER\r\n\r\nStarts the SQL Server services related to the default instance MSSQLSERVER on computers sql1 and sql2.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eStart-DbaSqlService -ComputerName $MyServers -Type SSRS\r\n\r\nStarts the SQL Server related services of type \"SSRS\" (Reporting Services) on computers in the variable MyServers.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Stop-DbaProcess", "Description": "This command kills all spids associated with a spid, login, host, program or database.\n\t\nIf you are attempting to kill your own login sessions, the process performing the kills will be skipped.", "Tags": "Processes", "Synopsis": "This command finds and kills SQL Server processes.", "Name": "Stop-DbaProcess", "Links": "https://dbatools.io/Stop-DbaProcess", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaProcess -SqlInstance sqlserver2014a -Login base\\ctrlb, sa\r\n\r\nFinds all processes for base\\ctrlb and sa on sqlserver2014a, then kills them. Uses Windows Authentication to login to \r\nsqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaProcess -SqlInstance sqlserver2014a -SqlCredential $credential -Spids 56, 77\r\n\r\nFinds processes for spid 56 and 57, then kills them. Uses alternative (SQL or Windows) credentials to login to \r\nsqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaProcess -SqlInstance sqlserver2014a -Programs \u0027Microsoft SQL Server Management Studio\u0027\r\n\r\nFinds processes that were created in Microsoft SQL Server Management Studio, then kills them.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaProcess -SqlInstance sqlserver2014a -Hosts workstationx, server100\r\n\r\nFinds processes that were initiated by hosts (computers/clients) workstationx and server 1000, then kills them.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaProcess -SqlInstance sqlserver2014 -Database tempdb -WhatIf\r\n\r\nShows what would happen if the command were executed.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaProcess -SqlInstance sql2016 -Programs \u0027dbatools PowerShell module - dbatools.io\u0027 | Stop-DbaProcess\r\n\r\nFinds processes that were created with dbatools, then kills them.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Stop-DbaSqlService", "Description": "Stops the SQL Server related services on one or more computers. Will follow SQL Server service dependencies.\n\nRequires Local Admin rights on destination computer(s).", "Author": "Kirill Kravtsov( @nvarscar )", "Synopsis": "Stops SQL Server services on a computer.", "Name": "Stop-DbaSqlService", "Links": "https://dbatools.io/Stop-DbaSqlService", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaSqlService -ComputerName sqlserver2014a\r\n\r\nStops the SQL Server related services on computer sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e\u0027sql1\u0027,\u0027sql2\u0027,\u0027sql3\u0027| Get-DbaSqlService | Stop-DbaSqlService\r\n\r\nGets the SQL Server related services on computers sql1, sql2 and sql3 and stops them.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaSqlService -ComputerName sql1,sql2 -Instance MSSQLSERVER\r\n\r\nStops the SQL Server services related to the default instance MSSQLSERVER on computers sql1 and sql2.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaSqlService -ComputerName $MyServers -Type SSRS\r\n\r\nStops the SQL Server related services of type \"SSRS\" (Reporting Services) on computers in the variable MyServers.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eStop-DbaSqlService -ComputerName sql1 -Type Engine -Force\r\n\r\nStops SQL Server database engine services on sql1 forcing dependent SQL Server Agent services to stop as well.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Sync-DbaSqlLoginPermission", "Description": "Syncs only SQL Server login permissions, roles, etc. Does not add or drop logins. If a matching login does not exist on the destination, the login will be skipped. Credential removal is not currently supported for this operation.", "Tags": [ "Migration", "Login" ], "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Copies SQL login permission from one server to another.", "Name": "Sync-DbaSqlLoginPermission", "Links": "https://dbatools.io/Sync-DbaSqlLoginPermission", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eSync-DbaSqlLoginPermission -Source sqlserver2014a -Destination sqlcluster\r\n\r\nSyncs only SQL Server login permissions, roles, etc. Does not add or drop logins or users. To copy logins and their \r\npermissions, use Copy-SqlLogin.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eSync-DbaSqlLoginPermission -Source sqlserver2014a -Destination sqlcluster -Exclude realcajun \r\n-SourceSqlCredential $scred -DestinationSqlCredential $dcred\r\n\r\nCopies all login permissions except for realcajun using SQL Authentication to connect to each server. If a login \r\nalready exists on the destination, the permissions will not be migrated.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eSync-DbaSqlLoginPermission -Source sqlserver2014a -Destination sqlcluster -Login realcajun, netnerds\r\n\r\nCopies permissions ONLY for logins netnerds and realcajun.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaCmConnection", "Description": "Tests over which paths a computer can be managed.\n\nThis function tries out the connectivity for:\n - Cim over WinRM\n - Cim over DCOM\n - Wmi\n - PowerShellRemoting\nResults will be written to the connectivity cache and will cause Get-DbaCmObject and Invoke-DbaCmMethod to connect using the way most likely to succeed. This way, it is likely the other commands will take less time to execute. These others too cache their results, in order to dynamically update connection statistics.\n\nThis function ignores global configuration settings limiting which protocols may be used.", "Tags": "ComputerManagement", "Author": "Fred Winmann (@FredWeinmann)", "Synopsis": "Tests over which paths a computer can be managed.", "Name": "Test-DbaCmConnection", "Links": "https://dbatools.io/Test-DbaCmConnection", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaCmConnection -ComputerName sql2014\r\n\r\nPerforms a full-spectrum connection test against the computer sql2014. The results will be reported and registered. \r\nFuture calls from Get-DbaCmObject will recognize the results and optimize the query.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaCmConnection -ComputerName sql2014 -Credential $null -Type CimDCOM, CimRM\r\n\r\nThis test will run a connectivity test of CIM over DCOM and CIM over WinRM against the computer sql2014 using Windows \r\nAuthentication.\r\n\r\nThe results will be reported and registered. Future calls from Get-DbaCmObject will recognize the results and optimize \r\nthe query.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaConnection", "Description": "Tests the ability to connect to an SQL Server instance outputting information about the server and instance.", "Tags": [ "CIM", "Test", "Connection" ], "Author": "Chrissy LeMaire", "Synopsis": "Tests the connection to a single instance.", "Name": "Test-DbaConnection", "Links": null, "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaConnection SQL2016\r\n\r\nComputerName : SQL2016\r\nInstanceName : MSSQLSERVER\r\nSqlInstance : sql2016\r\nSqlVersion : 13.0.4001\r\nConnectingAsUser : BASE\\ctrlb\r\nConnectSuccess : True\r\nAuthType : Windows Authentication\r\nAuthScheme : KERBEROS\r\nTcpPort : 1433\r\nIPAddress : 10.2.1.5\r\nNetBiosName : sql2016.base.local\r\nIsPingable : True\r\nPSRemotingAccessible : True\r\nDomainName : base.local\r\nLocalWindows : 10.0.15063.0\r\nLocalPowerShell : 5.1.15063.502\r\nLocalCLR : 4.0.30319.42000\r\nLocalSMOVersion : 13.0.0.0\r\nLocalDomainUser : True\r\nLocalRunAsAdmin : False\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaConnectionAuthScheme", "Description": "By default, this command will return the ConnectName, ServerName, Transport and AuthScheme of the current connection.\n\t\nConnectName is the name you used to connect. ServerName is the name that the SQL Server reports as its @@SERVERNAME which is used to register its SPN. If you were expecting a Kerberos connection and got NTLM instead, ensure ConnectName and ServerName match. \n\nIf -Kerberos or -Ntlm is specified, the $true/$false results of the test will be returned. Returns $true or $false by default for one server. Returns Server name and Results for more than one server.", "Tags": "SPN", "Synopsis": "Returns the transport protocol and authentication scheme of the connection. This is useful to determine if your connection is using Kerberos.", "Name": "Test-DbaConnectionAuthScheme", "Links": "https://dbatools.io/Test-DbaConnectionAuthScheme", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaConnectionAuthScheme -SqlInstance sqlserver2014a, sql2016\r\n\r\nReturns ConnectName, ServerName, Transport and AuthScheme for sqlserver2014a and sql2016.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaConnectionAuthScheme -SqlInstance sqlserver2014a -Kerberos\r\n\r\nReturns $true or $false depending on if the connection is Kerberos or not.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaConnectionAuthScheme -SqlInstance sqlserver2014a -Detailed\r\n\r\nReturns the results of \"SELECT * from sys.dm_exec_connections WHERE session_id = @@SPID\"\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaDatabaseCollation", "Description": "Compares Database Collations to Server Collation", "Synopsis": "Compares Database Collations to Server Collation", "Name": "Test-DbaDatabaseCollation", "Links": "https://dbatools.io/Test-DbaDatabaseCollation", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDatabaseCollation -SqlInstance sqlserver2014a\r\n\r\nReturns server name, databse name and true/false if the collations match for all databases on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDatabaseCollation -SqlInstance sqlserver2014a -Database db1, db2\r\n\r\nReturns server name, databse name and true/false if the collations match for the db1 and db2 databases on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDatabaseCollation -SqlInstance sqlserver2014a, sql2016 -Detailed -Exclude db1\r\n\r\nLots of detailed information for database and server collations for all databases except db1 on sqlserver2014a and \r\nsql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2016 | Test-DbaDatabaseCollation\r\n\r\nReturns db/server collation information for every database on every server listed in the Central Management Server on \r\nsql2016\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaDatabaseCompatibility", "Description": "Compares Database Compatibility level to Server Compatibility", "Synopsis": "Compares Database Compatibility level to Server Compatibility", "Name": "Test-DbaDatabaseCompatibility", "Links": "https://dbatools.io/Test-DbaDatabaseCompatibility", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDatabaseCompatibility -SqlInstance sqlserver2014a\r\n\r\nReturns server name, databse name and true/false if the compatibility level match for all databases on sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDatabaseCompatibility -SqlInstance sqlserver2014a -Database db1, db2\r\n\r\nReturns server name, databse name and true/false if the compatibility level match for the db1 and db2 databases on \r\nsqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDatabaseCompatibility -SqlInstance sqlserver2014a, sql2016 -Detailed -Exclude db1\r\n\r\nLots of detailed information for database and server compatibility level for all databases except db1 on sqlserver2014a \r\nand sql2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2014 | Test-DbaDatabaseCompatibility\r\n\r\nReturns db/server compatibility information for every database on every server listed in the Central Management Server \r\non sql2016\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaDatabaseOwner", "Description": "This function will check all databases on an instance against a SQL login to validate if that\nlogin owns those databases or not. By default, the function will check against \u0027sa\u0027 for\nownership, but the user can pass a specific login if they use something else. Only databases\nthat do not match this ownership will be displayed, but if the -Detailed switch is set all\ndatabases will be shown.\n\nBest Practice reference: http://weblogs.sqlteam.com/dang/archive/2008/01/13/Database-Owner-Troubles.aspx", "Author": "Michael Fal (@Mike_Fal), http://mikefal.net", "Synopsis": "Checks database owners against a login to validate which databases do not match that owner.", "Name": "Test-DbaDatabaseOwner", "Links": "https://dbatools.io/Test-DbaDatabaseOwner", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDatabaseOwner -SqlInstance localhost\r\n\r\nReturns all databases where the owner does not match \u0027sa\u0027.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDatabaseOwner -SqlInstance localhost -TargetLogin \u0027DOMAIN\\account\u0027\r\n\r\nReturns all databases where the owner does not match \u0027DOMAIN\\account\u0027. Note\r\nthat TargetLogin must be a valid security principal that exists on the target server.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaDbCompression", "Description": "This function returns the results of a full table/index compression analysis.\n This function returns the best option to date for either NONE, Page, or Row Compression.\n Remember Uptime is critical, the longer uptime, the more accurate the analysis is.\n You would probably be best if you utilized Get-DbaUptime first, before running this command.\n\nTest-DbaCompression script derived from GitHub and the tigertoolbox \n (https://github.com/Microsoft/tigertoolbox/tree/master/Evaluate-Compression-Gains)\n In the output, you will find the following information:\n Column Percent_Update shows the percentage of update operations on a specific table, index, or partition, \n relative to total operations on that object. The lower the percentage of Updates \n (that is, the table, index, or partition is infrequently updated), the better candidate it is for page compression.\n Column Percent_Scan shows the percentage of scan operations on a table, index, or partition, relative to total \n operations on that object. The higher the value of Scan (that is, the table, index, or partition is mostly scanned), \n the better candidate it is for page compression.\n Column Compression_Type_Recommendation can have four possible outputs indicating where there is most gain, \n if any: \u0027PAGE\u0027, \u0027ROW\u0027, \u0027NO_GAIN\u0027 or \u0027?\u0027. When the output is \u0027?\u0027 this approach could not give a recommendation, \n so as a rule of thumb I would lean to ROW if the object suffers mainly UPDATES, or PAGE if mainly INSERTS, \n but this is where knowing your workload is essential. When the output is \u0027NO_GAIN\u0027 well, that means that according \n to sp_estimate_data_compression_savings no space gains will be attained when compressing, as in the above output example, \n where compressing would grow the affected object.\n \n Note: Note that this script will execute on the context of the current database. \n Also be aware that this may take awhile to execute on large objects, because if the IS locks taken by the \n sp_estimate_data_compression_savings cannot be honored, the SP will be blocked.", "Tags": [ "Compression", "Table", "Database" ], "Author": "Jason Squires (@js_0505, jstexasdba@gmail.com)", "Synopsis": "Returns tables and indexes with preferred compression setting.", "Name": "Test-DbaDbCompression", "Links": "https://dbatools.io/Test-DbaCompression", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaCompression -SqlInstance localhost\r\n\r\nReturns all user database files and free space information for the local host\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaCompression -SqlInstance ServerA -Database DBName | Out-GridView\r\n\r\nReturns results of all potential compression options for a single database \r\n with the recommendation of either Page or Row into and nicely formated GridView\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaCompression -SqlInstance ServerA\r\n\r\nReturns results of all potential compression options for all databases\r\n with the recommendation of either Page or Row\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$cred = Get-Credential sqladmin\r\n\r\nTest-DbaCompression -SqlInstance ServerA -ExcludeDatabase Database -SqlCredential $cred\r\nReturns results of all potential compression options for all databases\r\nwith the recommendation of either Page or Row\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$servers = \u0027Server1\u0027,\u0027Server2\u0027\r\n\r\nforeach ($svr in $servers)\r\n{\r\nTest-DbaCompression -SqlInstance $svr | Export-Csv -Path C:\\temp\\CompressionAnalysisPAC.csv -Append\r\n}\r\n\r\nThis produces a full analysis of all your servers listed and is pushed to a csv for you to \r\nanalyize.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaDiskAlignment", "Description": "Returns $true or $false by default for one server. Returns Server name and IsBestPractice for more than one server.\n\nSpecify -Detailed for additional information which returns some additional optional \"best practice\" columns, which may show false even though you pass the alignment test.\nThis is because your offset is not one of the \"expected\" values that Windows uses, but your disk is still physically aligned.\n\nPlease refer to your storage vendor best practices before following any advice below.\nBy default issues with disk alignment should be resolved by a new installation of Windows Server 2008, Windows Vista, or later operating systems, but verifying disk alignment continues to be recommended as a best practice.\nWhile some versions of Windows use different starting alignments, if you are starting anew 1MB is generally the best practice offset for current operating systems (because it ensures that the partition offset % common stripe unit sizes == 0 )\n\nCaveats:\nDynamic drives (or those provisioned via third party software) may or may not have accurate results when polled by any of the built in tools, see your vendor for details.\nWindows does not have a reliable way to determine stripe unit Sizes. These values are obtained from vendor disk management software or from your SAN administrator.\nSystem drives in versions previous to Windows Server 2008 cannot be aligned, but it is generally not recommended to place SQL Server databases on system drives.", "Tags": "Storage", "Author": "Constantine Kokkinos (https://constantinekokkinos.com, @mobileck)", "Synopsis": "Verifies that your non-dynamic disks are aligned according to physical constraints.", "Name": "Test-DbaDiskAlignment", "Links": "https://dbatools.io/Test-DbaDiskAlignment", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDiskAlignment -ComputerName sqlserver2014a\r\n\r\nTests the disk alignment of a single server named sqlserver2014a\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDiskAlignment -ComputerName sqlserver2014a, sqlserver2014b, sqlserver2014c\r\n\r\nTests the disk alignment of mulitiple servers\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaDiskAllocation", "Description": "Checks all disks on a computer for disk allocation units that match best practice recommendations. If one server is checked, only $true or $false is returned. If multiple servers are checked, each server\u0027s name and an IsBestPractice field are returned.\n\nSpecify -Detailed for details.\n\nReferences:\nhttps://technet.microsoft.com/en-us/library/dd758814(v=sql.100).aspx - \"The performance question here is usually not one of correlation per the formula, but whether the cluster size ..has been explicitly defined at 64 KB, which is a best practice for SQL Server.\"\n\nhttp://tk.azurewebsites.net/2012/08/", "Tags": [ "CIM", "Storage" ], "Synopsis": "Checks all disks on a computer to see if they are formatted with allocation units of 64KB.", "Name": "Test-DbaDiskAllocation", "Links": "https://dbatools.io/Test-DbaDiskAllocation", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDiskAllocation -ComputerName sqlserver2014a\r\n\r\nScans all disks on server sqlserver2014a for best practice allocation unit size.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDiskAllocation -ComputerName sqlserver2014 -Detailed\r\n\r\nScans all disks on server sqlserver2014a for allocation unit size and returns detailed results for each.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaDiskAllocation -ComputerName sqlserver2014a -NoSqlCheck\r\n\r\nScans all disks not hosting SQL Server data or log files on server sqlserver2014a for best practice allocation unit \r\nsize.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaFullRecoveryModel", "Description": "When you switch a database into FULL recovery model, it will behave like a SIMPLE recovery model until a full backup is taken in order to begin a log backup chain.\nThis state is also known as \u0027pseudo-Simple\u0027.\n\nInspired by Paul Randal\u0027s post (http://www.sqlskills.com/blogs/paul/new-script-is-that-database-really-in-the-full-recovery-mode/)", "Tags": [ "DisasterRecovery", "Backup" ], "Author": "Claudio Silva (@ClaudioESSilva)", "Synopsis": "Find if database is really in the Full recovery model or not.", "Name": "Test-DbaFullRecoveryModel", "Links": "https://dbatools.io/Test-DbaFullRecoveryModel", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaFullRecoveryModel -SqlInstance sql2005\r\n\r\nShows all databases which actual configured recovery model is FULL and says if they are really in FULL recovery model \r\nor not\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaFullRecoveryModel -SqlInstance . | Where-Object {$_.ActualRecoveryModel -ne \"FULL\"}\r\n\r\nOnly shows the databases that are in \u0027pseudo-simple\u0027 mode.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaFullRecoveryModel -SqlInstance sql2008 | Sort-Object Server, ActualRecoveryModel -Descending\r\n\r\nShows all databases which actual configured recovery model is FULL and says if they are really in FULL recovery model \r\nor not. Will show in first place the ones that are in \u0027pseudo-simple\u0027 mode.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaIdentityUsage", "Description": "IDENTITY seeds have max values based off of their data type. This module will locate identity columns and report the seed usage.", "Tags": "Identity", "Author": "Brandon Abshire, netnerds.net", "Synopsis": "Displays information relating to IDENTITY seed usage. Works on SQL Server 2008 and above.", "Name": "Test-DbaIdentityUsage", "Links": "https://dbatools.io/Test-DbaIdentityUsage", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaIdentityUsage -SqlInstance sql2008, sqlserver2012\r\n\r\nCheck identity seeds for servers sql2008 and sqlserver2012.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaIdentityUsage -SqlInstance sql2008 -Database TestDB\r\n\r\nCheck identity seeds on server sql2008 for only the TestDB database\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaIdentityUsage -SqlInstance sql2008 -Database TestDB -Threshold 20\r\n\r\nCheck identity seeds on server sql2008 for only the TestDB database, limiting results to 20% utilization of seed range \r\nor higher\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaJobOwner", "Description": "This function will check all SQL Agent Job on an instance against a SQL login to validate if that\nlogin owns those SQL Agent Jobs or not. \n\nBy default, the function will check against \u0027sa\u0027 for ownership, but the user can pass a specific \nlogin if they use something else. \n\nOnly SQL Agent Jobs that do not match this ownership will be displayed, but if the -Detailed \nswitch is set all SQL Agent Jobs will be shown.\n\nBest practice reference: http://sqlmag.com/blog/sql-server-tip-assign-ownership-jobs-sysadmin-account", "Tags": [ "Agent", "Job", "Owner" ], "Author": "Michael Fal (@Mike_Fal), http://mikefal.net", "Synopsis": "Checks SQL Agent Job owners against a login to validate which jobs do not match that owner.", "Name": "Test-DbaJobOwner", "Links": "https://dbatools.io/Test-DbaJobOwner", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaJobOwner -SqlInstance localhost\r\n\r\nReturns all databases where the owner does not match \u0027sa\u0027.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaJobOwner -SqlInstance localhost -Login DOMAIN\\account\r\n\r\nReturns all databases where the owner does not match DOMAIN\\account. Note\r\nthat Login must be a valid security principal that exists on the target server.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaLastBackup", "Description": "Restores all or some of the latest backups and performs a DBCC CHECKDB\n\n1. Gathers information about the last full backups\n2. Restores the backps to the Destination with a new name. If no Destination is specified, the originating SqlServer wil be used.\n3. The database is restored as \"dbatools-testrestore-$databaseName\" by default, but you can change dbatools-testrestore to whatever you would like using -Prefix\n4. The internal file names are also renamed to prevent conflicts with original database\n5. A DBCC CHECKDB is then performed\n6. And the test database is finally dropped", "Tags": [ "DisasterRecovery", "Backup", "Restore" ], "Synopsis": "Quickly and easily tests the last set of full backups for a server", "Name": "Test-DbaLastBackup", "Links": "https://dbatools.io/Test-DbaLastBackup", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLastBackup -SqlInstance sql2016\r\n\r\nDetermines the last full backup for ALL databases, attempts to restore all databases (with a different name and file \r\nstructure), then performs a DBCC CHECKDB\r\n\r\nOnce the test is complete, the test restore will be dropped\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLastBackup -SqlInstance sql2016 -Database master\r\n\r\nDetermines the last full backup for master, attempts to restore it, then performs a DBCC CHECKDB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLastBackup -SqlInstance sql2016 -Database model, master -VerifyOnly\r\n\r\n\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLastBackup -SqlInstance sql2016 -NoCheck -NoDrop\r\n\r\nSkips the DBCC CHECKDB check. This can help speed up the tests but makes it less tested. NoDrop means that the test \r\nrestores will remain on the server.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLastBackup -SqlInstance sql2016 -DataDirectory E:\\bigdrive -LogDirectory L:\\bigdrive -MaxMB 10240\r\n\r\nRestores data and log files to alternative locations and only restores databases that are smaller than 10 GB\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLastBackup -SqlInstance sql2014 -Destination sql2016 -CopyFile\r\n\r\nCopies the backup files for sql2014 databases to sql2016 default backup locations and then attempts restore from there.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLastBackup -SqlInstance sql2014 -Destination sql2016 -CopyFile -CopyPath \"\\\\BackupShare\\TestRestore\\\"\r\n\r\nCopies the backup files for sql2014 databases to sql2016 default backup locations and then attempts restore from there.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaLinkedServerConnection", "Description": "Test each linked server on the instance", "Author": "Thomas LaRock ( https://thomaslarock.com )", "Synopsis": "Test all linked servers from the sql servers passed", "Name": "Test-DbaLinkedServerConnection", "Links": "https://dbatools.io/Test-DbaLinkedServerConnection", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLinkedServerConnection -SqlInstance DEV01\r\n\r\nTest all Linked Servers for the SQL Server instance DEV01\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLinkedServerConnection -SqlInstance sql2016 | Out-File C:\\temp\\results.txt\r\n\r\nTest all Linked Servers for the SQL Server instance sql2016 and output results to file\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaLinkedServerConnection -SqlInstance sql2016, sql2014, sql2012\r\n\r\nTest all Linked Servers for the SQL Server instances sql2016, sql2014 and sql2012\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$servers = \"sql2016\",\"sql2014\",\"sql2012\"\r\n\r\n$servers | Test-DbaLinkedServerConnection -SqlCredential (Get-Credential sqladmin)\r\n\r\nTest all Linked Servers for the SQL Server instances sql2016, sql2014 and sql2012 using SQL login credentials\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$servers | Get-DbaLinkedServer | Test-DbaLinkedServerConnection\r\n\r\nTest all Linked Servers for the SQL Server instances sql2016, sql2014 and sql2012\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaMaxDop", "Description": "Inspired by Sakthivel Chidambaram\u0027s post about SQL Server MAXDOP Calculator (https://blogs.msdn.microsoft.com/sqlsakthi/p/maxdop-calculator-SqlInstance/), \nthis script displays a SQL Server\u0027s: max dop configured, and the calculated recommendation.\n\nFor SQL Server 2016 shows:\n - Instance max dop configured and the calculated recommendation\n - max dop configured per database (new feature)\n\nMore info: \n https://support.microsoft.com/en-us/kb/2806535\n https://blogs.msdn.microsoft.com/sqlsakthi/2012/05/23/wow-we-have-maxdop-calculator-for-sql-server-it-makes-my-job-easier/\n\nThese are just general recommendations for SQL Server and are a good starting point for setting the \"max degree of parallelism\" option.\n\nTHIS CODE IS PROVIDED \"AS IS\", WITH NO WARRANTIES.", "Synopsis": "Displays information relating to SQL Server Max Degree of Paralellism setting. Works on SQL Server 2005-2016.", "Name": "Test-DbaMaxDop", "Links": "https://dbatools.io/Test-DbaMaxDop", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMaxDop -SqlInstance sql2008, sqlserver2012\r\n\r\nGet Max DOP setting for servers sql2008 and sqlserver2012 and also the recommended one.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMaxDop -SqlInstance sql2014 -Detailed\r\n\r\nShows Max DOP setting for server sql2014 with the recommended value. As the -Detailed switch was used will also show \r\nthe \u0027NUMANodes\u0027 and \u0027NumberOfCores\u0027 of each instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMaxDop -SqlInstance sqlserver2016 -Detailed\r\n\r\nGet Max DOP setting for servers sql2016 with the recommended value. As the -Detailed switch was used will also show the \r\n\u0027NUMANodes\u0027 and \u0027NumberOfCores\u0027 of each instance. Because it is an 2016 instance will be shown \u0027InstanceVersion\u0027, \r\n\u0027Database\u0027 and \u0027DatabaseMaxDop\u0027 columns.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaMaxMemory", "Description": "Inspired by Jonathan Kehayias\u0027s post about SQL Server Max memory (http://bit.ly/sqlmemcalc), this script displays a SQL Server\u0027s: \ntotal memory, currently configured SQL max memory, and the calculated recommendation.\n\nJonathan notes that the formula used provides a *general recommendation* that doesn\u0027t account for everything that may be going on in your specific environment.", "Tags": "Memory", "Synopsis": "Calculates the recommended value for SQL Server \u0027Max Server Memory\u0027 configuration setting. Works on SQL Server 2000-2014.", "Name": "Test-DbaMaxMemory", "Links": "https://dbatools.io/Test-DbaMaxMemory", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMaxMemory -SqlInstance sqlcluster,sqlserver2012\r\n\r\nCalculate the \u0027Max Server Memory\u0027 settings for all servers within the SQL Server Central Management Server \"sqlcluster\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMaxMemory -SqlInstance sqlcluster | Where-Object { $_.SqlMaxMB -gt $_.TotalMB } | Set-DbaMaxMemory\r\n\r\nFind all servers in CMS that have Max SQL memory set to higher than the total memory of the server (think 2147483647) \r\nand set it to recommended value.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaMigrationConstraint", "Description": "When you want to migrate from a higher edition to a lower one there are some features that can\u0027t be used.\nThis function will validate if you have any of this features in use and will report to you.\nThe validation will be made ONLY on on SQL Server 2008 or higher using the \u0027sys.dm_db_persisted_sku_features\u0027 dmv.\n\nThis function only validate SQL Server 2008 versions or higher.\nThe editions supported by this function are:\n\t- Enterprise\n\t- Developer\n\t- Evaluation\n\t- Standard\n\t- Express\n\nTake into account the new features introduced on SQL Server 2016 SP1 for all versions. More information at https://blogs.msdn.microsoft.com/sqlreleaseservices/sql-server-2016-service-pack-1-sp1-released/\n\nThe -Database parameter is auto-populated for command-line completion.", "Tags": "Migration", "Author": "Claudio Silva (@ClaudioESSilva)", "Synopsis": "Show if you can migrate the database(s) between the servers.", "Name": "Test-DbaMigrationConstraint", "Links": "https://dbatools.io/Test-DbaMigrationConstraint", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMigrationConstraint -Source sqlserver2014a -Destination sqlcluster\r\n\r\nAll databases on sqlserver2014a will be verified for features in use that can\u0027t be supported on sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMigrationConstraint -Source sqlserver2014a -Destination sqlcluster -SqlCredential $cred\r\n\r\nAll databases will be verified for features in use that can\u0027t be supported on the destination server. SQL credentials \r\nare used to authenticate against sqlserver2014 and Windows Authentication is used for sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaMigrationConstraint -Source sqlserver2014a -Destination sqlcluster -Database db1\r\n\r\nOnly db1 database will be verified for features in use that can\u0027t be supported on the destination server.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaNetworkLatency", "Description": "This function is intended to help measure SQL Server network latency by establishing a connection and executing a simple query. This is a better than a simple ping because it actually creates the connection to the SQL Server and measures the time required for only the entire routine, but the duration of the query as well how long it takes for the results to be returned.\n\nBy default, this command will execute \"SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES\" three times.\n\nIt will then output how long the entire connection and command took, as well as how long *only* the execution of the command took.\n\nThis allows you to see if the issue is with the connection or the SQL Server itself.", "Tags": [ "Performance", "Network" ], "Synopsis": "Tests how long a query takes to return from SQL Server", "Name": "Test-DbaNetworkLatency", "Links": "https://dbatools.io/Test-DbaNetworkLatency", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster\r\n\r\nTests the roundtrip return of \"SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES\" on sqlserver2014a and sqlcluster using \r\nWindows credentials.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaNetworkLatency -SqlInstance sqlserver2014a -SqlCredential $cred\r\n\r\nTests the execution results return of \"SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES\" on sqlserver2014a using SQL \r\ncredentials.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster, sqlserver -Query \"select top 10 * from \r\notherdb.dbo.table\" -Count 10\r\n\r\nTests the execution results return of \"select top 10 * from otherdb.dbo.table\" 10 times on sqlserver2014a, sqlcluster, \r\nand sqlserver using Windows credentials.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaOptimizeForAdHoc", "Description": "When this option is set, plan cache size is further reduced for single-use ad hoc OLTP workload.\n\nMore info: https://msdn.microsoft.com/en-us/library/cc645587.aspx\nhttp://www.sqlservercentral.com/blogs/glennberry/2011/02/25/some-suggested-sql-server-2008-r2-instance-configuration-settings/\n\nThese are just general recommendations for SQL Server and are a good starting point for setting the \"optimize for adhoc workloads\" option.", "Author": "Brandon Abshire, netnerds.net", "Synopsis": "Displays information relating to SQL Server Optimize for AdHoc Workloads setting. Works on SQL Server 2008-2016.", "Name": "Test-DbaOptimizeForAdHoc", "Links": "https://dbatools.io/Test-DbaOptimizeForAdHoc", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaOptimizeForAdHoc -SqlInstance sql2008, sqlserver2012\r\n\r\nGet Optimize for AdHoc Workloads setting for servers sql2008 and sqlserver2012 and also the recommended one.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaPowerPlan", "Description": "Checks the Power Plan settings on a computer against best practices recommendations. If one server is checked, only $true or $false is returned. If multiple servers are checked, each server\u0027s name and an IsBestPractice field are returned.\n\nSpecify -Detailed for details.\n\nReferences:\nhttps://support.microsoft.com/en-us/kb/2207548\nhttp://www.sqlskills.com/blogs/glenn/windows-power-plan-effects-on-newer-intel-processors/", "Synopsis": "Checks the Power Plan settings for compliance with best practices, which recommend High Performance for SQL Server.", "Name": "Test-DbaPowerPlan", "Links": "https://dbatools.io/Test-DbaPowerPlan", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaPowerPlan -ComputerName sqlserver2014a\r\n\r\nChecks the Power Plan settings for sqlserver2014a and indicates whether or not it complies with best practices.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaPowerPlan -ComputerName sqlserver2014a -CustomPowerPlan \u0027Maximum Performance\u0027\r\n\r\nChecks the Power Plan settings for sqlserver2014a and indicates whether or not it is set to the custom plan \"Maximum \r\nPerformance\".\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaPowerPlan -ComputerName sqlserver2014a -Detailed\r\n\r\nReturns detailed information about the Power Plans on sqlserver2014a.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaServerName", "Description": "When a SQL Server\u0027s host OS is renamed, the SQL Server should be as well. This helps with Availability Groups and Kerberos.\n\nThis command helps determine if your OS and SQL Server names match, and thus, if a rename is required.\n\nIt then checks conditions that would prevent a rename like database mirroring and replication.\n\nhttps://www.mssqltips.com/sqlservertip/2525/steps-to-change-the-server-name-for-a-sql-server-machine/", "Tags": "SPN", "Synopsis": "Tests to see if it\u0027s possible to easily rename the server at the SQL Server instance level, or if it even needs to be changed.", "Name": "Test-DbaServerName", "Links": "https://dbatools.io/Test-DbaServerName", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaServerName -SqlInstance sqlserver2014a\r\n\r\nReturns ServerInstanceName, SqlServerName, IsEqual and RenameRequired for sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaServerName -SqlInstance sqlserver2014a, sql2016\r\n\r\nReturns ServerInstanceName, SqlServerName, IsEqual and RenameRequired for sqlserver2014a and sql2016.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaServerName -SqlInstance sqlserver2014a, sql2016 -Detailed\r\n\r\nReturns ServerInstanceName, SqlServerName, IsEqual and RenameRequired for sqlserver2014a and sql2016.\r\n\r\nIf a Rename is required, it will also show Updatable, and Reasons if the servername is not updatable.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaSpn", "Description": "This function is designed to take in a server name(s) and attempt to determine required SPNs. It was initially written to mimic the (previously)\nbroken functionality of the Microsoft Kerberos Configuration manager and SQL Server 2016. The functon will connect to a remote server and,\nthrough WMI, discover all running intances of SQL Server. For any instances with TCP/IP enabled, the script will determine which port(s)\nthe instances are listening on and generate the required SPNs. For named instances NOT using dynamic ports, the script will generate a port-\nbased SPN for those instances as well. At a minimum, the script will test a base, port-less SPN for each instance discovered.\n\nOnce the required SPNs are generated, the script will connect to Active Directory and search for any of the SPNs (if any) that are already\nset.\n\nThe function will return a custom object(s) that contains the server name checked, the instance name discovered, the account the service is\nrunning under, and what the \"required\" SPN should be. It will also return a boolean property indicating if the SPN is set in Active Directory\nor not.", "Tags": [ "SQLWMI", "SPN" ], "Author": "Drew Furgiuele (@pittfurg), http://www.port1433.com", "Synopsis": "Test-DbaSpn will determine what SPNs *should* be set for a given server (and any instances of SQL running on it) and return\nwhether the SPNs are set or not.", "Name": "Test-DbaSpn", "Links": "https://dbatools.io/Test-DbaSpn", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSpn -ComputerName SQLSERVERA -Credential (Get-Credential)\r\n\r\nConnects to a computer (SQLSERVERA) and queries WMI for all SQL instances and return \"required\" SPNs. It will then take \r\neach SPN it generates\r\nand query Active Directory to make sure the SPNs are set.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSpn -ComputerName SQLSERVERA,SQLSERVERB -Credential (Get-Credential)\r\n\r\nConnects to multiple computers (SQLSERVERA, SQLSERVERB) and queries WMI for all SQL instances and return \"required\" \r\nSPNs. \r\nIt will then take each SPN it generates and query Active Directory to make sure the SPNs are set.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSpn -ComputerName SQLSERVERC -Credential (Get-Credential)\r\n\r\nConnects to a computer (SQLSERVERC) on a specified and queries WMI for all SQL instances and return \"required\" SPNs. \r\nIt will then take each SPN it generates and query Active Directory to make sure the SPNs are set. Note that the \r\ncredential you pass must\r\nhave be a valid login with appropriate rights on the domain\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaSqlManagementObject", "Description": "The Test-DbaSqlManagementObject returns True if the Version is on the computer, and False if it does not exist.", "Tags": "SMO", "Author": "Ben Miller (@DBAduck - http://dbaduck.com)", "Synopsis": "Tests to see if the SMO version specified exists on the computer.", "Name": "Test-DbaSqlManagementObject", "Links": "https://dbatools.io/Test-DbaSqlManagementObject", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSqlManagementObject -VersionNumber 13\r\n\r\nReturns True if the version exists, if it does not exist it will return False\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaSqlPath", "Description": "Uses master.dbo.xp_fileexist to determine if a file or directory exists.", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Tests if file or directory exists from the perspective of the SQL Server service account.", "Name": "Test-DbaSqlPath", "Links": "https://dbatools.io/Test-DbaSqlPath", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaSqlPath -SqlInstance sqlcluster -Path L:\\MSAS12.MSSQLSERVER\\OLAP\r\n\r\nTests whether the service account running the \"sqlcluster\" SQL Server instance can access L:\\MSAS12.MSSQLSERVER\\OLAP. \r\nLogs into sqlcluster using Windows credentials.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$credential = Get-Credential\r\n\r\nTest-DbaSqlPath -SqlInstance sqlcluster -SqlCredential $credential -Path L:\\MSAS12.MSSQLSERVER\\OLAP\r\n\r\nTests whether the service account running the \"sqlcluster\" SQL Server instance can access L:\\MSAS12.MSSQLSERVER\\OLAP. \r\nLogs into sqlcluster using SQL authentication.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaTempDbConfiguration", "Description": "Evaluates tempdb against a set of rules to match best practices. The rules are:\n\n* TF 1118 enabled - Is Trace Flag 1118 enabled (See KB328551).\n* File Count - Does the count of data files in tempdb match the number of logical cores, up to 8?\n* File Growth - Are any files set to have percentage growth? Best practice is all files have an explicit growth value.\n* File Location - Is tempdb located on the C:\\? Best practice says to locate it elsewhere.\n* File MaxSize Set (optional) - Do any files have a max size value? Max size could cause tempdb problems if it isn\u0027t allowed to grow.\n\nOther rules can be added at a future date.", "Tags": [ "tempdb", "configuration" ], "Author": "Michael Fal (@Mike_Fal), http://mikefal.net", "Synopsis": "Evaluates tempdb against several rules to match best practices.", "Name": "Test-DbaTempDbConfiguration", "Links": "https://dbatools.io/Test-DbaTempDbConfiguration", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaTempDbConfiguration -SqlInstance localhost\r\n\r\nChecks tempdb on the localhost machine.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaTempDbConfiguration -SqlInstance localhost | Select-Object *\r\n\r\nChecks tempdb on the localhost machine. All rest results are shown.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaValidLogin", "Description": "The purpose of this function is to find SQL Server logins that are used by active directory users that are either disabled or removed from the domain. It allows you to keep your logins accurate and up to date by removing accounts that are no longer needed.", "Author": "Stephen Bennett: https://sqlnotesfromtheunderground.wordpress.com/", "Synopsis": "Test-DbaValidLogin finds any logins on SQL instance that are AD logins with either disabled AD user accounts or ones that no longer exist", "Name": "Test-DbaValidLogin", "Links": "https://dbatools.io/Test-DbaValidLogin", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaValidLogin -SqlInstance Dev01\r\n\r\nTests all logins in the current Active Directory domain that are either disabled or do not exist on the SQL Server \r\ninstance Dev01\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaValidLogin -SqlInstance Dev01 -FilterBy GroupsOnly -Detailed\r\n\r\nTests all Active Directory groups that have logins on Dev01, returning a detailed view.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaValidLogin -SqlInstance Dev01 -ExcludeDomains subdomain\r\n\r\nTests all logins excluding any that are from the subdomain Domain\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Test-DbaVirtualLogFile", "Description": "As you may already know, having a TLog file with too many VLFs can hurt database performance.\n\nToo many virtual log files can cause transaction log backups to slow down and can also slow down database recovery and, in extreme cases, even affect insert/update/delete performance.\n\n\tReferences:\n\thttp://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/\n\thttp://blogs.msdn.com/b/saponsqlserver/archive/2012/02/22/too-many-virtual-log-files-vlfs-can-cause-slow-database-recovery.aspx\n\nIf you\u0027ve got a high number of VLFs, you can use Expand-SqlTLogResponsibly to reduce the number.", "Tags": [ "DisasterRecovery", "Backup" ], "Synopsis": "Returns database virtual log file information for database files on a SQL instance.", "Name": "Test-DbaVirtualLogFile", "Links": "https://dbatools.io/Test-DbaVirtualLogFile", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaVirtualLogFile -SqlInstance sqlcluster\r\n\r\nReturns all user database virtual log file counts for the sqlcluster instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaVirtualLogFile -SqlInstance sqlserver | Where-Object {$_.Count -ge 50}\r\n\r\nReturns user databases that have more than or equal to 50 VLFs\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e@(\u0027sqlserver\u0027,\u0027sqlcluster\u0027) | Test-DbaVirtualLogFile\r\n\r\nReturns all VLF information for the sqlserver and sqlcluster SQL Server instances. Processes data via the pipeline.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eTest-DbaVirtualLogFile -SqlInstance sqlcluster -Database db1, db2\r\n\r\nReturns VLF counts for the db1 and db2 databases on sqlcluster.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Uninstall-DbaWatchUpdate", "Description": "Removes the scheduled task created for Watch-DbaUpdate by Install-DbaWatchUpdate so that notifications no longer pop up.", "Tags": [ "JustForFun", "Module" ], "Synopsis": "Removes the scheduled task created for Watch-DbaUpdate by Install-DbaWatchUpdate so that notifications no longer pop up.", "Name": "Uninstall-DbaWatchUpdate", "Links": "https://dbatools.io/Uninstall-DbaWatchUpdate", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eUninstall-DbaWatchUpdate\r\n\r\nRemoves the scheduled task created by Install-DbaWatchUpdate.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Update-Dbatools", "Description": "Exported function. Updates dbatools. Deletes current copy and replaces it with freshest copy.", "Tags": "Module", "Synopsis": "Exported function. Updates dbatools. Deletes current copy and replaces it with freshest copy.", "Name": "Update-Dbatools", "Links": "https://dbatools.io/Update-DbaTools", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eUpdate-Dbatools\r\n\r\nUpdates dbatools. Deletes current copy and replaces it with freshest copy.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eUpdate-Dbatools -dev\r\n\r\nUpdates dbatools to the current development branch. Deletes current copy and replaces it with latest from github.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Watch-DbaDbLogin", "Description": "Watch-DbaDbLogin uses SQL Server DMVs to track logins into a SQL Server table. This is helpful when you need to migrate a SQL Server and update connection strings, but have inadequate documentation on which servers/applications are logging into your SQL instance.\n\nRunning this script every 5 minutes for a week should give you a sufficient idea about database and login usage.", "Tags": "Login", "Author": "Chrissy LeMaire (@cl), netnerds.net", "Synopsis": "Tracks SQL Server logins: which host they came from, what database they\u0027re using, and what program is being used to log in.", "Name": "Watch-DbaDbLogin", "Links": "https://dbatools.io/Watch-DbaDbLogin", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eWatch-DbaDbLogin -SqlInstance sqlserver -SqlCms SqlCms1\r\n\r\nA list of all database instances within the Central Management Server SqlCms1 is generated. Using this list, the script \r\nenumerates all the processes and gathers login information and saves it to the table Dblogins in the DatabaseLogins \r\ndatabase on SQL Server sqlserver.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eWatch-DbaDbLogin -SqlInstance sqlcluster -Database CentralAudit -ServersFromFile .\\sqlservers.txt\r\n\r\nA list of servers is gathered from the file sqlservers.txt in the current directory. Using this list, the script \r\nenumerates all the processes and gathers login information and saves it to the table Dblogins in the CentralAudit \r\ndatabase on SQL Server sqlcluster.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eWatch-DbaDbLogin -SqlInstance sqlserver -SqlCms SqlCms1 -SqlCredential $cred\r\n\r\nA list of servers is generated using database instance names within the SQL2014Clusters group on the Central Management \r\nServer SqlCms1. Using this list, the script enumerates all the processes and gathers login information and saves it to \r\nthe table Dblogins in the DatabaseLogins database on sqlserver.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Watch-DbaUpdate", "Description": "Just for fun - checks the PowerShell Gallery every 1 hour for updates to dbatools. Notifies once max per release.\n\nAnyone know how to make it clickable so that it opens an URL?", "Tags": [ "JustForFun", "Module" ], "Synopsis": "Just for fun - checks the PowerShell Gallery every 1 hour for updates to dbatools. Notifies once per release.", "Name": "Watch-DbaUpdate", "Links": "https://dbatools.io/Watch-DbaUpdate", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eWatch-DbaUpdate\r\n\r\nWatches the gallery for updates to dbatools.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Write-DbaDataTable", "Description": "Writes a .NET DataTable to a SQL Server table using SQL Bulk Copy.", "Tags": [ "DataTable", "Insert" ], "Synopsis": "Writes data to a SQL Server Table.", "Name": "Write-DbaDataTable", "Links": "https://dbatools.io/Write-DbaDataTable", "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003e$DataTable = Import-Csv C:\\temp\\customers.csv | Out-DbaDataTable\r\n\r\nWrite-DbaDataTable -SqlInstance sql2014 -InputObject $DataTable -Table mydb.dbo.customers\r\n\r\nPerforms a bulk insert of all the data in customers.csv into database mydb, schema dbo, table customers. A progress bar \r\nwill be shown as rows are inserted. If the destination table does not exist, the import will be halted.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$DataTable = Import-Csv C:\\temp\\customers.csv | Out-DbaDataTable\r\n\r\n$DataTable | Write-DbaDataTable -SqlInstance sql2014 -Table mydb.dbo.customers\r\n\r\nPerforms a row by row insert of the data in customers.csv. This is significantly slower than a bulk insert and will not \r\nshow a progress bar.\r\n\r\nThis method is not recommended. Use -InputObject instead.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e$DataTable = Import-Csv C:\\temp\\customers.csv | Out-DbaDataTable\r\n\r\nWrite-DbaDataTable -SqlInstance sql2014 -InputObject $DataTable -Table mydb.dbo.customers -AutoCreateTable\r\n\r\nPerforms a bulk insert of all the data in customers.csv. If mydb.dbo.customers does not exist, it will be created with \r\ninefficient but forgiving DataTypes.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003e$DataTable = Import-Csv C:\\temp\\customers.csv | Out-DbaDataTable\r\n\r\nWrite-DbaDataTable -SqlInstance sql2014 -InputObject $DataTable -Table mydb.dbo.customers -Truncate\r\n\r\nPerforms a bulk insert of all the data in customers.csv. Prior to importing into mydb.dbo.customers, the user is \r\ninformed that the table will be truncated and asks for confirmation. The user is prompted again to perform the import.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$DataTable = Import-Csv C:\\temp\\customers.csv | Out-DbaDataTable\r\n\r\nWrite-DbaDataTable -SqlInstance sql2014 -InputObject $DataTable -Database mydb -Table customers -KeepNulls\r\n\r\nPerforms a bulk insert of all the data in customers.csv into mydb.dbo.customers. Because Schema was not specified, dbo \r\nwas used. NULL values in the destination table will be preserved.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$passwd = ConvertTo-SecureString \"P@ssw0rd\" -AsPlainText -Force\r\n\r\n$AzureCredential = Mew-Object System.Management.Automation.PSCredential(\"AzureAccount\"),$passwd)\r\n$DataTable = Import-Csv C:\\temp\\customers.csv | Out-DbaDataTable\r\nWrite-DbaDataTable -SqlInstance AzureDB.database.windows.net -InputObject $DataTable -Database mydb -Table customers \r\n-KeepNulls -Credential $AzureCredential -RegularUser -BulkCopyTimeOut 300\r\n\r\nThis performs the same operation as the previous example, but against a SQL Azure Database instance using the required \r\ncredentials. The -RegularUser switch is needed to prevent trying to get administrative privilege, and we increase the \r\nBulkCopyTimeout value to cope with any latency.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e$process = Get-Process | Out-DbaDataTable\r\n\r\nWrite-DbaDataTable -InputObject $process -SqlInstance sql2014 -Database mydb -Table myprocesses -AutoCreateTable\r\n\r\nCreates a table based on the Process object with over 60 columns, converted from PowerShell data types to SQL Server \r\ndata types. After the table is created a bulk insert is performed to add process information into the table.\r\n\r\nThis is an example of the type conversion in action. All process properties are converted, including special types like \r\nTimeSpan. Script properties are resolved before the type conversion starts thanks to Out-DbaDataTable.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" } ] |