Skip to content

Instantly share code, notes, and snippets.

View MagicAndi's full-sized avatar
👹
Hard at work, coding. Ignoring all distractions, including you.

Andy P. MagicAndi

👹
Hard at work, coding. Ignoring all distractions, including you.
View GitHub Profile
@MagicAndi
MagicAndi / gist:1499455c45110faaadaa42741b3945f8
Last active May 7, 2017 19:45
List all installed programmes
# Locally installed Chocolately packages
chocolatey list -localonly
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize
# Output to a file:
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize > C:\Temp\InstalledPrograms.txt
@MagicAndi
MagicAndi / ListIisWorkerProcesses.bat
Created April 7, 2017 11:38
Lists the running w3wp.exe process(es) (worker process) present on the local server with their respective PIDs and application pools. Runs in the %windir%\system32\inetsrv\ folder.
REM To run in the %windir%\system32\inetsrv\ folder
appcmd list wp
@MagicAndi
MagicAndi / RestoreNuGetPackages.ps1
Created March 22, 2017 14:54
NuGet PM Consol command to restore all NuGet packages associated with a specific project... Because I'm tired of searching for it all the bloody time.
# Taken from http://stackoverflow.com/a/6882750
Update-Package -reinstall -Project YourProjectName
@MagicAndi
MagicAndi / Get-AllFilePaths.ps1
Created March 2, 2017 16:08
One-liner script that lists all file paths in a specified directory
Get-ChildItem "C:\Temp\IIS Logs" -recurse | where {$_.extension -eq ".log"} | % { Write-Host $_.FullName }
@MagicAndi
MagicAndi / List-InstalledSoftware
Created May 26, 2015 12:16
Get installed softwrae on a PC as a text file.
Get-WmiObject Win32_Product | Sort-Object Vendor, Name | Format-Table Vendor, Name, Version -groupBy Vendor | Out-File C:\Temp\Test.txt
# Note, can also use
# Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Sort-Object Publisher, DisplayName | Format-Table DisplayName, Publisher, InstallDate | Out-File C:\Temp\Installed.txt
# See
# http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/13/use-powershell-to-quickly-find-installed-software.aspx
# and
# http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/15/use-powershell-to-find-installed-software.aspx
# for details
@MagicAndi
MagicAndi / Get-MD5Hash
Created May 18, 2015 12:58
PowerShell function to compute a MD5 checksum for a file. Based on an answer at http://stackoverflow.com/questions/10521061/how-to-get-an-md5-checksum-in-powershell. Note, this method works for files greater than 2GB in size.
function md5hash($path)
{
$fullPath = Resolve-Path $path
$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$file = [System.IO.File]::Open($fullPath,[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
[System.BitConverter]::ToString($md5.ComputeHash($file))
$file.Dispose()
}
@MagicAndi
MagicAndi / RunAs-Admin.ps1
Created May 13, 2015 13:15
PowerShell snippet to run PowerShell code in an elevated (UAC) process. Taken from answers to this StackOverflow question: http://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
#"No Administrative rights, it will display a popup window asking user for Admin rights"
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments
break
}
#"After user clicked Yes on the popup, your file will be reopened with Admin rights"
@MagicAndi
MagicAndi / gist:ec3f43d70aa4b731114d
Created February 5, 2015 09:42
PowerShell one-liner to discover all SQL Server instances running on network. Requires SQL Browser service to be running, as described in http://www.mssqltips.com/sqlservertip/2013/find-sql-server-instances-across-your-network-using-windows-powershell/
[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()
@MagicAndi
MagicAndi / ListUniqueFilenamesInDirectory
Created December 13, 2014 17:58
PowerShell script to list unique filenames (DLLs in example) in a specified directory
Get-ChildItem 'C:\Temp\' -recurse -filter "*.dll" -name | % { [IO.Path]::GetFileNameWithoutExtension($_) } | Sort-Object -unique
@MagicAndi
MagicAndi / DropAllStoredProcedures.sql
Created November 29, 2014 19:48
A SQL script to delete all stored procedures in a SQL database.
DECLARE @DeleteProcCommand NVARCHAR(500)
DECLARE Syntax_Cursor CURSOR
FOR
SELECT 'DROP PROCEDURE ' + p.NAME
FROM sys.procedures p
OPEN Syntax_Cursor
FETCH NEXT FROM Syntax_Cursor