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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>net7.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="System.Management.Automation" Version="7.3.2" PrivateAssets="all" /> |
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
#requires -version 7 -module Microsoft.Graph.Applications | |
using namespace Microsoft.Graph.PowerShell.Models | |
using namespace System.Collections.Generic | |
enum MicrosoftGraphServicePrincipalType { | |
Application | |
Delegated | |
} | |
class MgServicePrincipalPermission { |
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
using namespace Microsoft.Azure.Commands.PrivateDns.Models | |
filter Sync-AzPrivateDnsZone { | |
[CmdletBinding(SupportsShouldProcess = $true)] | |
param( | |
#The zone to copy A records from | |
[Parameter(Mandatory)][PSPrivateDNSZone]$SyncFrom, | |
#The zone to copy A records into | |
[Parameter(Mandatory, ValueFromPipeline)][PSPrivateDNSZone]$SyncTo, | |
#How fast to create records | |
[int]$ThrottleLimit = 10 |
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
filter ThrowStdOutErrors($messageFilter,[Parameter(ValueFromPipeline)]$obj) { | |
if ($obj -is [Management.Automation.ErrorRecord]) { | |
if ($obj -match $messageFilter) { | |
throw $obj | |
} else { | |
Write-Error $obj | |
return | |
} | |
} | |
$obj |
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
$items = 0..26 | ForEach-Object -ThrottleLimit 30 -Parallel { | |
$return = Invoke-RestMethod -Verbose "https://www.powershellgallery.com/api/v2/Packages()?`$filter=IsLatestVersion eq true and Dependencies%20gt%20%27a%27&`$select=Dependencies,Version,NormalizedVersion&`$orderby=Created%20desc&`$top=50000&`$skip=$($PSItem*100)" | |
$return | ForEach-Object { | |
[PSCustomObject]@{ | |
Name = $_.title.'#text' | |
Dependency = $_.Properties.Dependencies | |
Version = $_.Properties.Version | |
NormalizedVersion = $_.Properties.NormalizedVersion | |
} | |
} |
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
using namespace Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription | |
using namespace Microsoft.Azure.Management.Internal.Resources.Utilities.Models | |
param( | |
$Subscriptions = $(Get-AzSubscription) | |
) | |
$Subscriptions | |
| Where-Object State -ne 'Disabled' | |
| ForEach-Object { | |
$context = Select-AzSubscription -SubscriptionID $PSItem.Id |
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
#require -version 5.1 | |
#Usage: iwr https://tinyurl.com/VSCodeServer | iex | |
#Parameterized usage: & ([ScriptBlock]::Create((iwr https://tinyurl.com/VSCodeServer))) -Your -Options | |
param( | |
#Path to install the vscode binary to. This defaults to a folder in your Local AppData path. Must be writable by your current user without sudo | |
[ValidateNotNullOrEmpty()] | |
[string]$InstallPath = $(Join-Path -Path ([System.Environment]::GetFolderPath('LocalApplicationData')) -ChildPath 'vscode-cli'), | |
#Installation architecture. This is normally autodetected. | |
$Arch, | |
$OS, |
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
#Filter is just a function with the process{} | |
#block as the default rather than end{}. That's it, it's not scary. | |
# $y = 1..3 | |
# foreach ($x in $y) { | |
# "This is item $x" | |
# } | |
# #Result: | |
# #This is item 1 |
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
using namespace System.Management.Automation.Language | |
using namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic | |
function IncorrectUseOfFormatCmdletsInMiddleOfPipeline { | |
<# | |
.SYNOPSIS | |
Do not place format-table in the middle of a pipeline | |
.DESCRIPTION | |
Detects when Format commands are commonly misused in the middle of a pipeline, causing unexpected results with display objects that dont have the same properties as the original piped object. |
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 | |
Install PowerShell on Windows, Linux or macOS. | |
#> | |
[CmdletBinding(SupportsShouldProcess)] | |
param( | |
#Where PowerShell should be installed. | |
[string]$Destination, | |
#The version to install. Default is the latest stable version. Additional Options are a LTS, Preview, Daily, or a specific version number tag. | |
[ValidateNotNullOrEmpty][string]$Version = 'Stable' |