Skip to content

Instantly share code, notes, and snippets.

@mhudasch
mhudasch / Get-PendingWindowsUpdate.ps1
Last active June 12, 2018 08:27
Find pending windows updates.
Function Get-PendingWindowsUpdate {
[CmdletBinding()]
param(
[Parameter(Position = 0, ValueFromPipeline = $true)]
[string[]]$ComputerName = $env:COMPUTERNAME)
Process {
# Use this scriptblock for both remote and local execution
$unifiedScriptBlock = [scriptblock]{
param([string]$computer)
$ErrorActionPreference = $using:ErrorActionPreference;
@mhudasch
mhudasch / Install-WindowsUpdate.ps1
Last active June 4, 2024 14:04
Installs all pending windows updates or updates piped from Get-PendingWindowsUpdate.
Function Install-WindowsUpdate {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Position = 0, Mandatory=$false, ValueFromPipeline = $true, ParameterSetName="computer")]
[string[]]$ComputerName = $env:COMPUTERNAME,
[Parameter(Position = 0, Mandatory=$true, ValueFromPipeline = $true, ParameterSetName="updates")]
[PSCustomObject[]]$PendingUpdates)
Process {
@mhudasch
mhudasch / Set-FileSystemItem.ps1
Last active September 23, 2016 09:29
The Set-FileSystemItem command is the easiest way to create new, empty files. It is also used to change the timestamps (i.e., dates and times of the most recent access and modification) on existing files.
Function Set-FileSystemItem {
<#
.SYNOPSIS
The Set-FileSystemItem command is the easiest way to create new, empty files. It is also used to change the timestamps (i.e., dates and times of the most recent access and modification) on existing files.
.DESCRIPTION
The Set-FileSystemItem command is used to update the access date and / or modification date of a file. In its default usage, it is the equivalent of creating or opening a file and saving it without any change to the file contents. Touch eliminates the unnecessary steps of opening the file, saving the file, and closing the file again. Instead it simply updates the dates associated with the file or directory. An updated access or modification date can be important for a variety of other programs such as backup utilities. Typically these types of programs are only concerned with files which have been created or modified after the program was last run. Set-FileSystemItem can also be useful for quickly creating files for programs or scripts that require a f
@mhudasch
mhudasch / New-PSModule.ps1
Created August 31, 2016 15:50
The New-PSModule command creates a convention based folder structure to develop a new powershell module. In addition the command automatically creates a module manifest file (.psd1).
<#
.SYNOPSIS
The New-PSModule command creates a convention based folder structure to develop a new powershell module. In addition the command automatically creates a module manifest file (.psd1).
.DESCRIPTION
The New-PSModule command creates a convention based folder structure to develop a new powershell module. The folder structure contains a folder for exported functions (public) and a folder for internal functions (private). Furthermore the structure contains a folder for test-scripts (Tests) and a folder with handy scripts to analyze and publish the created module.
In addition the command automatically creates a module manifest file (.psd1). The manifest file will be filled with the given parameters. The parameters of this command do only cover the bare minimum requirements of the manifest file. The file must be changed to complete all metadata.
@mhudasch
mhudasch / Update-PSModule.ps1
Last active February 9, 2017 20:45
Real update of modules
Function Update-PSModule {
<#
.SYNOPSIS
Contrary to Update-Module command this command removes all previous versions of the module automatically.
.DESCRIPTION
The Update-PSModule command tries to find the current version of the given module. If there is a new version of the module
available the command removes all previous versions of the module and installs the new version. When the newest version of
the module is already installed the command does nothing unless the Force parameter is present. In case the Force parameter
is present the module will always be reinstalled with the newest available version.
@mhudasch
mhudasch / Write-Robot.ps1
Created September 20, 2016 22:19
Draw a waiting wall-e
Function Robot {
$overallIndex = 0;
$cx = $Host.UI.RawUI.CursorPosition.X;
$cy = $Host.UI.RawUI.CursorPosition.Y;
$left = 0;
$right = $Host.UI.RawUI.BufferSize.Width;
$sIdx = 0;
$uIdx = 0;
$stg = "walk";
@mhudasch
mhudasch / Read-Choice.ps1
Last active October 27, 2016 16:01
Test of Input mask for PS
#requires -version 5
Set-StrictMode -Version Latest
Function Read-Input {
[Diagnostics.CodeAnalysis.SuppressMessage("PSAvoidUsingWriteHost", "", Justification = "This is an interface cmdlet that should be seen in its host.")]
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=1)]
[string]$Message,
[Parameter(Mandatory=$false, Position=2)]
@mhudasch
mhudasch / Add-EnvironmentPath.ps1
Last active September 27, 2016 14:41
Add a path to the machine PATH environment variable
Function Add-EnvironmentPath {
<#
.SYNOPSIS
Adds a path to the PATH environment variable at give scope.
.DESCRIPTION
Adds a Path to the PATH environment variable stored in the current process or in the Windows operating system registry key reserved for the current user or local machine.
In addition to that the command sorts the paths and removes duplicates.
.PARAMETER Path
@mhudasch
mhudasch / Invoke-ScheduledCommand.ps1
Last active February 9, 2017 20:44
Invoke a command via the task scheduler on any computer
#requires -version 5
Set-StrictMode -Version Latest
Function Invoke-ScheduledCommand {
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This re-establishes the global environment preferences. They can be used all over child scripts.")]
[OutputType("ScheduledCommandResult[]")]
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[String]$TaskName,
@mhudasch
mhudasch / Add-StartupCommand.ps1
Created October 13, 2016 15:57
Schedule an auto-start command to a remote machine with given rights and integrated cleaup after it ran leaving possible piped results.
#requires -version 5
Set-StrictMode -Version Latest
Function Add-StartupCommand {
[OutputType("ScheduledCommand")]
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[String]$TaskName,
[Parameter(Mandatory=$true,Position=1)]