Category: Power Shell Script
-
Powershell Script to Drop Logins across multile servers.
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’) | out-null $Error.Clear() cls $servers = Get-Content E\LoginNames\Servers.txt $logins = @(login name to be dropped) foreach($server in $servers) { $srv = New-Object (‘Microsoft.SqlServer.Management.Smo.Server’) $server #drop database users foreach($database in $srv.Databases) { foreach($login in $logins) { if($database.Users.Contains($login)) { $database.Users[$login].Drop(); } } } #drop server logins foreach($login in $logins) { if ($srv.Logins.Contains($login)) { $srv.Logins[$login].Drop(); } } } $FilePath = “E:\LoginNames\” $OutFile = Join-Path -path $FilePath -childPath (“logins_” + (get-date).toString(‘yyyyMMdd_hhmmtt’) + “.log”)
//
-
Get SQL Server version information installed on multiple servers
$start = get-date write-host “Start: ” $start [reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) | out-null ## Specify path of output file $FilePath = “D:\Version\” $OutFile = Join-Path -path $FilePath -childPath (“SQLVersions_” + (get-date).toString(‘yyyyMMdd_hhmmtt’) + “.log”) ## Output file name will be like “X:\Monitoring_Automation\ SQLVersions_20130906_1248AM.log” # Below is loop to generate version of each server @(foreach ($svr in get-content “D:\Version\Monitoring_servers.txt”) { $s = New-Object “Microsoft.SqlServer.Management.Smo.Server” $svr $s | select Name, Version }) | export-csv -noType $OutFile $end = get-date write-host “End: ” $end
//
-
DBCC IND
The DBCC IND statement takes three parameters like this: DBCC IND(0,’dbo.SalesOrderDetailList’,1); First parameter is the database id. If you pass in 0 here, the current database is used. Second parameter is the table name in quotes. You can also pass in the object_id of the table instead of the quoted name like this: DBCC IND(0,1797581442,1); Third parameter is the index_id. There is an optional fourth parameter that…
//
-
Read a big file using PowerShell
Get-Content C:\MySQL_Dump_8April2022\agii-tdsqlpw01_08April_11PM.sql | Select-Object -skip 0 -first 100
//
-
AOG on Azure Blob with a different region SQL Server instance
Hello there, everyone! I hope everything is going well for you. Today, I’ll show you AOG on Azure Blob with different region SQL Server Instance. Ø Created SQL disk layout and formatted with 64K- · Disk E: SQL Binaries · Disk T: TempDB · Disk R: User Databases · Disk L: User DB transaction logs Ø SQL Server Memory Configuration as…
//
-
Read a big file using PowerShell
# Command-Format: Get-Content ‘your-file-path’ -Tail <number-of-line>Get-Content ‘.\mylargefile.txt’ -Tail 5000 # Get-Content D:\MyBigFeedFile.txt | Select-Object -skip 123798766555672 -first 6
//
Search
Categories
- Azure (7)
- About Us (1)
- Azure SQL Database (6)
- My SQL (53)
- About Us (1)
- DBMS Concepts (20)
- Handbook (1)
- MySQL Architecture (19)
- MySQL Basics (29)
- MySQL L1 (14)
- Oracle (34)
- PostgreSQL (37)
- About Us (1)
- DBMS Concepts (21)
- PG Hand Book (1)
- pg_ High Availability (4)
- pg_Backup (4)
- pg_basic (11)
- SQL Server (132)
- About Us (1)
- Azure SQL Database (4)
- Backup and Recovery (17)
- Backup Tools for SQL Server (3)
- DBA Worries Continued (27)
- DBMS Concepts (28)
- High Availability (12)
- Installation and Configuration (23)
- L1 DBA (59)
- Monitoring (17)
- Performance Tuning (29)
- Power Shell Script (6)
- Security (12)
- SQL DBA Hand Book (2)
- SQL Scripting (16)
- SQL Server Reporting Services (2)
- Uncategorized (3)