This file contains 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
( | |
resourcecontainers | |
| where type =~ 'microsoft.resources/subscriptions' | |
| project SubscriptionName=name, subscriptionId | |
) | join kind = inner | |
( | |
resources | |
| where type =~ 'microsoft.network/applicationgateways' | |
| project subscriptionId, AppGateway=name, httpListeners = properties['httpListeners'] | |
) on subscriptionId |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> | |
<title>Google Demo</title> | |
<style type="text/css" media="screen"> | |
.rainbow-text { | |
background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet); | |
-webkit-background-clip: text; | |
-webkit-text-fill-color: transparent; |
This file contains 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
function Get-HttpUrlRedirects { | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Mandatory)] | |
[ValidateNotNullOrEmpty()] | |
[string]$Url | |
, | |
[Parameter()] | |
[AllowNull()] | |
[AllowEmptyString()] |
This file contains 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
# Thanks to [Reddit](https://www.reddit.com/r/excel/comments/70r89w/need_to_delete_thousands_of_errored_named_ranges/i4huccg) | |
# for the tip on resolving the name manager issue | |
# once you've extracted your XLSX file as a zip, find the `workbook.xml` file (should be under the `xl` subfolder) | |
$wbPath = 'C:\Temp\MyExtractedXlsx\xl\workbook.xml' | |
# open this XML file / parse it as XML | |
$wb = [xml](Get-Content -Path $wbPath -encoding UTF8 -Raw) | |
# find all `definedName` elements which contain the string `#REF!`. |
This file contains 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
function Convert-PemToX509Cert { | |
Param ( | |
[Parameter(Mandatory)] | |
[string]$Path | |
, | |
[Parameter()] | |
[System.Text.Encoding]$Encoding = [System.Text.Encoding]::UTF8 | |
) | |
$options = [System.Text.RegularExpressions.RegexOptions]::CultureInvariant -bor [System.Text.RegularExpressions.RegexOptions]::Singleline | |
$regex = [System.Text.RegularExpressions.RegEx]::new('\-{5}BEGIN CERTIFICATE\-{5}(?<CERT>.*?)\-{5}END CERTIFICATE\-{5}', $options) |
This file contains 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
<# | |
This example shows how you can collect information on exceptions which occur in a loop, | |
whilst still processing other items in that loop, and bubbling up the exceptions which | |
were thrown during the loop | |
#> | |
# Dummy methods for illustration | |
function Do-Something{'Did Something'} | |
function Do-SomethingToTheThing([int]$thing) { | |
if ($thing % 7 -eq 0) { |
This file contains 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
# :: Prune dangling (untagged) images | |
docker image prune | |
# :: Stop Docker Desktop | |
Stop-Service 'com.docker.service' | |
# :: Stop the WSL service to ensure that doesn't lock the file | |
wsl --shutdown |
This file contains 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
# See also https://gist.github.com/JohnLBevan/a6c819ba5d825f29d465fb0433b54082 -- useful for fetching a range of IPs to be scanned | |
Function Get-TlsCertificate { | |
# Note: This uses PS7's parallel foreach feature; so requires PS7. If we wanted to write a version compatible with older versions we could use workflows (e.g. https://codereview.stackexchange.com/questions/97726/powershell-to-quickly-ping-a-number-of-machines) or add custom job/runspace logic (though that's much less tidy) | |
[CmdletBinding(DefaultParameterSetName = 'ByComputerAndPort')] | |
Param ( | |
[Parameter(ParameterSetName = 'ByComputerAndPort', Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] | |
[string[]]$ComputerName | |
, | |
[Parameter(ParameterSetName = 'ByComputerAndPort', ValueFromPipelineByPropertyName)] |
This file contains 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
<# | |
.SYNOPSIS | |
Converts a CIDR notation IP Range to an array of those IPs, or an object containing the first and last values in the range. | |
All representations of IPs are returned as type: [System.Net.IPAddress] | |
.DESCRIPTION | |
Converts a CIDR notation IP Range to an array of those IPs, or an object containing the first and last values in the range. | |
All representations of IPs are returned as type: [System.Net.IPAddress] | |
.PARAMETER IpRangeCidr |
This file contains 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
' Simple Example Usage: `=RegexReplace(S181,"(\d+)\.(\d+)\.(\d+)", "$3-$2-$1 00:00:00")` - dd.mm.yyyy formatted date replaced with yyyy-MM-dd HH:mm:ss | |
' Ensure you add a reference to `Microsoft VBScript Regular Expressions 5.5` (or later) | |
' Thanks to AutomateThis for their answer pointing me to this library: https://stackoverflow.com/a/22542835/361842 | |
Option Explicit | |
Option Base 0 | |
Public Function RegexReplace(sourceString As String, matchPattern As String, replaceVar As String, Optional globalRegex As Boolean = True, Optional multiLine As Boolean = True, Optional ignoreCase As Boolean = True) As String | |
' Could improve by adding validation (e.g. is the matchPattern blank), but for now just doing a quick and dirty | |
Dim regEx As New RegExp |