🕵️♂️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OFS - special variable that contains the string to be used as the output field seperator | |
$OFS = '...';$array = ('first','last');[string]$array; Remove-Variable OFS | |
$array = ('first','last');[string]$array; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wrap Measure-Command in & { } for increased measuring performance | |
Measure-Command { & { | |
$var = foreach ($i in 0..50000){ | |
$i | |
} | |
}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git update-index --add --chmod=+x install_terraform.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$a = @( | |
'AWS.Tools.Common' | |
'AWS.Tools.CloudFormation' | |
'AWS.Tools.CloudFormation' | |
'AWS.Tools.CloudWatch' | |
'AWS.Tools.CostExplorer' | |
'AWS.Tools.EC2' | |
'AWS.Tools.Installer' | |
'AWS.Tools.S3' | |
'AWS.Tools.SecretsManager' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ChildItem -Filter *.ps1 | ForEach-Object { | |
$ast = [System.Management.Automation.Language.Parser]::ParseFile($_.FullName, [ref]$null, [ref]$null) | |
$ast.FindAll({ param($sa) $sa -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $false) | ForEach-Object { | |
# Define functions | |
New-Item -Path Function:\ -Name $_.Name -Value $_.Body.GetScriptBlock() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The default branch has been renamed! | |
master is now named main | |
If you have a local clone, you can update it by running the following commands. | |
git branch -m master main | |
git fetch origin | |
git branch -u origin/main main | |
git remote set-head origin -a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires –Modules PoshGram | |
#https://support.plex.tv/articles/201539237-backing-up-plex-media-server-data/ | |
#https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/ | |
# if you don't want to send yourself telegram messages the telegram portion can be removed | |
Import-Module -Name PoshGram | |
$token = '111111111:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
$chat_id = '-111111111' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It 'should run the expected commands if an error is encountered' { | |
Mock -CommandName Invoke-RestMethod { | |
throw 'Fake Error' | |
} #endMock | |
Mock -CommandName Write-Warning { } | |
Mock -CommandName Write-Error { } | |
$sendTelegramContactSplat = @{ | |
BotToken = $token | |
ChatID = $chat | |
PhoneNumber = $phone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#----------------------------------------------------------------------------- | |
Mock Invoke-RestMethod { | |
[System.Exception]$exception = "The remote server returned an error: (400) Bad Request." | |
[System.String]$errorId = 'BadRequest' | |
[Management.Automation.ErrorCategory]$errorCategory = [Management.Automation.ErrorCategory]::InvalidOperation | |
[System.Object]$target = 'Whatevs' | |
$errorRecord = New-Object Management.Automation.ErrorRecord ($exception, $errorID, $errorCategory, $target) | |
[System.Management.Automation.ErrorDetails]$errorDetails = '{"message":"Username does not exist: [user]"}' | |
$errorRecord.ErrorDetails = $errorDetails | |
throw $errorRecord |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$script:mockCalled = 0 | |
$mockInvoke = { | |
$script:mockCalled++ | |
if ($script:mockCalled -eq 1) { | |
return $false | |
} | |
elseif ($script:mockCalled -eq 2) { | |
return $true | |
} | |
} |