Skip to content

Instantly share code, notes, and snippets.

View kabtech's full-sized avatar

kabtech

View GitHub Profile
@kabtech
kabtech / PowerShellPasswordGenerator.md
Last active May 5, 2018 19:48
PowerShell - a basic, reasonably strong password generator that avoids some more problematic special characters #PowerShell

A basic, reasonably strong password generator that avoids some more problematic special characters

function Get-Password()
{
  $strUcase = Get-Random -Count 2 -InputObject (65..90) | % {[char]$_}
  $strLcase = Get-Random -Count 2 -InputObject (97..122) | % {[char]$_}
  $strSymbol = Get-Random -Count 1 -InputObject "!","^","-","_","."
  $strNumber = Get-Random -Count 1 -InputObject (50..57) | % {[char]$_}
 $strLcase2 = Get-Random -Count 2 -InputObject (97..122) | % {[char]$_}
@kabtech
kabtech / PowerShellCheckIfFileIsLocked.md
Last active April 9, 2018 12:06
PowerShell - check if file is locked #PowerShell

The following construct can be used so that $intLocked is an indicator whether you may access a file to write:

try { [IO.File]::OpenWrite($FilePath).close();$intLocked = 0}
catch{$intLocked = 1}
@kabtech
kabtech / PowerShellPasteIntoArray.md
Last active April 9, 2018 12:04
PowerShell - setup an array-input construct which awaits pasted list to populate the array #PowerShell

Hit ctrl-C after you paste, at which point your populated array is ready for use.

$arrList = @();while (!$strStop){$arrList += read-host "Next entry:"}

Or...use a construct like this if you want to be able to signal to a running script that you are done pasting entries:

while ($arrList -notcontains "swordfish"){$arrList += read-host "Paste list or type 'swordfish' to indicate paste is done"}
@kabtech
kabtech / PowerShellCurlAlternatives.md
Last active March 18, 2018 12:05
PowerShell curl alternatives -- methods not dependent on PSVersion. #PowerShell

CURL equivalent that is not dependent on PowerShell version. NOTE that there is also a .DownloadFile method:

$webclient.DownloadString('http://google.com')

CURLs that intentionally constrain the cryptography protocol:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;