Skip to content

Instantly share code, notes, and snippets.

@sqlchow
sqlchow / Get-SQLServerVersionDetails.ps1
Last active August 29, 2015 14:19
One of the very first powershell scripts I created. Checks a list of servers and gets the details of installed SQL Server instances and puts the data in excel. Uses Get-RemoteRegistryKeyProperty by Lee Holmes. It uses a csv file with the following headers "Monitor", "PhysicalServer", "POrNP".
##############################################################################
## BEGIN-HELPER FUNCTIONS ##
##############################################################################
##############################################################################
## Get-RemoteRegistryKeyProperty
## Get the value of a remote registry key property
##
## Author: Lee Holmes
## Book: Windows Powershell Cookbook
@sqlchow
sqlchow / Get-SlipStreamedInstallMedia.ps1
Last active August 29, 2015 14:19
Creating a Slipstream SQL Server install media (pre-2012 as you do not need to do this anymore).
<#
.LINK https://sqlchow.wordpress.com/2012/07/30/creating-a-slipstream-sql-server-install-media-using-powershell/
#>
Begin
{
$isPCU = $true
$isCU = $false
$verPCU = "5500" # service pack version
$verCU = $null
$archArray = @('x64', 'x86', 'ia64')
@sqlchow
sqlchow / Move-MouseEveryMin.ps1
Last active August 29, 2015 14:19
A fun function that moves the mouse every minute on screen
function Move-MouseEveryMin
{
$startTime = Get-Date
$endTime = Get-Date
$timeDiff = New-TimeSpan -Start $startTime -End $endTime
$screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$StartPos = [System.Windows.Forms.Cursor]::Position
$Pos = $StartPos
While($timeDiff.Hours -lt 1)
{
@sqlchow
sqlchow / Get-DiskSizes.ps1
Last active August 29, 2015 14:19
get disk sizes including mount points
function Get-DiskSizes
{
<#
.SYNOPSIS
Get disk sizes
.DESCRIPTION
The Get-DiskSizes function returns data about the disks on a given machine.
It uses Win32_Volume class to get this information.
.PARAMETER ComputerName
Name of the machine from where we need to retrieve the information.
@sqlchow
sqlchow / Get-WMIDirectoryTree.ps1
Last active August 29, 2015 14:19
View a directory tree using WMI..
function Get-WMIDirectoryTree
{
<#
.SYNOPSIS
To view a directory tree.
.DESCRIPTION
The script takes a path and computername and lists the directory
tree on that particular computer for that particular path.
@sqlchow
sqlchow / Get-SubnetMask.ps1
Last active August 29, 2015 14:19
Gets the subnet mask of a given adapter address or all the adapters that have an address assigned to them.
function Get-SubnetMask
{
<#
Address IPv4Mask
------- --------
192.168.1.39 255.255.255.0
127.0.0.1 255.0.0.0
PS C:\Users\sqlchow> Get-SubnetMask -address 127.0.0.1
@sqlchow
sqlchow / Add-LoginsToSQLServerAsSysAdmin.ps1
Last active August 29, 2015 14:19
Adds a windows group to SQL Server as a sysadmin login to a given set of servers.
function Add-LoginsToSQLServerAsSysAdmin
{
<#
.SYNOPSIS
Add windows group to sysadmin role
.DESCRIPTION
The function loops through a list of sql servers and adds a given
windows group to the sysadmin role on these servers.
.PARAMETER LoginToAdd
Name of the windows group that needs to be added in the following format
@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
@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-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