Skip to content

Instantly share code, notes, and snippets.

@sqlchow
sqlchow / mersenne_twister.ps1
Last active August 29, 2015 14:19
Attempt at implementing PRNG mersenne twister in powershell. Mostly educational purposes.
#Mersenne_twister
$MT = New-Object int64[] 624
[int]$index = 0
function Initialize-Generator
{
<#
Initialize the generator from a seed.
#>
param(
@sqlchow
sqlchow / Fisher-Yates_shuffle.ps1
Last active August 29, 2015 14:19
Given a set of 1000 numbers, how do I shuffle the set in an unbiased way so that it has the appearance of a randomly generated set?
Function Get-ShuffledArray
{
#Given a set of 1000 numbers, how do I shuffle the set in an unbiased way
#so that it has the appearance of a randomly generated set?
param(
[Array]$gnArr
)
$len = $gnArr.Length;
while($len)
{
@sqlchow
sqlchow / Search-SqlErrorLog.ps1
Last active August 29, 2015 14:19
The script was created to answer a question on twitter: "How to filter line + following line using Get-SqlErrorLog? Something like Select-String -Context 1"
<#
.SYNOPSIS
Get data from SQL Server error log
.DESCRIPTION
The script was created to answer a question on twitter:
"How to filter line + following line using Get-SqlErrorLog?
Something like Select-String -Context 1"
.LINK
https://sqlchow.wordpress.com/2013/08/18/filtering-data-from-sqlserver-errorlogs/
.LINK
@sqlchow
sqlchow / Set-ScomConsolePollingInterval.ps1
Last active August 29, 2015 14:19
Sets the polling rate of your SCOM console to every 75 seconds from the default polling rate of every 5 seconds.
<#
.SYNOPSIS
Set SCOM console polling rate.
.DESCRIPTION
Sets the polling rate of your SCOM console to every 75 seconds from the
default polling rate of every 5 seconds.
.LINK
https://sqlchow.wordpress.com/2013/03/15/setting-scom-console-polling-rate/
.LINK
.NOTES
@sqlchow
sqlchow / Get-SQLInstanceList.ps1
Last active August 29, 2015 14:19
Get SQL Server instances installed on a local machine
function Get-SQLInstanceList
{
<#
.SYNOPSIS
Get SQL Server instances installed on a local machine
.DESCRIPTION
The script looks in the registry path
HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL\
and will check which SQL*Server instances are installed and for each
@sqlchow
sqlchow / Get-failedBackups.ps1
Last active August 29, 2015 14:19
Get a list of failed backups in the error log.
<#
.SYNOPSIS
Get failed backup details from SQL Error log.
.DESCRIPTION
The script uses SMO to read error log and filters data based on the criteria.
.LINK
https://sqlchow.wordpress.com/2013/02/13/t-sql-tuesday-39-getting-installed-instances-querying-logs/
.LINK
@sqlchow
sqlchow / Search-WinEventLogs.ps1
Last active August 29, 2015 14:19
Get errors in windows log for the past 24hrs.
<#
.SYNOPSIS
Get errors in windows log for the past 24hrs.
.DESCRIPTION
The below function will query the windows event logs and return the highest
occurring error events along with their counts.
.LINK
https://sqlchow.wordpress.com/2013/02/13/t-sql-tuesday-39-getting-installed-instances-querying-logs/
@sqlchow
sqlchow / Get-UnexpectedShutdowns.ps1
Last active August 29, 2015 14:19
This script checks if a given computer has been shutdown unexpectedly in the last 24hrs.
function Get-UnexpectedShutdowns
{
<#
.SYNOPSIS
Checks unexpected shutdowns in the last 24hrs.
.DESCRIPTION
This script checks if a given computer has been shutdown unexpectedly
in the last 24hrs.
KB: http://support.microsoft.com/kb/2028504
@sqlchow
sqlchow / Test-SQLConnection.ps1
Last active August 29, 2015 14:19
Test if a given sql server instance is available to connect or not.
function Test-SQLConnection
{
<#
.Synopsis
Test connection to a sql server.
.DESCRIPTION
The function tries to connect to the SQL Server, if a successful
connection is made we return back the server name.
You cannot pipe parameter to Test-SQLConnection.
@sqlchow
sqlchow / Get-SMOConnection.ps1
Last active August 29, 2015 14:19
Gets an SMO connection object to a given SQL Server instance.
function Get-SMOConnection {
<#
.SYNOPSIS
Create a new SMOConnection Object.
.DESCRIPTION
The Get-SMOConnection creates new SMO Connection to the SQL Server instance
and returns the connection object to the calling function or script.
.PARAMETER SqlServer