Archive for the ‘Powershell’ Category

Fun with the Get-Hotfix cmdlet

With the Get-Hotfix cmdlet you can query the list of hotfixes that have been applied to computers. ?View Code POWERSHELLGet-Hotfix | Format-Table -AutoSize; This will display the list of hotfixes installed on the local computer. Source Description HotFixID InstalledBy InstalledOn —— ———– ——– ———– ———– SO0590 Update 982861 NT AUTHORITY\SYSTEM 07/07/2011 00:00:00 SO0590 Update KB958830 […]

Fun with the Get-EventLog cmdlet

The Get-EventLog cmdlet is great for working with the Windows Event Logs on local and remote computers. It includes lots of parameters that make life much easier than using the Event Viewer GUI. To list the available logs on the local computer just execute; ?View Code POWERSHELLGet-EventLog -List | Format-Table -AutoSize; Max(K) Retain OverflowAction Entries […]

Identify the Active Cluster Node with Powershell

I wanted to find a way of programatically identifying the active node of a SQL Server Cluster. I found this post that demonstrated how to do it with TSQL. As I love Powershell so much here’s another method to do it; ?View Code POWERSHELL# Set cluster name $cluster_name = "ClusterName"; # Load SMO extension [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") […]

Failover All Cluster Resources With Powershell

Here’s a simple example showing how to manage the failover process with Powershell, making sure all resources are running on one node. First, execute the below command to show which node owns the resources. ?View Code POWERSHELLGet-ClusterGroup -Cluster ClusterName | Format-Table -AutoSize; Name OwnerNode State —- ——— —– SoStagSQL20Dtc Node1 Online SQL Server Node1 Online […]

Powershell Primary Key & Clustered Index Check

It’s considered a bad practice  Not using Primary Keys and Clustered Indexes here’s a Powershell script that can make checking a database for this very easy. Just set the $server to the sql instance you want to check and $database as appropriate. ?View Code POWERSHELL# variables $server = "sqlinstance"; $database = "badDB"; # Load SMO […]