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
$Timer = [System.Diagnostics.Stopwatch]::StartNew() | |
$maxThreads = 20 | |
$RunSpacePool = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspacePool(1, $maxThreads ) | |
$Jobs = New-Object System.Collections.ArrayList | |
$RunSpacePool.Open() | |
$Worker = { | |
param($Item) |
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
AudioDeviceCmdlets | |
AutomatedLab | |
AutomatedLab.Common | |
AutomatedLabDefinition | |
AutomatedLabNotifications | |
AutomatedLabUnattended | |
AutomatedLabWorker | |
Az.Accounts | |
Az.Aks | |
Az.AnalysisServices |
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
# method 1 | |
$a = 1..5 | |
[array]::Reverse($a) | |
$a | |
# method 2 | |
$a = 1..5 | |
$a[$a.count..0] |
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
# Method 1 - Using Expand-Archive cmdlet | |
Expand-Archive -Path C:\Data\Compressed.zip -DestinationPath C:\Data\one -Verbose | |
# Method 2 - Using .Net ZipFile Class | |
Add-Type -Assembly "System.IO.Compression.Filesystem" | |
[System.IO.Compression.ZipFile]::ExtractToDirectory('C:\Data\Compressed.zip','C:\Data\two') | |
# Method 3 - Using Shell.Application COM object | |
$ZippedFilePath = "C:\Data\Compressed.zip" | |
$DestinationFolder = "C:\Data\three\" |
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
Function Malicious { | |
#Get current user context | |
$CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) | |
#Check user is running the script is member of Administrator Group | |
if($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) | |
{ | |
Write-host "Script is running with Administrator privileges!" | |
} | |
else |
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
# Method 1 - Using PSTypeNames | |
$Alpha = [PSCustomObject]@{a=1; b=2} | |
$Alpha.pstypenames.Clear() | |
$Alpha.pstypenames.Add('Alpha') | |
$Alpha | Get-Member | |
# Method 2 - Using PSObject Adapter | |
$Beta = Get-Service BITS | |
$Beta.PSObject.TypeNames.Insert(0,'Beta') | |
$Beta | Get-Member |
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
$URLs = "https://aka.ms/wsl-ubuntu-1804" ,"https://aka.ms/wsl-ubuntu-1804-arm" ,"https://aka.ms/wsl-ubuntu-1604" ,"https://aka.ms/wsl-debian-gnulinux" ,"https://aka.ms/wsl-kali-linux" ,"https://aka.ms/wsl-opensuse-42" ,"https://aka.ms/wsl-sles-12" | |
$ProgressPreference = 'SilentlyContinue' | |
$ErrorActionPreference = 'Stop' | |
Foreach($URL in $URLs){ | |
$Filename = "$(Split-Path $URL -Leaf).appx" | |
Write-Host "Downloading: $Filename" -Foreground Yellow -NoNewline | |
try{ | |
Invoke-WebRequest -Uri $URL -OutFile $Filename -UseBasicParsing | |
Add-AppxPackage -Path $Filename |
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
$URL = 'https://aka.ms/wsl-ubuntu-1804' | |
$Filename = "$(Split-Path $URL -Leaf).appx" | |
$ProgressPreference = 'SilentlyContinue' | |
Invoke-WebRequest -Uri $URL -OutFile $Filename -UseBasicParsing | |
Invoke-Item $FileName |
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
$Error.count # empty automatic variable | |
# throwing an error when file doesn't exists | |
Get-Item C:\Data\nosuchfile.txt | |
$Error.count # one error record logged | |
# supressing the error | |
Get-Item C:\Data\nosuchfile.txt -ErrorAction SilentlyContinue | |
$Error.count # but still capturing the error |
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
Function Get-FolderSize { | |
param( | |
$Path = (Get-Location), | |
$Top = 10, | |
[Switch] $ShowErrors | |
) | |
$Start = Get-Date | |
$FSO = New-Object -ComObject Scripting.FileSystemObject -ErrorAction Stop | |
$Folders = Get-ChildItem $Path -Recurse -ea Silentlycontinue -ErrorVariable +err | Where-Object { $_.PSIscontainer } | Select-Object -ExpandProperty fullname |