Input Box Pop-up
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null $Value = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a value", "Title", $null)
Get the AD Groups for a User with 1 Level of Inheritance
# Get the direct group memberships $UserGroups = Get-ADPrincipalGroupMembership $UserName | Select distinguishedName, GroupCategory, GroupScope, name, objectClass, objectGUID, SamAccountName, SID, @{l='Membership';e={'Direct'}}, @{l='Parent';e={$null}} # Get the group membership 1 level down foreach($group in $UserGroups){ $UserGroups += Get-ADPrincipalGroupMembership -Identity $group.distinguishedName | Select distinguishedName, GroupCategory, GroupScope, name, objectClass, objectGUID, SamAccountName, SID, @{l='Membership';e={'Inherit'}}, @{l='Parent';e={$group.distinguishedName}} } # Display results $UserGroups | FT name, GroupCategory, GroupScope,...
Get External IP Address
Invoke-RestMethod 'https://api.ipify.org?format=json' | Select-Object -ExpandProperty IP
Zip All Files in Folder
# Get the files to zip $FilesToZip = Get-ChildItem -Path $FolderPath -File # Load the assembly to get the zip functionality [Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" ) | Out-Null # Set compression level $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal # Set Zip file pathc based on folder $ZipPath = Join-Path $FolderPath "$(Split-Path $FolderPath -Leaf).zip" # initialize the zip file $Archive = [System.IO.Compression.ZipFile]::Open( $ZipPath, "Update" ) #...
Yes/No Prompt
$yes = new-Object System.Management.Automation.Host.ChoiceDescription "&Yes","help" $no = new-Object System.Management.Automation.Host.ChoiceDescription "&No","help" $choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no) $answer = $host.ui.PromptForChoice("Prompt","Click yes to continue",$choices,0) if($answer -eq 0){ Write-Host "You clicked Yes" }elseif($answer -eq 1){ Write-Host "You clicked No" }
Generate Random Names
Function Get-RandomNames{ [CmdletBinding()] [OutputType([Object])] param( [Parameter(Mandatory=$false)] [int] $count=10 ) $Webfemale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-female-first.txt" $Webmale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-male-first.txt" $WebSurname = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-surnames.txt" $female = @() $female = $Webfemale.Content.Split("`n").Trim() | ?{$_.length -gt 2} $male = @() $male = $Webmale.Content.Split("`n").Trim() | ?{$_.length -gt 2} $Surname = @() $Surname = $WebSurname.Content.Split("`n").Trim() | ?{$_.length -gt 2} $names = @() for($i=0; $i -ne $count; $i++) {...
Find Guid in String
$guidPattern = "(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}" [Regex]::Matches($string, $guidPattern).Value