Skip to content

Instantly share code, notes, and snippets.

@DBremen
DBremen / Get-FileWCAsynchronous.ps1
Last active August 16, 2022 00:45
Download files using the DownloadFileAsync method of the WebClient class within the System.Net Namespace
function Get-FileWCAsynchronous{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
$wc = New-Object Net.WebClient
$wc.UseDefaultCredentials = $true
$file = $url | Split-Path -Leaf
@DBremen
DBremen / Get-FileBitsTransferSynchronous.ps1
Last active October 27, 2015 12:58
Download files using Start-BitsTransfer in synchronous mode
function Get-FileBitsTransferSynchronous{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
Import-Module BitsTransfer
$destination = Join-Path $destinationFolder ($url | Split-Path -Leaf)
$start = Get-Date
@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 / 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-ZenCode.ps1
Last active August 16, 2022 03:30
Expand zen coding expression for PowerShell
#requires zenCoding.dll in \resources. Download via https://github.com/madskristensen/zencoding and compile.
function Get-ZenCode{
[Alias("zenCode")]
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
Position=0)]
$zenCodeExpr,
[Parameter(ValueFromPipeline=$true,
@DBremen
DBremen / Get-WmiPowerShell.ps1
Last active March 16, 2017 12:46
Query WMI with PowerShell syntax
function Get-WmiPowerShell {
[CmdletBinding()]
Param
(
[Parameter(Mandatory)]$Class,
[Parameter(Mandatory)]$Filter
)
$errors = $tokens = $null
$AST= [Management.Automation.Language.Parser]::ParseInput($filter.ToString().Replace('$null','NULL'), [ref]$tokens, [ref]$errors)
$tokens = $tokens | where { $_.Text -and $_.Name -ne '_' -and $_.Kind -ne 'Dot' }
@DBremen
DBremen / WMIProxyCommands.ps1
Created November 13, 2015 14:25
Proxy commands for Get-WmiObject and Get-CimInstance that support PowerShell query syntax via 'PowerShellFilter' paramater
foreach ($command in ('Get-WmiObject','Get-CimInstance')){
$Metadata = New-Object System.Management.Automation.CommandMetaData (Get-Command $command)
$proxyCmd = [System.Management.Automation.ProxyCommand]::Create($Metadata) #| clip
if ($command -eq 'Get-WmiObject'){
$newParam = @'
[Parameter(ParameterSetName='query')]
[ScriptBlock]
$PowerShellFilter,
'@
}
@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
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({
@DBremen
DBremen / Get-Uninstaller.ps1
Last active February 14, 2016 19:27
Retrieve Uninstall information for software packages from the registry
function Get-Uninstaller {
[CmdletBinding()]
Param(
$DisplayName = '*',
[ValidateSet('HKLM', 'HKCU')]
[string[]]$Hive = @('HKLM','HKCU')
)
$keys =@'
:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall