Posted on January 31, 2012, 12:21 pm, by Rhys, under
DBA,
Powershell.
Here’s a simple Powershell snippet to check the mirroring statusĀ on your SQL Server instances. ?View Code POWERSHELL# Load SMO extension [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null; # Servers to check $sqlservers = @("server1", "server2", "server3"); foreach($server in $sqlservers) { $srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $server; # Get mirrored databases $databases = $srv.Databases | Where-Object {$_.IsMirroringEnabled -eq $true}; Write-Host [...]
Posted on January 6, 2012, 4:57 pm, by Rhys, under
DBA,
Powershell.
Here’s a little Powershell function I’m using to check the Event LogsĀ and SQL Server Error Logs in one easy swoop; ?View Code POWERSHELLfunction Get-ServerErrors { # Server to check & hours back. Will only support default sql instances # Could add a third param for instance and modify script where appropriate if needed param ($server, [...]
Posted on December 30, 2011, 12:28 pm, by Rhys, under
Powershell.
Here’s a quick Powershell one-liner to list all the Organizational Units, or OUs, in your Active Directory domain. Firstly you’ll probably need to load the ActiveDirectory module. This can be done at the Powershell prompt with the below command; ?View Code POWERSHELLImport-Module ActiveDirectory; Then we can use the Get-ADOrganizationalUnit cmdlet to retrieve a list of [...]
Posted on November 29, 2011, 12:20 pm, by Rhys, under
Powershell.
Many of us tend to jump quickly, into a new programming or scripting language, applying knowledge we’ve learned elsewhere to the current task at hand. Broadly speaking this works well but these always a little gotcha to trip you up! A good example is the Powershell -contains operator. It’s not like .Net String.Contains method as [...]
We don’t use SSRS much at my workplace but its usage is slowly creeping up. I realised that none of us are keeping an eye on the few subscriptions we have set-up. So I decided to do something about that. Here’s a bit of Powershell code that uses the SSRS Web Service to pull out [...]
Posted on November 10, 2011, 4:10 pm, by Rhys, under
Powershell.
Here’s a little snippet of Powershell code I used recently to test some TSQL that runs according to a two week schedule. This code will increment the date by one day, up to the maximum specified in $days, sleeping in between for a short while. The date is set back correctly at the end. Far [...]
Posted on November 3, 2011, 11:26 am, by Rhys, under
DBA,
Powershell.
Just a quick Powershell snippet that I’m going to use to run validation tests on one of my staging Failover Clusters during OOH. The script below will take some services offline, run the validation tests, before bringing the appropriate cluster groups back online. The report will be saved using the date as the name. To [...]
Posted on October 13, 2011, 12:14 pm, by Rhys, under
Powershell.
I needed to figure out a method for producing alerts when a domain account is approaching the password reset date. Here it is in a few lines of Powershell… ?View Code POWERSHELL# Set name here $name = "Rhys Campbell"; $user = Get-ADUser -LDAPFilter "(Name=$name)" -Properties PasswordLastSet; $days = $(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge; $expires = $user.PasswordLastSet + $days; $days_left [...]
Disk alignment has been well discussed on the web and the methods to check this always seem to use wmic or DISKPART. I’ve always loathed wmi so here’s a few lines of Powershell that achieves the same thing; ?View Code POWERSHELL$sqlserver = "sqlinstance"; # Get disk partitions $partitions = Get-WmiObject -ComputerName $sqlserver -Class Win32_DiskPartition; $partitions [...]
I’ve been reading a bit about VLFs (Virtual Log Files) this week. I’ve found quite a few interesting links, especially this one, informing us that there’s such a thing as too few or too many VLFs. We can view details about VLFs using the DBCC LOGINFO TSQL command. This only works against the current database [...]