Getting all SQL Server services running on a server using PowerShell: Get-WmiObject -Class sqlservice -Namespace “ROOT\Microsoft\SqlServer\ComputerManagement11” | Select ServiceName Additionally, this can be set to an array and worked with as such. $services = Get-WmiObject -Class sqlservice -Namespace “ROOT\Microsoft\SqlServer\ComputerManagement11” | Select ServiceName foreach($service in $services) { $service.ServiceName } $services[0].ServiceName >>...
powershell
The basics of creating a PowerShell array and working with it.
PowerShell script that prints out the state of the node you are on – Active or Passive.
The basic syntax for sending a query to SQL Server using PowerShell. sqlcmd -S SERVER_NAME -d master -Q "select count(1) from sys.objects"
Show Date/Time Of Last Boot Get-WmiObject -class Win32_OperatingSystem | Select-Object __SERVER,@{label='LastBootUpTime';expression={$_.ConvertToDateTime($_.LastBootUpTime)}}
If PowerShell is not allowing you to run scripts then you might need to set the execution policy. Set-ExecutionPolicy RemoteSigned https://technet.microsoft.com/en-us/library/ee176961.aspx
Source: https://gist.github.com/mbrownnycnyc/9913361 This is a very fast way to ping a server using PowerShell. # with reference to http://theadminguy.com/2009/04/30/portscan-with-powershell/ 2 function fastping{ 3 [CmdletBinding()] 4 param( 5 [String]$computername = “127.0.0.1”, 6 [int]$delay = 100 7 ) 8 9 $ping = new-object System.Net.NetworkInformation.Ping 10 # see http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipstatus%28v=vs.110%29.aspx 11 try { 12...
$assemblylist = “Microsoft.SqlServer.Management.Common”, “Microsoft.SqlServer.Smo”, “Microsoft.SqlServer.Dmf “, “Microsoft.SqlServer.Instapi “, “Microsoft.SqlServer.SqlWmiManagement “, “Microsoft.SqlServer.ConnectionInfo “, “Microsoft.SqlServer.SmoExtended “, “Microsoft.SqlServer.SqlTDiagM “, “Microsoft.SqlServer.SString “, “Microsoft.SqlServer.Management.RegisteredServers “, “Microsoft.SqlServer.Management.Sdk.Sfc “, “Microsoft.SqlServer.SqlEnum “, “Microsoft.SqlServer.RegSvrEnum “, “Microsoft.SqlServer.WmiEnum “, “Microsoft.SqlServer.ServiceBrokerEnum “, “Microsoft.SqlServer.ConnectionInfoExtended “, “Microsoft.SqlServer.Management.Collector “, “Microsoft.SqlServer.Management.CollectorEnum”, “Microsoft.SqlServer.Management.Dac”, “Microsoft.SqlServer.Management.DacEnum”, “Microsoft.SqlServer.Management.Utility” foreach ($asm in $assemblylist) { $asm = [Reflection.Assembly]::LoadWithPartialName($asm) } $computers...
This script searches every file in a directory for a particular string and replaces it with another value. get-childItem | ForEach { (Get-Content $_ | ForEach {$_ -replace “OLDVALUE,”NEWVALUE”}) | Set-Content $_}