View Test-URL.ps1
ForEach ($URL in $URLs) {
Write-Host $URL -NoNewline ": "
Try {
Invoke-WebRequest $URL -UseBasicParsing | Out-Null
Write-Host ('Yup','Looks Good','OK' | Get-Random) -ForegroundColor Green
}Catch{
Write-Host $_ -ForegroundColor Red
}
}
View Get-CoinFlip.ps1
Function Get-CoinFlip {
Param(
$Heads = 'Heads',
$Tails = 'Tails'
)
Get-Random $Heads,$Tails
}
View Format-ColourList.ps1
Function Format-ColourList {
Param(
#The input object to be formatted.
[Parameter(Position=0,ValueFromPipeline)]
$InputObject,
#A hashtable of text to colour and the colour of that text. By default colours 'True' as Green and 'False' as Red.
[Hashtable]$Colour = @{True = 'Green'; False = 'Red'}
)
Begin {
View Install.ps1
[cmdletbinding()]
Param()
<#
.SYNOPSIS
Installs a module.
#>
Function Install-Module {
[cmdletbinding(SupportsShouldProcess)]
Param (
View working-days.ps1
#As a function
Function Get-WorkingDays ($Date) {
(0..((Get-Date $Date) - (Get-Date)).days | % { (Get-Date).AddDays($_) } | Where-Object DayOfWeek -notin 'Saturday','Sunday').count
}
Get-WorkingDays 15/09/2017
#One liner
(0..((Get-Date '15/09/2017') - (Get-Date)).days | % { (Get-Date).AddDays($_) } | ? DayOfWeek -notin 'Saturday','Sunday').count
View SO-UsefulComments.md

New User

Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve).

Code Writing

View Remove-WhiteSpace.ps1
function Remove-WhiteSpace {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Path
,
[Parameter()]
[string]$Encoding = 'UTF8' #type FileSystemCmdletProviderEncoding is not public and does not match [System.Text.Encoding
)
process {
View Write-Log.ps1
function Write-Log {
Param(
$Message,
$Path = "$env:USERPROFILE\log.txt"
)
function TS {Get-Date -Format 'hh:mm:ss'}
"[$(TS)]$Message" | Tee-Object -FilePath $Path -Append | Write-Verbose
}
View cardgame.ps1
#Generate the deck
$Suits = 'Hearts','Diamonds','Spades','Clubs'
$Pack = ForEach ($Suit in $Suits) {
2..10 + 'Jack','Queen','King','Ace' | ForEach-Object { "$_ of $Suit" }
}
#Shuffle the deck between 1 and 5 times
1..(Get-Random -Min 1 -Max 5) | ForEach-Object { $Pack = $Pack | Sort-Object {Get-Random} }
#Deal 5 cards to each player and sort them in natural order
View Calculated-Expression-Examples.ps1
#https://technet.microsoft.com/en-us/library/ff730948.aspx
Get-Process
Get-Process | Select-Object Name, VM, PM -First 10
Get-Process | Select-Object Name, @{name='VirtualMemory (MB)'; expression={$_.VM / 1MB}}, PM -First 10
Get-Process | Select-Object Name, @{name='VirtualMemory (MB)'; expression={ '{0:N2}' -f ($_.VM / 1MB)}}, PM -First 10