Skip to content

Instantly share code, notes, and snippets.

# Change Path
$path = "$env:userprofile\Downloads\Takeout\YouTube and YouTube Music\history\watch-history.json"
# $path2 = 'C:\Users\Mercier\Downloads\Takeout\YouTube and YouTube Music\history\search-history.json' # NOT USED
$Params = @{
# Remove the "Watched" keyword from the title (might be another keyword in your language or default to english...)
# Do not change if not needed
function Test-Port ($Hostname = 'yahoo.com', $Port = 80, $Timeout = 100) {
$requestCallback = $state = $null
$client = [System.Net.Sockets.TcpClient]::new()
$iar = $client.BeginConnect($Hostname, $Port, $null, $null)
$wait = $iar.AsyncWaitHandle.WaitOne($Timeout, $false)
if (!$wait) {
$client.Close()
$open = $false
}
else {
@itfranck
itfranck / AutomaticVariable.ps1
Last active January 19, 2020 21:44
Create a new automatic variable / PSScriptRootAlternative
$Now = new-object psobject
$Now.psobject.members.add((new-object System.Management.Automation.PSScriptMethod "ToString", { Get-Date }))
@itfranck
itfranck / New-CMSSelfSignedCertificate.ps1
Last active March 26, 2020 13:44
Create Document Encryption certificate for Protect-CMSMessage / UnprotectCMSMessage use
$CertParams = @{
CertStoreLocation = 'Cert:\CurrentUser\My'
Subject = 'ttt'
KeyExportPolicy = 'Exportable'
NotAfter = (get-date).AddYears(1000)
}
New-SelfSignedCertificate @CertParams -Provider 'Microsoft Enhanced Cryptographic Provider V1.0' -KeyAlgorithm 'RSA' -KeyLength 4096 -Type 'DocumentEncryptionCert' -KeySpec 'KeyExchange'
#
@itfranck
itfranck / BrainCandy.ps1
Created August 31, 2019 02:03
BrainCandy
for ($i = 1; $i -lt 10; $i++) {
$Currentnumstr = "$Currentnumstr$i"
Write-Host "$($Currentnumstr.PadLeft(9,' ')) x " -NoNewline
Write-Host "8" -NoNewline -ForegroundColor Red
Write-Host " + $i = $([int]$Currentnumstr * 8 + $i)"
}
@itfranck
itfranck / Search.ps1
Created April 13, 2019 23:34
Put in profile - use interactively to search stuff
Function Search-Gist {$str = "https://gist.github.com/search?utf8=%E2%9C%93&q=language%3APowerShell+%s"; Start-Process ($str -replace '%s', [System.Web.HttpUtility]::UrlEncode([String[]]$args)) }
Function Search-Github {$str = "https://github.com/search?utf8=%E2%9C%93&q=language%3APowerShell+%s&type=Code"; Start-Process ($str -replace '%s', [System.Web.HttpUtility]::UrlEncode([String[]]$args -join ' '))}
Function Search-Google {$str = "https://www.google.ca/search?q=%s"; Start-Process ($str -replace '%s', [System.Web.HttpUtility]::UrlEncode([String[]]$args -join ' '))}
Function Search-Reddit {$str = "https://www.reddit.com/r/PowerShell/search?q=%s&restrict_sr=1"; Start-Process ($str -replace '%s', [System.Web.HttpUtility]::UrlEncode([String[]]$args)) }
Function Search-StackOverflow {$str = "https://stackoverflow.com/search?q=%5BPowershell%5D+%s"; Start-Process ($str -replace '%s', [System.Web.HttpUtility]::UrlEncode([String[]]$args)) }
@itfranck
itfranck / Start-UDHotReloader.ps1
Last active January 4, 2019 20:12
Modified Start-UDHotReloader from Adam Driscoll that includes an app pool restart when a file in the Endpoints subdirectory is modified so the changes are applied nearly instantly. This was intended to works with IIS.
#Remove Import if not found and not using IIS
Import-Module WebAdministration
Add-Type -TypeDefinition @"
[System.Flags]
public enum DashboardAction
{
Undefined = 0,
function New-TempPassword($letters = 6,$digits=2, [Switch]$Capital) {
[Char[]]$Vowels = 'aeiouy'
[char[]]$Consonants = 'bcdfghjklmnpqrstvwxz'
$output = New-Object System.Text.StringBuilder
for ($i=0;$i -lt $letters;$i++) {
Switch ($i % 2 -eq 0) {
@itfranck
itfranck / Get-AllSubsAzureVms
Created August 24, 2018 15:50
Get All resources /Vms accross multiple azure subscription
$Subscriptions = Get-AzureRmSubscription
$rsx = $Subscriptions | % {
$SubName = $_.Name
Select-AzureRmSubscription $_.Id | Out-Null
Get-AzureRmResource |
Select *,@{n='SubscriptionName';e={$SubName}}
}
$rsx[0] | fl
$Vms = $rsx | where ResourceType -Like '*virtualMachines' | Select *,@{n='Classic';e={$_.ResourceType.Contains('Classic')}}
$Vms | ft Name,ResourceType,Classic,SubscriptionName