Skip to content

Instantly share code, notes, and snippets.

@mhudasch
mhudasch / Update-PSModule.ps1
Last active April 12, 2025 17:09
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 / 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 / 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 / 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 / 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;