Skip to content

Instantly share code, notes, and snippets.

@milesgratz
milesgratz / Run-CustomFunction-DoubleHop.ps1
Created June 12, 2017 16:39
Custom function to start Invoke-Command "jobs" on remote systems ... but with double hop consideration
$FirstHop = "Server1"
$SecondHop = "Server2"
$Cred = Get-Credential
Function Run-CustomFunction {
param(
$FirstHop,
$SecondHop,
$Cred
)
@milesgratz
milesgratz / Replace-individual-rows-in-CSV.ps1
Created June 12, 2017 18:44
Replace an individual rows in a CSV by indexing
<#
Replace individual rows in a CSV
(if there are no multiline rows)
Define example input file
City Zipcode
---- -------
Phoenix, AZ 85001
Little Rock, AR 72201
@milesgratz
milesgratz / parse_powershell_ise_theme.ps1
Created June 15, 2017 13:52
Parse PowerShell_ISE theme for RGB values
$File = 'C:\Users\miles.gratz\desktop\Dark Console Light Editor default.StorableColorTheme.ps1xml'
$Content = Get-Content $file
$Results = @()
$Index = 0
foreach ($line in $content)
{
if ($line -match "\<string\>")
{
$key = (($line -split "<string>")[1] -split "</string>")[0]
$object = New-Object PSCustomObject
@milesgratz
milesgratz / Update-machine-certificate-private-key-permissions.ps1
Created May 31, 2019 17:40
PowerShell example of updating machine certificate private key permissions (CAPI vs CNG)
# Get cert on local computer by thumbprint
$thumbprint = '89D3FC64B6405E161EDC7A4CF14E111F5F6895AA'
$Cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Thumbprint -eq $thumbprint }
###################################################
# Manage private key of CAPI cert
###################################################
# Find private key
$privKey = $Cert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName