Last active
May 9, 2024 19:52
-
-
Save bruno-brant/bed689ce6cb1d2fc075d81f35cb78653 to your computer and use it in GitHub Desktop.
PowerShell Toolbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SUMMARY | |
Restart a list of computers using shutdown.exe. | |
#> | |
function Invoke-ComputerRestart { | |
[CmdletBinding()] | |
param ( | |
# List of computers to shutdown | |
[Parameter(ValueFromPipeline = $true)] | |
[string[]]$Computer, | |
# How many seconds to sleep between calls. If 0, calls are made in parallel. | |
[Parameter()] | |
[int] $SleepSeconds = 0 | |
) | |
if ($SleepSeconds -eq 0) { | |
Invoke-Command -Computer $Computer -ScriptBlock { | |
shutdown /r /t 0 | |
} | |
} | |
foreach ($comp in $Computer) { | |
Invoke-Command -Computer $comp -ScriptBlock { | |
shutdown /r /t 0 | |
} | |
} | |
} | |
<# | |
.SUMMARY | |
Writes a list of items filtering by uniqueness. Does it continuously, can be used for optimizing output on long lists. | |
#> | |
function Show-UniqueItems { | |
[CmdletBinding()] | |
param ( | |
# The list of items to print. | |
[Parameter(ValueFromPipeline = $true)] | |
[ValidateNotNullOrEmpty()] | |
[object]$InputObject | |
) | |
begin { | |
$seenItems = @{} | |
} | |
process { | |
foreach ($item in $InputObject) { | |
if (-not $seenItems.ContainsKey($item)) { | |
Write-Host $item | |
$seenItems[$item] = $true | |
} | |
Write-Output $item | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment