First Weekday of Month
# Get first day of Month $FirstWeekDay = Get-Date $date.Date -day 1 # if day is Sat or Sun add days until it is not while(0,6 -contains $FirstWeekDay.DayOfWeek.value__){ $FirstWeekDay = $FirstWeekDay.AddDays(1) } $FirstWeekDay
Last Weekday of Month
# Get last day of Month $LastWeekDay = (Get-Date $date.Date -day 1).AddMonths(1).AddMilliseconds(-1) # if day is Sat or Sun subtract days until it is not while(0,6 -contains $LastWeekDay.DayOfWeek.value__){ $LastWeekDay = $LastWeekDay.AddDays(-1) } $LastWeekDay
Input Box Pop-up
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null $Value = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a value", "Title", $null)
Yes/No Prompt
$yes = new-Object System.Management.Automation.Host.ChoiceDescription "&Yes","help" $no = new-Object System.Management.Automation.Host.ChoiceDescription "&No","help" $choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no) $answer = $host.ui.PromptForChoice("Prompt","Click yes to continue",$choices,0) if($answer -eq 0){ Write-Host "You clicked Yes" }elseif($answer -eq 1){ Write-Host "You clicked No" }
Generate Random Names
Function Get-RandomNames{ [CmdletBinding()] [OutputType([Object])] param( [Parameter(Mandatory=$false)] [int] $count=10 ) $Webfemale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-female-first.txt" $Webmale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-male-first.txt" $WebSurname = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-surnames.txt" $female = @() $female = $Webfemale.Content.Split("`n").Trim() | ?{$_.length -gt 2} $male = @() $male = $Webmale.Content.Split("`n").Trim() | ?{$_.length -gt 2} $Surname = @() $Surname = $WebSurname.Content.Split("`n").Trim() | ?{$_.length -gt 2} $names = @() for($i=0; $i -ne $count; $i++) {...
Round to the Nearest Half
[math]::Round($number * 2, [MidpointRounding]::AwayFromZero) / 2
Switch Statement
switch ($value) { 1 {"It is one."} 2 {"It is two."} 3 {"It is three."} 4 {"It is four."} }