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 / sig.ps1
Last active December 22, 2015 20:09
Geeky signature line I stumbled across and modified for myself …
[string](0..9|%{[char][int](32+("54698284737179506589").substring(($_*2),2))})-replace "\s{1}\b"
try {
foreach ($res in $Search.FindAll())
{
$User = $res.GetDirectoryEntry()
$NewObject = New-Object PSObject
Add-Member -InputObject $NewObject NoteProperty 'DistinguishedName' $User.DistinguishedName
Add-Member -InputObject $NewObject NoteProperty 'SamAccountName' $User.SamAccountName
$OutputList += $NewObject
}
$forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name
$ADsPath = [ADSI]"GC://$forestName"
$Search = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)
$Search.Filter = "(&(objectCategory=User)(SamAccountName=user0123))"
$Search.FindAll()
<#
.SYNOPSIS
Get Computers by Last Logged on User via SCCM.
.DESCRIPTION
Queries SCCM for the list of computer’s whose last logged on user matches the supplied SamAccountName.
.PARAMETER SamAccountName
For users, this is typically their EUID. Non-user accounts may vary.
.PARAMETER SiteName
SCCM Server Site Name.
.PARAMETER SCCMServer
@VertigoRay
VertigoRay / top.sls
Created August 23, 2013 00:43
pillar top.sls
base:
'*':
- is_test_computer
dev:
'is_test_computer:True':
- match: pillar
- apps.dsconfigad
- apps.munki
@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 %}
@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 / 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 / InstallFirefox.ps1
Last active June 8, 2016 15:31
You'll want to sign the code so you can run it without changing the execution policy to unrestricted. Sample Usage: InstallFirefox.ps1 22.0 http://go.vertigion.com/PowerShell-InstallFirefox
Param (
[parameter(
Position = 0,
Mandatory = $true,
HelpMessage = 'This is the version number, such as "22.0". Valid version numbers can be found here: http://mzl.la/1c9hPmo'
)]
[string] $version,
[parameter(
Position = 1,
Mandatory = $false,