Skip to content

Instantly share code, notes, and snippets.

View potatoqualitee's full-sized avatar
big permz energy

Chrissy LeMaire potatoqualitee

big permz energy
View GitHub Profile
@potatoqualitee
potatoqualitee / advanced-datatable.ps1
Created February 3, 2015 04:24
Formatting Data within .NET DataTables using PowerShell
# Create Basic Datatable
$datatable = New-Object System.Data.Datatable
[void]$datatable.Columns.Add("name")
[void]$datatable.Columns.Add("directory")
[void]$datatable.Columns.Add("bytes", [double])
# Add data
[void]$datatable.Rows.Add("locate","C:",1.0)
[void]$datatable.Rows.Add("Backup","C:\locate",1.0)
[void]$datatable.Rows.Add("Invoke-Locate.ps1","C:\locate",39630.0)
@potatoqualitee
potatoqualitee / Get-DupesinCSV.ps1
Created March 31, 2015 08:41
Quickly Find Duplicates in Large CSV Files using PowerShell
# From https://blog.netnerds.net/2015/01/quickly-find-duplicates-from-csv-using-powershell/
# The Text OleDB driver is only available in PowerShell x86. Start x86 shell if using x64.
# This has to be the first check this script performs.
if ($env:Processor_Architecture -ne "x86") {
Write-Warning "Switching to x86 shell"
&"$env:windir\syswow64\windowspowershell\v1.0\powershell.exe" "$PSCommandPath $args"; return
}
# Change to your CSV file name, must end in .csv or .tsv
$csvfile = "C:\temp\million-commas.txt"
Function Join-AdminUNC {
<#
.SYNOPSIS
Parses a path to make it an admin UNC.
.EXAMPLE
Join-AdminUNC sqlserver C:\windows\system32
Output: \\sqlserver\c$\windows\system32
.OUTPUTS
@potatoqualitee
potatoqualitee / CSVSQL.ps1
Created May 6, 2015 04:11
Query CSV with SQL
# See PowerShell Magazine article at .....
$jet = (New-Object System.Data.OleDb.OleDbEnumerator).GetElements() | Where-Object { $_.SOURCES_NAME -eq "Microsoft.Jet.OLEDB.4.0" }
if ($jet -eq $null) {
if ($env:Processor_Architecture -ne "x86") {
&"$env:windir\syswow64\windowspowershell\v1.0\powershell.exe"
}
}
$csv = "$env:TEMP\top-tracks.csv"
Invoke-WebRequest http://git.io/vvzxA | Set-Content -Path $csv
$firstRowColumnNames = "Yes"
@potatoqualitee
potatoqualitee / New-TextIcon.ps1
Created September 14, 2015 15:09
Creates Text Icon. Useful for NotifyIcons.
Function New-TextIcon {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]$Text,
[string]$Path,
[int]$Height = 16,
[int]$Width = 16,
[int]$FontSize = 9
@potatoqualitee
potatoqualitee / Show-SystemColors.ps1
Last active September 16, 2015 10:25
PowerShell function Show-SystemColor to get GUI list of System.Windows.SystemColors
Function Show-SystemColors {
<#
.SYNOPSIS
Shows a visual representation (grid with color block, name, and hex code)) of system colors.
.NOTES
Author : Chrissy LeMaire
Requires: PowerShell 3.0
Version: 1.0
DateUpdated: 2015-Sep-16
@potatoqualitee
potatoqualitee / lowerright.ps1
Last active September 12, 2022 10:52
PowerShell WPF popup in lower right corner of the screen
[xml]$xaml = '<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" ResizeMode="NoResize" ShowInTaskbar="False"
Height="0" Width="0" Background="Transparent">
<Popup Name="popup" Placement="AbsolutePoint" StaysOpen="False">
<Grid Name="grid" Height="400" Width="390" Background="DarkGray">
<Label Name="label" Content="Double-click to close" Foreground="White" FontSize="18"/>
</Grid>
</Popup>
@potatoqualitee
potatoqualitee / Show-WPFExample.ps1
Created November 27, 2015 11:29
WPF + PowerShell + SQL super simple example
# Load WPF Assemblies
Add-Type -AssemblyName PresentationFramework
# Get the info you need from SQL Server
$sqlserver = "sqlserver2014a"
$query = "select name from master.dbo.sysdatabases order by name"
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Data Source=$sqlserver;Integrated Security=True;Connection Timeout=3"
$conn.Open()
@potatoqualitee
potatoqualitee / dbcombobox.ps1
Created November 27, 2015 12:07
Classic Forms Get-DBComboBox example
$sqlserver = "sqlserver2014a"
Function Get-SqlDatabases {
param(
[Parameter(Mandatory=$true)]
[string]$SqlServer,
[object]$Credential
)
$paramconn = New-Object System.Data.SqlClient.SqlConnection
@potatoqualitee
potatoqualitee / LoginReport.ps1
Last active May 11, 2016 15:19
SQL Login Report in PowerShell
# Solution for http://powershell.com/cs/forums/t/23737.aspx
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO")
$server = New-Object Microsoft.SqlServer.Management.Smo.Server "sqlserver"
$servername = $server.netname
$sqlinstancename = $server.DomainInstanceName
$dbs = $server.databases | Where-Object { 'tempdb','Pubs','Northwind','model' -notcontains $_.Name }
$loginreport = @()
foreach ($db in $dbs) {
$users = $db.users | Where-Object { 'guest','sys','INFORMATION_SCHEMA'-notcontains $_.Name -and $_.Name -notlike '*##*' -and $_.Name -notlike '*$*' -and $_.Name -ne $null }