Skip to content

Instantly share code, notes, and snippets.

View mwallner's full-sized avatar
🧙

Manfred Wallner mwallner

🧙
View GitHub Profile
@mwallner
mwallner / Get-LatestProcesses.ps1
Created March 20, 2019 10:47
get 'youngest' process with some filter possibilites
param(
[Parameter(Mandatory = $False)]
[int]$NumberOfProcesses = 1,
[Parameter(Mandatory = $False)]
[switch]$IncludeMicrosoftProcesses,
[Parameter(Mandatory = $False)]
[switch]$RequirePath,
# IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file:
#   $f='c:\path\to\thisFile.ps1'
#   gc $f | ? {$_ -notmatch "^\s*#"} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+".~" -en utf8; mv -fo $f+".~" $f
 
# 1. See the _TODO.md that is generated top level and read through that
# 2. Follow the documentation below to learn how to create a package for the package type you are creating.
# 3. In Chocolatey scripts, ALWAYS use absolute paths - $toolsDir gets you to the package's tools directory.
$ErrorActionPreference = 'Stop'; # stop on all errors
$toolsDir   = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
# Internal packages (organizations) or software that has redistribution rights (community repo)
@mwallner
mwallner / Install-SCCMUpdates.ps1
Last active December 5, 2024 02:56
install all available updates via SCCM
<#
.SYNOPSIS
Install all updates available via SCCM and WAIT for the installation to finish.
.PARAMETER Computer
the computer to install updates on
.OUTPUTS
a object containing information about the installed updates and the reboot state (if a reboot is required or not)
@mwallner
mwallner / Invoke-WithMockedEnv-Demo.ps1
Created July 4, 2019 19:20
"mocking" environment variables in a ScriptBlock
function Invoke-WithMockedEnv {
param(
[Parameter(ValueFromPipeline)]
[scriptblock]$ScriptBlock,
[Hashtable]$mockValues
)
@mwallner
mwallner / ps-jenkins-incosistency.md
Created July 23, 2019 13:01
PowerShell RemoteException incosistency when run via Jenkins

NOTE: This seems to only affect Win10 1809 LTSC and/or PowerShell 5.1.17763.1

I've got this demo-script, which I put into a Jenkins job:

Write-Host "##############################################"
$ErrorActionPreference = "Stop"

Write-Host "ErrorActionPreference: $ErrorActionPreference"
Write-Host "whoami: $(whoami)"
$PSVersionTable | Format-Table
$script:_https_certs = @{}
function Add-HTTPSCertificateCheck {
param(
[string]$Url,
[TimeSpan]$ValidityTime
)
@mwallner
mwallner / fzf-posh.md
Created September 27, 2019 09:15
using fzf to nagive directories in PowerShell

using fzf to nagive directories in PowerShell

simplest way: 1-liner

Set-Location (Get-Item $(fzf)).Directory.FullName

creating a function

@mwallner
mwallner / Chocolatey.ps1.md
Created October 19, 2019 09:12
Boxstarter-Chocolatey-Param-Troubleshooting

I modified function 'choco' in Chocolatey.ps1 to include some additional logging:

function choco {
<#
.SYNOPSIS
Intercepts Chocolatey call to check for reboots
@mwallner
mwallner / cmdlettest.ps1
Created January 14, 2020 21:26
powershell cmdet vs basic function argument handling
function Get-EvilCmdLet {
[CmdletBinding()]
param(
[ValidateSet('A', 'B')]
$Category
)
Write-Output "= Get-EvilCmdLet ="
Write-Output "* PSBoundParameters"
$PSBoundParameters.Keys | % {
@mwallner
mwallner / boxstarter-bootstrapper.md
Created February 3, 2020 19:53
using Boxstarter to overcome PowerShell v2 on Box deployments

using Boxstarter to overcome PowerShell v2 on Box deployments

Preparation (on a random host)

  • Install Chocolatey
  • choco install boxstarter -y
  • open "Boxstarter Shell"
  • create "Portable Boxstarter" see wiki