Posted on April 22, 2013, 7:27 am, by Rhys, under
Powershell.
Here’s a quick Powershell script I knocked up to help me check AD Group Memberships between two user accounts. Just set the $user1 and $user2 variables and you’re good to go. ?View Code POWERSHELLImport-Module ActiveDirectory; $user1 = "username1"; $user2 = "username2"; $groups1 = Get-ADPrincipalGroupMembership –Identity $user1 | Select-Object -Property Name; $groups2 = Get-ADPrincipalGroupMembership –Identity $user2 | Select-Object [...]
Posted on March 19, 2013, 11:57 am, by Rhys, under
Powershell.
Here’s a quick Powershell snippet to get the startup and shutdown times for a windows system after a specific point. Get-EventLog -LogName System -ComputerName myHost -After 12/03/2013 -Source “Microsoft-Windows-Kernel-General” | Where-Object { $_.EventId -eq 12 -or $_.EventId -eq 13; } | Select-Object EventId, TimeGenerated, UserName, Source | Sort-Object TimeGenerated | Format-Table -Autosize; Id 12 indicates [...]
I don’t have access, like many DBAs, to the inner bowels of Active Directory. While I’m more than happy for it to stay this way I still want to check that certain things have been setup correctly and haven’t been “cleaned-up” by a security nazi focused domain administrator. One such situation arose recently with Service Principal Names. SPNs [...]
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, [...]