Skip to content

Instantly share code, notes, and snippets.

View VertigoRay's full-sized avatar
🔌
😏

Raymond Piller VertigoRay

🔌
😏
View GitHub Profile
@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
<#
.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
$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()
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
}
@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"
@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 / CatchLineNumbers.ps1
Last active January 15, 2017 06:01
The `$MyInvocation.ScriptLineNumber` variable is not the Current Line Number. It’s the Line number from where the function that you’re in was called. Actual line numbers can be caught for an error if you catch them. Used in this comment: http://goo.gl/7oeSEL
function a {
param(
[string]$UninstallString = 'thing'
)
$MyInvocation
Write-Host -Fore Cyan "$($here.File) $($MyInvocation.MyCommand):$($MyInvocation.ScriptLineNumber)"
b
try {
Throw('Thing!!!!')
@VertigoRay
VertigoRay / Get-FileEncoding.ps1
Last active November 24, 2023 20:51
Get-FileEncoding function determines encoding by looking at Byte Order Mark (BOM).
<#
.SYNOPSIS
Gets file encoding.
.DESCRIPTION
The Get-FileEncoding function determines encoding by looking at Byte Order Mark (BOM).
Based on port of C# code from http://www.west-wind.com/Weblog/posts/197245.aspx
.OUTPUTS
System.Text.Encoding
.PARAMETER Path
The Path of the file that we want to check.
@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