Skip to content

Instantly share code, notes, and snippets.

Avatar
🕵️‍♂️
Investigating a better artifact workflow

Jake Morrison techthoughts2

🕵️‍♂️
Investigating a better artifact workflow
View GitHub Profile
@techthoughts2
techthoughts2 / CustomPSObject
Last active Jun 11, 2020
Several examples of creating and working with custom PowerShell objects and hash tables. Examples include creating customer Powershell objects that contain multiple values.
View CustomPSObject
#Jake Morrison - @jakemorrison - http://techthoughts.info
$results = [PSCustomObject]@{
HypTotal = $hyptotal
MgmtVMTotal = $mgmtVMTotal
UniqueCustomerCount = $customerTotal
TotalComputerObjects = $allCompsTotal
TotalUserObjects = $userTotal
}
View argument_completer
function test-arg {
[cmdletbinding()]
param(
[ArgumentCompleter({'mouse','house','goat'})]
$GreenEggs
)
$greeneggs
}
@techthoughts2
techthoughts2 / ps_Errors.ps1
Last active Feb 17, 2020
Working with PowerShell Errors
View ps_Errors.ps1
function Reset-Errors {
$Global:Error.Clear()
$psISE.Options.ErrorForegroundColor = '#FFFF0000'
$Global:ErrorView = 'NormalView'
}
Reset-Errors
#generate an error
function Show-Error {
Get-Item c:\doesnotexist.txt
View argument_completer
function Get-Something {
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[ArgumentCompleter( {
@(
"keys"
"wallet"
"phone"
)
View select_property
$top50 = $community `
| Sort-Object { [int]$_.AdditionalMetadata.downloadCount } -Descending `
| Select-Object Name, @{N = "Downloads"; E = { $_.AdditionalMetadata.downloadCount } } -First 50
View ps1xml
Update-FormatData -AppendPath 'C:\ProjectName.Format.ps1xml'
# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @(
'ProjectName.Format.ps1xml'
)
$item.PSObject.TypeNames.Insert(0, 'The.Name.Here')
View ps_random
# Get Random Stuff
-join (33..126 | %{ [char]$_ } | Get-Random -Count 16)
@techthoughts2
techthoughts2 / Gallery.ps1
Last active Dec 20, 2019
PowerShell Gallery Commands
View Gallery.ps1
View suppress
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingCmdletAliases", "", Justification = "Invoke-Build is alias only")]
param ()
You can’t perform that action at this time.