Skip to content

Instantly share code, notes, and snippets.

View VertigoRay's full-sized avatar
🔌
😏

Raymond Piller VertigoRay

🔌
😏
View GitHub Profile
@VertigoRay
VertigoRay / pre-commit
Created March 25, 2014 18:31
Test pre-commit hook
#!/bin/sh
# Line to test if POSH is even executing
/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command "Get-Location | Out-File C:\Temp\test.txt"
if /c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command "If ((Get-AuthenticodeSignature .\install.ps1).Status -ne 'Valid') { Exit 1 }"
then
cat <<\EOF
The install.ps1 file has a valid signature.
EOF
@VertigoRay
VertigoRay / Write-Json
Last active August 29, 2015 14:05
Write a Json object in human readable format. The `$json` parameter expects a Json object, returned from `ConvertFrom-Json`. More Info: http://blog.vertigion.com/post/94476016067/powershell-write-json
function Write-Json {
param(
[Parameter(
Mandatory=$true,
HelpMessage = "Json object to be printed out in human readable format."
)][PSCustomObject]$Json,
[int]$tab=1,
[bool]$array=$false
)
@VertigoRay
VertigoRay / Pause.ps1
Created February 4, 2015 00:11
Mimics the command prompt Pause command.
<#
.SYNOPSIS
Mimics the command prompt Pause command.
.DESCRIPTION
Powershell doesn't have a Pause command that Prompts the user with "Press any key to continue..." and waits for a response.
This brings that command to PowerShell and allows you to customize the message.
.PARAMETER Message
The paused Message can be customzied by passing a string.
.INPUTS
@VertigoRay
VertigoRay / SCCM2012-DeleteInvalideDrivers.ps1
Last active December 14, 2015 09:50
SCCM 2012 - Driver Importing. This code to deletes drivers with bad sources.
$a = (Get-WmiObject -ComputerName 'myserver.fqdn' -Namespace 'root\SMS\Site_XXX' -Class 'SMS_Driver' | ?{!(test-path $_.ContentSourcePath)})
$a | %{$_.delete()}
@VertigoRay
VertigoRay / ServiceRecovery.cmd
Last active December 14, 2015 12:29
Used with Win Service Recovery to recover servers that Exit Unclean. Will log to file and retry n times. Implementation Screenshots: http://imgur.com/a/dmqq8
@echo off
setlocal
SET /A RETRYMAX=10
SET LOG=%SystemRoot%\Logs\ServiceRecovery.log
FOR /F "tokens=2*" %%a in ('sc query %1 ^| findstr STATE') do SET STATUS=%%b
SET STATUS=%STATUS: =%
IF ERRORLEVEL 1 goto _errawr
IF "%STATUS%"=="4RUNNING" goto:eof
@VertigoRay
VertigoRay / ProductsInstalled.vbs
Created March 5, 2013 16:49
This will Query WMI for all of the Programs installed with Windows Installer - which covers about 90% of our supported applications. Results are written to ProductsInstalled.txt in the Working Dir.
Option Explicit
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Usage:
' cscript.exe ProductsInstalled.vbs
'
' Description:
' This will Query WMI for all of the Programs installed with Windows Installer - which covers about 90%
' of our supported applications. Results are written to ProductsInstalled.txt in the Working Dir.
'
' Output Format:
@VertigoRay
VertigoRay / Uninstaller.vbs
Last active December 14, 2015 13:09
This will Query WMI for the specified program and uninstall it with Windows Installer - which covers about 90% of our supported applications. All actions are logged to %SystemRoot%\Logs\SCCM.
Option Explicit
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Usage:
' cscript.exe Uninstaller.vbs ApplicationName [LogFileName]
'
' Parameters:
' ApplicationName The Product Name of the Program you want to Uninstall. This will
' remove all instances of the program, so be as specific as you want.
' - Example: "Adobe" would remove all Adobe products (anything with Adobe in the Name)
' - Example: "Adobe Reader" will remove all versions of Adobe Reader.
@VertigoRay
VertigoRay / gist:6091753
Last active December 20, 2015 07:09
If you're possibly working with unclean data (or typo the DC structure) while checking if OU exists, you'll need to catch your errors.
[string] $Path = 'OU=foo,OU=test,DC=domain,DC=com'
try {
$ou_exists = [adsi]::Exists("LDAP://$Path")
} catch {
# If invalid format, error is thrown.
Throw("Supplied Path is invalid.`n$_")
}
if (-not $ou_exists) {
Throw('Supplied Path does not exist.')
@VertigoRay
VertigoRay / gist:6091801
Last active December 20, 2015 07:09
In my case, I only work within a particular OU in our Domain, so I’ve made it so my $Path can be abbreviated. Forked (https://gist.github.com/VertigoRay/6091753) ... here’s how I handle things:
[string] $RootOU = 'OU=test,DC=domain,DC=com'
[string] $Path = 'OU=foo'
try {
$ou_exists = [adsi]::Exists("LDAP://$Path")
} catch {
# If invalid format, error is thrown.
Write-Debug "Supplied Path is invalid.`n$_"
# It's probably the abbreviated version, so let's tack on the Root OU and confirm exists.
Write-Debug 'Placing Path in Root OU and re-verifying ...'
$Path = "$Path,$RootOU"
@VertigoRay
VertigoRay / is_test_computer.sls
Created August 23, 2013 00:40
List of test computers
{% for computer in 'TEST001','TEST002','TEST003' %}
{% if grains['nodename'] == computer %}
is_test_computer: True
{% else %}
is_test_computer: False
{% endif %}
{% else %}
is_test_computer: False
{% endfor %}