Skip to content

Instantly share code, notes, and snippets.

function Get-DateRange {
Add-Type -AssemblyName System.Windows.Forms
$form = new-object Windows.Forms.Form
$form.text = "Calendar"
$form.Size = new-object Drawing.Size @(656,639)
# Make "Hidden" SelectButton to handle Enter Key
$btnSelect = new-object System.Windows.Forms.Button
$btnSelect.Size = "1,1"
$btnSelect.add_Click({
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@DBremen
DBremen / whereEx.ps1
Last active August 16, 2022 03:26
Proof of concept on how a simplified Where-Object for multiple conditions on the same property could be implemented
function whereEx {
[CmdletBinding()]
Param
(
[Parameter(ValueFromPipeline=$true)]
$InputObject,
[Parameter(Mandatory=$true,
Position=0)]
$predicateString
@DBremen
DBremen / Get-FileWCSynchronous.ps1
Last active August 16, 2022 03:26
Download files using the DownloadFile method of the WebClient class within the System.Net Namespace
function Get-FileWCSynchronous{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
$wc = New-Object Net.WebClient
$wc.UseDefaultCredentials = $true
$destination = Join-Path $destinationFolder ($url | Split-Path -Leaf)
@DBremen
DBremen / RegEx.Replace.ps1
Created August 21, 2015 15:28
RegEx.Replace Examples
#Increase a number within a string by one
$data = 'XX3.txt', 'XX33.txt', 'XX333.txt'
$data | foreach{
[RegEx]::Replace($_, '(\d{1,3})', {1+$args[0].Value})
}
#Capitalize the second word within a sentence string
$script:counter = 0
[regex]::Replace('this is a test','\w+', {
$script:counter++
if ($counter -eq 2){
@DBremen
DBremen / bing.ps1
Last active August 16, 2022 00:48
Usage of Bing Search and Synonyms API through PowerShell
#https://datamarket.azure.com/account/keys
#Home -> My Account -> Account Keys:
#based on http://www.powershelladmin.com/wiki/Accessing_the_Bing_Search_API_v2_using_PowerShell
function Get-BingSearchResult($query){
Add-Type -Assembly System.Web
$Key = 'YOURACCOUNTKEY'
$Base64KeyBytes = [byte[]] [Text.Encoding]::ASCII.GetBytes("ignored:$Key")
$Base64Key = [Convert]::ToBase64String($Base64KeyBytes)
$QueryString = '%27' + [Web.HttpUtility]::UrlEncode($query) + '%27'
@DBremen
DBremen / Get-FileBitsTransferAsynchronous.ps1
Last active August 16, 2022 00:48
Download files using Start-BitsTransfer in asynchronous mode
function Get-FileBitsTransferAsynchronous{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
$start = Get-Date
$job = Start-BitsTransfer -Source $url -Destination $destinationFolder -DisplayName 'Download' -Asynchronous
$destination = Join-Path $destinationFolder ($url | Split-Path -Leaf)
@DBremen
DBremen / parseExact.ps1
Created June 29, 2020 19:41
DateTime.parseExact example
[datetime]::ParseExact('08|12|2009 4:33 PM','dd|MM|yyyy h:m tt',$Null)
#returns Tuesday, December 8, 2009 4:33:00 PM on an English system
@DBremen
DBremen / PromptForChoice.ps1
Created September 10, 2015 08:19
Usage of built-in PromptForChoice
$Title = "Title"
$Info = "Pick Something!"
$options = echo Option1 Option2 Option3
$defaultchoice = 2
$selected = $host.UI.PromptForChoice($Title , $Info , $Options, $defaultchoice)
$options[$selected]
@DBremen
DBremen / POP_SimplifiedSelect.ps1
Last active August 16, 2022 00:47
Proof of concept: Simplified syntax for calculated Properties with Select-Object
function mySelect {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true)]
[psobject]$InputObject,
[Parameter(Position=0)]
$Property
)
begin{
#only if the property array contains a hashtable property