Category: Powershell

  • SQL Server Policy-Based Management the hidden configuration baseline.

    Policy-Based Management Policy-Based Management is a policy based system for managing one or more instances of SQL Server. This has been around in SQL Server since 2008 but is often overlooked for both its primary function in administration as well as its ability to store baselines. If you open up SQL Server Management Studio (SSMS)…

  • Regain access to SQL Server via inject service

    One way to regain access to SQL Server is to use a simple inject technique which overrides the current Image Path for the SQL Writer service.   PsExec can alternatively be used to access SQL Server as shown in the post below. This relies on the NT AUTHORITY\SYSTEM account having been granted system administrator on…

  • SQL Server and PowerShell (SQLPS) Starter

    The following two snippets of code are two ways to achieve the same outcome, which is the $Server object containing the default instance. Or when opening a SQL PS (Powershell) prompt at the default location. e.g. PS SQLSERVER:\SQL\SB01\DEFAULT> I mention this because I was asked what the simplist entry point to PowerShell for SQL person…

  • Find SQL Server Instances

    Any environment will kick up the odd surprise with extra servers you did not know about (suddenly appearing), which is why I always like to have a look around the environment every so often to see what is there. So how do you find SQL instances and without a 3rd party tool? SQL Command Line…

  • Quick data wipe via truncate

    “How to remove all data from a database?” is something that I have often seen asked on the forums. How do you remove all the data quickly? First you try with delete and find that this is too slow and the transaction log has to record all the changes, so you use truncate which is…

  • Get-VolumeFreeSpace

    Here is an example function to return free space remaining on a volume with associated details. Updated 27/04/2012 to fix mount points. Usage Examples: Get-VolumeFreeSpace|ft Get-VolumeFreeSpace|Select ComputerName,Name,MountPoint,FreeSpaceGiB|ft Get-VolumeFreeSpace|Where-Object {!$_.SystemVolume}|Select ComputerName,Name,MountPoint,FreeSpaceGiB|ft Get-VolumeFreeSpace “ComputerA”,”ComputerB” |ft

  • Dell Service Tag

      The Dell soap API now returns a HTTP Error 503. The service is unavailable so the code listed below no longer functions. Dell provide an alternative method to retrieve the information via a REST API. Please search for Dell Support Services APIs for more details. A simple call can be made via the following…

  • Get-DatabaseSizes

    Simple example using SMO to get database storage information. You will need SMO installed for this script to work. Note Size relates to the file size on disk, where as space refers to the storage used or available. Usage Examples: Get-DatabaseSizes Get-DatabaseSizes . | Select * Get-DatabaseSizes . | Select DatabaseName,LogicalName,FileName,Size_MiB Get-DatabaseSizes . | Select…

  • Find Uptime / Last Boot Up Time Commands

    There are numerous ways to find how long a machine has been powered on for, and below I will list a few of them: CMD Powershell

  • Get-StringHash and Get-FileHash

    Hashing Here are two of my powershell scripts that provide a quick and easy way to hash either a string or a file using any of the cryptography hash algorithms. Get-StringHash Usage Examples: Get-StringHash “My String to hash” “MD5” Get-StringHash “My String to hash” “RIPEMD160” Get-StringHash “My String to hash” “SHA1” Get-StringHash “My String to hash” “SHA256”…