Posts Tagged ‘Powershell’

Check the value of an Environmental Variable on Multiple servers

Here’s one powershell method for how to check the value of an environment variable on multiple servers; ?View Code POWERSHELL$computers = @("server1", "server2", "server3");   foreach ($c in $computers) { Get-WmiObject -ComputerName $c -Class Win32_Environment -Filter "Username = ‘<SYSTEM>’ AND Name = ‘VAR_NAME’"; } Output will be similar to below… VariableValue Name UserName ————- —- […]

What’s protected from accidental deletion in Active Directory?

Here’s just a little tip I picked up from a presentation by Mark Broadbent (retracement on twitter). I’m the guy who wasn’t listening! Mark stressed the importance of enabling the Protection from accidental deletion property in active directory for your Failover Clusters. Here’s how to check this for Computers with Powershell. This string of commands […]

Compare AD Group Memberships with 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 […]

Powershell to get Windows Startup & Shutdown times

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 […]

Check Mirroring Status with 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 […]