full_path stringlengths 31 232 | filename stringlengths 4 167 | content stringlengths 0 48.3M |
|---|---|---|
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Control_GUI_App.ps1 | Control_GUI_App.ps1 | ##############################################################################
# Script: Control_GUI_App.ps1
# Date: 2.Jun.2012
# Version: 2.1
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Demos use of SendKeys(), Start-Sleep, and AppActivate().
# Legal: Script provided "AS IS" with... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/NTFS-Alternate-Data-Streams.ps1 | NTFS-Alternate-Data-Streams.ps1 | #############################################################################
# NTFS alternate data streams are used with the RemoteSigned PowerShell
# execution policy, Dynamic Access Control file classification, MS Office
# security policies, and other applications. The following commands
# demonstrate how to i... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Use_RunDLL32.ps1 | Use_RunDLL32.ps1 | ##############################################################################
# Script Name: Use_RunDLL32.ps1
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Updated: 18.May.2007
# Purpose: Will lock the desktop on Windows 2000 and later.
# Notes: This script al... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Compress-NtfsFile.ps1 | Compress-NtfsFile.ps1 | # Function to enable NTFS compression on a file.
# Returns $true if file gets (or already is) compressed; $false otherwise.
Param ( $FilePath )
function Compress-NtfsFile ( $FilePath )
{
# Get full path to file as a string:
[String] $FilePath = @(dir $FilePath)[0].FullName
# Return $true if t... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Get-Loaded-Classes.ps1 | Get-Loaded-Classes.ps1 | ##############################################################################
# Script: Get-Loaded-Classes.ps1
# Date: 16.May.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: To see a list of all the classes from all the assemblies
# currently loaded into P... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Process-Reaper.ps1 | Process-Reaper.ps1 | # In a GPO, make sure to use the PowerShell Scripts tab!
# Don't add this to the default Scripts tab on the left!
#
# This is just an example of what could be done with a
# startup script or script pushed out as an immediate
# task. A real script would more carefully define the
# processes to terminate, includi... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Get-Loaded-Assemblies.ps1 | Get-Loaded-Assemblies.ps1 | ##############################################################################
# Script: Get-Loaded-Assemblies.ps1
# Date: 16.May.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: To see a list of the assemblies currently loaded into PowerShell.
# Legal: Script provi... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Remove-UndeletableFolder.ps1 | Remove-UndeletableFolder.ps1 | ####################################################################
# Purpose: Tries hard to delete stubborn folders and files.
#
# By design, you may need to use the function two or three times to
# finally succeed in deletion, but it can still fail, so the script
# is relatively verbose so that you can see whe... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Extract-Text.ps1 | Extract-Text.ps1 | #############################################################################
# Select-string will return the entire line which matches a regex pattern,
# but this filter will extract just the matching text of the pattern.
# Pipe strings or file objects into the filter, and don't forget that you
# may sometimes nee... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Command-Line_Arguments.ps1 | Command-Line_Arguments.ps1 | ##############################################################################
# Script: Command-Line_Arguments.ps1
# Date: 27.Mar.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Demo how command line arguments are processed.
# Legal: Script provided "AS IS" withou... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Read-Excel.ps1 | Read-Excel.ps1 | ##############################################################################
# Script: Read-Excel.ps1
# Date: 2.Jul.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Reads one or more cells out of an Excel spreadsheet.
# Legal: Script provided "AS IS" without warra... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/New-HyperV-VirtualMachine-Example.ps1 | New-HyperV-VirtualMachine-Example.ps1 | ############################################################################
# Purpose: This script demonstrates how to create a Hyper-V virtual machine.
# Version: 1.0
# Date: 2.Aug.2013
# Author: Jason Fossen (http://www.sans.org/windows-security)
# Legal: Public domain, provided "AS IS" without any warran... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Get-MaxPathFiles.ps1 | Get-MaxPathFiles.ps1 | <#
.SYNOPSIS
Discovers or deletes files with 260+ character paths.
.DESCRIPTION
The MAX_PATH limit prevents most Windows tools from manipulating or
deleting files whose full path name is 260 characters or longer.
This script can discover and list files of any chosen path length
and optio... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Microsoft-Azure-AD.ps1 | Microsoft-Azure-AD.ps1 | ##############################################################################
#
# This script demonstrates how to interact with Microsoft Azure Active
# Directory via PowerShell. You will need an Azure AD account first, which
# is free: http://azure.microsoft.com/en-us/services/active-directory/
#
#
# Scrip... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Write-ApplicationLog.ps1 | Write-ApplicationLog.ps1 | ##############################################################################
# Script: Write-ApplicationLog.ps1
# Date: 21.May.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Write to the Application event log with a COM object.
# Legal: Script provided "AS IS" w... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Write-Something.ps1 | Write-Something.ps1 | ################################################################
# There are a variety of Write-* cmdlets, but which one
# should be used and how are they different?
################################################################
# To list the commands with the Write-* verb:
Get-Command -Verb Write
#... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Debugging-Part1.ps1 | Debugging-Part1.ps1 | # To debug a PowerShell script, you must set at least one breakpoint.
# There are three types of breakpoints: line, variable, and command.
# Only line breakpoints can be created by the ISE's menu options, but
# all breakpoint types can be created from the command line. Note
# that breakpoints are memory-resident only,... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Classes_Examples.ps1 | Classes_Examples.ps1 | # Creating custom classes requires PowerShell 5.0 or later.
# PowerShell 5.0 is built into Windows 10 and Server 2016.
#Requires -Version 5
# Define a simple class to represent a user:
Class User1
{
$FirstName
$LastName
$EmailAddress
}
# Create an instance of the User class:
$bob = ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Reboot-Shutdown-Sleep-Hibernate.ps1 | Reboot-Shutdown-Sleep-Hibernate.ps1 | # Shutdown a local/remote computer:
Stop-Computer
Stop-Computer -ComputerName Server47
# Reboot the local computer:
Restart-Computer
# Reboot a remote computer and wait up to 10 minutes until
# PowerShell remoting is available again (requires PoSh 3+):
Restart-Computer -Wait -For PowerShell -Timeout (60... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Runspace-Pool-Examples.ps1 | Runspace-Pool-Examples.ps1 | <#
PowerShell commands can be run concurrently using background processes, workflows, runspaces,
and, with a lot of effort, the .NET Task Parallel Library (TPL) or .NET threads directly.
This script demonstrates how to use multiple, concurrent runspaces to execute commands
which all share a single thread-safe d... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/New-7zipArchive.ps1 | New-7zipArchive.ps1 | ####################################################################################
#.Synopsis
# Crude wrapper for 7-Zip to make a password-encrypted archive.
#
#.Description
# First uses RoboCopy.exe to make a copy of the folders and files to be
# added to a 7-Zip (www.7-zip.org) archive encrypted with... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Parse-Nmap.ps1 | Parse-Nmap.ps1 | ####################################################################################
#.Synopsis
# Parse XML output files of the nmap port scanner (www.nmap.org).
#
#.Description
# Parse XML output files of the nmap port scanner (www.nmap.org) and
# emit custom objects with properties containing the ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/LibraryScript.ps1 | LibraryScript.ps1 | # These are just examples to show how "dot sourcing"
# a script copies the functions from that script
# into the function:\ drive in PowerShell.
#
# . .\LibraryScript.ps1
#
function hh ( $term ) { get-help $term -ShowWindow }
function Ping-Host ( [string] $HostName )
{
$p = new-object System.... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Remove-UnReadMessagesFromDeletedItemsInOutlook.ps1 | Remove-UnReadMessagesFromDeletedItemsInOutlook.ps1 | ###############################################################################
#
# Purpose: Delete unread messages in the Deleted Items folder in Outlook, but
# the script also demos some of the pains involved in COM interop.
#
#############################################################################... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Send-EMail.ps1 | Send-EMail.ps1 | ##############################################################################
# Script: Send-EMail.ps1
# Date: 7.Sept.2007
# Version: 1.3
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Send e-mail using SMTP or SMTPS.
# Notes: If multiple addresses to the addressing fields, separate... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Display-InInternetExplorer.ps1 | Display-InInternetExplorer.ps1 | ########################################################################
# Script Name: Display-InInternetExplorer.ps1
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Updated: 20.Jun.2007
# Purpose: Demonstrates how to use Internet Explorer to display
# HT... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Append-XmlElement.ps1 | Append-XmlElement.ps1 | ##############################################################################
# Script: Append-XmlElement.ps1
# Date: 4.Jun.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Demo some XML manipulation.
# Legal: Script provided "AS IS" without warranties or guarantee... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Switch-Log-Processing.ps1 | Switch-Log-Processing.ps1 | ##############################################################################
# Script: Switch-Log-Processing.ps1
# Date: 21.May.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Just demos the Switch statement for file processing...
# Legal: Script provided "AS IS"... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/New-RandomPassword.ps1 | New-RandomPassword.ps1 | ##############################################################################
#.Synopsis
# Generates a complex password of the specified length and text encoding.
#
#.Description
# Generates a random password using only common ASCII code numbers. The
# password will be four characters in length at a... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Math.NET.Numerics-Examples.ps1 | Math.NET.Numerics-Examples.ps1 | <#
.SYNOPSIS
PowerShell can utilize the math libraries of Math.NET Numerics and the processor-optimized Intel Math Kernel Library (MKL). To help coders get started, this article has a bunch of PowerShell examples of using Math.NET with Intel's MKL. You might be pleasantly surprised at how easy it is to use.
Bec... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Out-OneNote.ps1 | Out-OneNote.ps1 | ####################################################################################
#.Synopsis
# Objects piped into script are sent to the locally-installed Microsoft OneNote.
#
#.Description
# When Microsoft OneNote is installed, normally a virtual printer is created so
# that anything "printed" to ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/IP-Computer-Enumeration.ps1 | IP-Computer-Enumeration.ps1 | ####################################################################################
# Very often, you will want to enumerate through all the computers in a domain, or
# through all the computers in an organizational unit, or through all the IPv4
# addresses in a range, such as for remote command execution, ping sw... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/HyperV-Create-VM-Example.ps1 | HyperV-Create-VM-Example.ps1 | ############################################################################
# Purpose: This script demonstrates how to create a Hyper-V virtual machine.
# Version: 1.0
# Date: 2.Aug.2013
# Author: Jason Fossen (http://www.sans.org/windows-security)
# Legal: Public domain, provided "AS IS" without any warran... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Misc/Dell-QuestSoftware/Get-UsersWithOldPasswords.ps1 | Get-UsersWithOldPasswords.ps1 | ##############################################################################
# Script: Get-UsersWithOldPasswords.ps1
# Date: 6.Jun.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Gets AD user accounts which have not had their passwords changed
# or reset i... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Misc/Dell-QuestSoftware/Create-GlobalUser.ps1 | Create-GlobalUser.ps1 | ##############################################################################
# Script: Create-GlobalUser.ps1
# Date: 10.Sep.2007
# Version: 1.1
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Create user accounts in AD using the .NET classes directly.
# Legal: Script provided "AS IS... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Misc/Dell-QuestSoftware/Quest_AD.ps1 | Quest_AD.ps1 | ###############################################################################
# NOTE: None of these commands will work unless you have already installed
# the ActiveRoles AD snap-in from Quest:
# http://www.quest.com/activeroles-server/arms.aspx
########################################################... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Misc/Dell-QuestSoftware/Get-DistinguishedName.ps1 | Get-DistinguishedName.ps1 | ##############################################################################
# Script: Get-DistinguishedName.ps1
# Date: 10.Jun.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Extract the fully qualified distinguished name (DN) for an object
# in Active Di... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Misc/Dell-QuestSoftware/Update-ComputerDescription.ps1 | Update-ComputerDescription.ps1 | ##############################################################################
# Script: Update-ComputerDescription.ps1
# Date: 9.Sep.07
# Version: 1.1
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Adds the OS version and Service Pack number to the description
# field on all... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Remoting/HowTo-Install-PowerShell-Web-Access.ps1 | HowTo-Install-PowerShell-Web-Access.ps1 | ##############################################################################
#
# Demonstrates the minimal steps to install and use the PowerShell Web Access
# (PSWA) feature. Please see Microsoft's web site for further options, such
# as customizing sessions, authorization rules and SSL for security.
#
# PSW... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Remoting/Remoting_File_Copy.ps1 | Remoting_File_Copy.ps1 | # PowerShell 5.0 and later supports the copying of files through
# the remoting channel itself, which means no additional ports
# must be opened between source and destination machines other
# than the already-open remoting port(s).
# Create a session to a remote host with PoSh 5.0+:
$session = New-PSSession... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Remoting/Configure-RemotingForSSL.ps1 | Configure-RemotingForSSL.ps1 | ####################################################################################
#.Synopsis
# Configures the SSL/TLS settings for PowerShell remoting.
#
#.Description
# The script will walk the user through the steps necessary to choose a
# machine certificate and configure WSMan settings necessary ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Remoting/Remoting_Examples.ps1 | Remoting_Examples.ps1 | # To enable PowerShell remoting on the local machine:
Enable-PSRemoting -Force
# To connect to a local/remote computer by name:
Enter-PSSession -ComputerName LocalHost
# To exit a PowerShell remoting session:
Exit-PSSession # Or just "exit" by itself.
# To execute a set of commands on remo... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Databases/Query-AccessDB.ps1 | Query-AccessDB.ps1 | ##############################################################################
# Script: Query-AccessDB.ps1
# Date: 3.Jun.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Perform a SELECT query against an Access database and return data
# as an array of comma... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Databases/Update-AccessDB.ps1 | Update-AccessDB.ps1 | ##############################################################################
# Script: Update-AccessDB.ps1
# Date: 19.Jul.2007
# Version: 1.0
# Author: Jason Fossen (www.WindowsPowerShellTraining.com)
# Purpose: Perform a INSERT, UPDATE or DELETE command against an Access
# database. For SELECT,... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/Encoding-CodePage-Unicode.ps1 | Encoding-CodePage-Unicode.ps1 | <# ###########################################################################
*Glyphs and Unicode*
A glyph is a visual symbol seen by a human on a page of paper or screen. We
often call these "characters", but the term "character" is ambiguous: Is it
what you see? The name of what you see? The binary repres... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/Named-Pipe-Client.ps1 | Named-Pipe-Client.ps1 | #################################################################################################
# This script demos the use of named pipes. Run named-pipe-server.ps1 first, then this one.
# Requires .NET Framework 3.5 SP1 or later.
# For more information, see:
# http://msdn.microsoft.com/en-us/library/system.i... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/Base64-Conversion.ps1 | Base64-Conversion.ps1 | #####################################################################################################
# A couple of functions for coverting to/from Base64 and US-ASCII, as defined in RFC4648.
# Both functions can accept piped input.
# Legal: Public Domain, No Warranties or Guarantees of Any Kind, USE AT YOUR OWN ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/Manipulate-Binary.ps1 | Manipulate-Binary.ps1 | ##############################################################################
# Script: Manipulate-Binary.ps1
# Purpose: A variety of functions for manipulating hex and binary files.
# Date: 29.Nov.2012
# Version: 3.0
# Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505)
# Notes: Req... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/Named-Pipe-Server.ps1 | Named-Pipe-Server.ps1 | #################################################################################################
# This script demos the use of named pipes. Run this script first, then named-pipe-client.ps1.
# Requires .NET Framework 3.5 SP1 or later.
# For more information, see:
# http://msdn.microsoft.com/en-us/library/syste... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/ListenOnTcpPortOnce.ps1 | ListenOnTcpPortOnce.ps1 | ################################################################################################
# Purpose: This function demonstrates how to listen on a TCP port.
# Output: Outputs an array of raw bytes, which can be saved to a file using the
# "set-content -encoding byte" command, or, if you use the -To... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/PushToUdpPort.ps1 | PushToUdpPort.ps1 |
function PushToUdpPort {
################################################################
#.Synopsis
# Send byte array over UDP to IP address and port number.
#.Parameter ByteArray
# Array of [Byte] objects for the UDP payload.
#.Parameter IP
# IP address or FQDN of the destination host.
#.Parameter Port
... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/SMB2-DoS-Attack.ps1 | SMB2-DoS-Attack.ps1 | #####################################################################################
# Script demonstrates how to send raw byte data to a TCP listening port,
# in this case a DoS attack against SMBv2 on TCP/445. For more info, see:
# http://g-laurent.blogspot.com/2009/09/windows-vista7-smb20-negotiate-protocol.htm... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/BinaryData/Get-FileHex.ps1 | Get-FileHex.ps1 | ##############################################################################
#.Synopsis
# Display the hex dump of a file.
#
#.Parameter Path
# Path to file as a string or as a System.IO.FileInfo object;
# object can be piped into the function, string cannot.
#
#.Parameter Width
# Number of hex by... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Named_Parameters.ps1 | Named_Parameters.ps1 | # This creates the function, but does not run it!
function list-parameters ($User, $Password)
{
$User.ToUpper()
$Password.ToLower()
}
# You have to call or execute a function for it to run!
list-parameters Jill Sekrit
list-parameters -user Jill Sekrit
list-parameters -user Jill -password... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Where_Object.ps1 | Where_Object.ps1 |
get-service | where-object {$_.status -ne "running"}
get-service | where {$_.status -ne "running"}
get-service | ? {$_.status -ne "running"}
# To show the full paths to every file under C:\Windows\System32 over 10MB in size:
get-childitem c:\windows\system32 -recurse |
where-object {$_.length -gt 10000000} ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Edit-Profile.ps1 | Edit-Profile.ps1 |
# Need to check if it already exists, don't want to overwrite it:
if (-not $(test-path $profile.CurrentUserAllHosts))
{
new-item -path $profile.CurrentUserAllHosts -itemtype file -force
}
PowerShell_ISE.exe $profile.CurrentUserAllHosts
|
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Quick-RegEx.ps1 | Quick-RegEx.ps1 |
$input = "bed rat pop beets soot rich"
$pattern = '.[a|e|o]+.'
$strings = @( [RegEx]::Matches($input,$pattern) | foreach-object { $_.value } )
$strings
|
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Parameter_Switch.ps1 | Parameter_Switch.ps1 |
function show-folder ([Switch] $list) {
if ($list) {dir | format-list *}
else {dir | format-table fullname,length -autosize}
}
# Call function with or without the switch parameter:
show-folder -list
show-folder -l
show-folder
function show-hkcu ([Switch] $list) {
If ($list) {get-childite... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Switch_FlowControl.ps1 | Switch_FlowControl.ps1 |
$x = 58
switch ( $x )
{
{$_ -lt 20} {"Really Small"}
{$_ -gt 50} {"Pretty Big"}
58 {"It's 58"}
default {"What was that?"}
}
switch -wildcard ("c:\data5\archive.zip")
{
'?:\data?\*' {"In some data folder."}
'*.zip' {"File is a ZIP."}
}
switch -regex ("c:\data5\archive.zip"... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Associative_Arrays.ps1 | Associative_Arrays.ps1 |
# To create an associative array where the two-letter U.S. state code is associated with the full name of the state (the two-letter code is the key, the full name is the value):
$states = @{ "CA" = "California" ;
"FL" = "Florida" ;
"VA" = "Virginia" ;
"MD" = "Ma... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Advanced-Function-Template.ps1 | Advanced-Function-Template.ps1 | #######################################################################
#
# This is a template for creating an advanced function (aka, "script
# cmdlet") in PowerShell 2.0 and later. See the following help:
#
# get-help about_Functions_Advanced
# get-help about_Functions_Advanced_Methods
# get-help abo... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Environment_Variables.ps1 | Environment_Variables.ps1 |
# Environment variables are in the ENV:\ drive:
dir env:\
# Use an environment variable (not case sensitive):
$env:Path
$env:windir
$env:USERNAME
# Another way to get environment variables:
[Environment]::GetEnvironmentVariables()
[Environment]::GetEnvironmentVariable("Path")
# Retrieve a compute... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Creating_COM_Objects.ps1 | Creating_COM_Objects.ps1 |
$voice = new-object -comobject "sapi.spvoice"
$voice | get-member
$voice.speak("I have a type library!")
notepad.exe
start-sleep -seconds 1
$WshShell = new-object -comobject "WScript.Shell"
$result = $WshShell.AppActivate("Untitled")
$WshShell.SendKeys("I'm sending keystrokes to notepad.exe!")
... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Select_Object.ps1 | Select_Object.ps1 |
get-process "powershell*" | select-object -property Path
get-process "powershell*" | select-object modules
get-process "powershell*" | select-object -expandproperty modules
# To only show unique event ID numbers from the Application event log:
get-eventlog Application | select-object EventID -unique
... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/If_FlowControl.ps1 | If_FlowControl.ps1 | $string = "SANS Institute GIAC"
If ($string -like "SANS*")
{
"It's true that it starts with SANS."
}
ElseIf ($string -match "[FGH]IAC")
{
"It matches the regular expression pattern."
}
Else
{
"We don't know what it is, so we're giving up."
}
$x = 32
If ($x -eq 32) { $x = $x +... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Format_Strings.ps1 | Format_Strings.ps1 | #####################################################
# The -f operator is for formatting strings, such as:
#
# Currency with dollar symbol, decimal and commas.
# Decimal numbers with a specified precision.
# Hexadecimal numbers with zeros for left padding.
# Dates and times.
#
#################... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Returning_Results.ps1 | Returning_Results.ps1 |
function times-ten ($number) {
$x = $number * 10
return $x
"You'll never get here because of the return."
}
times-ten 7
function times-eleven ($number) {
$number * 11
return
"You'll never get here because of the return."
}
times-eleven 8
function shout { [Void] "Hey!" ; "There!" }
shout
... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Get-UsersWithOldPasswords.ps1 | Get-UsersWithOldPasswords.ps1 | ##############################################################################
# Script: Get-UsersWithOldPasswords.ps1
# Date: 6.Jun.2007
# Version: 1.0
# Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505)
# Purpose: Gets AD user accounts which have not had their passwords changed
# ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Modules.ps1 | Modules.ps1 | # The path(s) where PowerShell will search for module folders:
$env:PsModulePath
$env:PsModulePath -Split ";" #To see them easier.
# Get the currently-loaded root modules:
Get-Module
# A nested module is loaded by another module.
# Get currently-loaded modules and their nested modules:
Get-Module -All
... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Multiple_Matches.ps1 | Multiple_Matches.ps1 |
$logdata = @'
2007-11-11 02:36:50 DROP TCP 202.18.44.101 192.168.0.1
2007-11-19 12:12:09 DROP UDP 202.19.44.101 192.168.0.1
2007-11-22 09:01:21 DROP TCP 202.20.44.101 192.168.0.1
2007-11-24 11:29:58 DROP TCP 202.21.44.101 192.168.0.1
2007-11-30 04:48:32 DROP UDP 202.22.44.101 192.168.0.1
'@
$regex = [RegEx] ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Positional_Args.ps1 | Positional_Args.ps1 |
function show-args { foreach ($x in $args) {$x} }
show-args cat dog fish
# If you know that you'll pass in three arguments, you can access them by index number.
function show-3args
{
$computer, $user, $password = $args[0,1,2]
"Count of arguments: " + $args.count
}
# Example of calling the fu... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Here-Strings.ps1 | Here-Strings.ps1 | $text1 = @'
All this text, across multiple lines,
will be treated by PowerShell as one big
literal string. $Any $variable-looking $text
$will $be $left $alone.
'@
@'
Multiple lines
of comment text
here.
'@ > $null
$text2 = @"
What's true is $true, and
my home is folder is $home,
since my us... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/SecureString-Theory.ps1 | SecureString-Theory.ps1 | ##############################################################################
# Script: SecureString-Theory.ps1
# Date: 24.Sep.2013
# Version: 2.0
# Purpose: Demonstrate how to work with secure string objects.
# Notes: Credit for deobfuscation function goes to MoW, The PowerShell Guy:
# http://the... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Formatters.ps1 | Formatters.ps1 |
get-item hklm:\software | format-list *
get-item hklm:\software | fl *
get-service | format-table Name,DisplayName,Status -autosize
get-service | format-list *
get-item hklm:\software\microsoft | fl name,subkeycount
get-childitem $env:windir\*.exe | format-table *
get-childitem $env:windir\*.exe | f... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Terminating_Errors.ps1 | Terminating_Errors.ps1 |
$ErrorActionPreference = "Continue"
dir c:\ ; nosuch-cmdlet ; dir c:\
$ErrorActionPreference = "Stop"
dir c:\ ; nosuch-cmdlet ; dir c:\
$ErrorActionPreference = "Continue"
# To experiment with the erroraction parameter and the non-existent service "444":
get-service 444 -erroraction Continue ; di... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Working_With_Items.ps1 | Working_With_Items.ps1 |
# Cmdlets for manipulating items in drives:
new-item $home\somefile.txt -type file
new-item $home\somefolder -type directory
new-item hkcu:\software\somekey -type key
new-item hkcu:\software\somekey\somevalue -type value
del hkcu:\software\somekey\somevalue
ren hkcu:\software\somekey otherkey
# Cmdlets for... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Create-GlobalUser.ps1 | Create-GlobalUser.ps1 | ##############################################################################
# Script: Create-GlobalUser.ps1
# Date: 11.Jun.2007
# Version: 1.0
# Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505)
# Purpose: Create user accounts in AD using the .NET classes directly.
# Legal: Scrip... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/HTML_Report.ps1 | HTML_Report.ps1 | get-process |
convertto-html -property Name,Path,ID `
-title "Process Report" `
-head "<h1>Process Report</h1>" `
-body "<h2>Report Was Run: $(get-date) </h2><hr>" |
out-file -filepath $env:temp\report.html
invoke-item $env:temp\report.html
|
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Translate.ps1 | Translate.ps1 |
##############################################################################
# Script: Translate.ps1
# Date: 18.Jul.2014
# Version: 2.0
# Author: Jason Fossen, Enclave Consulting LLC (www.sans.org)
# Purpose: Demos piping into functions and scripts.
# Legal: Script provided "AS IS" without warranties o... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Grouping.ps1 | Grouping.ps1 | (get-service spooler).status
(get-service spooler).stop()
(get-service spooler).start()
# To get today's date and time in a System.DateTime object, add three days to the current date, then show the result:
(get-date).AddDays(3)
# To get the count of processes using over 50MB of workingset memory:
(get-p... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/ForEach_FlowControl.ps1 | ForEach_FlowControl.ps1 | $services = get-service
ForEach ($x in $services)
{
$x.name + " : " + $x.status
}
ForEach ($x In @(dir c:\ | where {-not $_.psiscontainer})) {
$x.name + " : " + $x.length / 1024 + "KB"
}
# Implicit foreach using grouping.
# Requires PowerShell 3.0 or later.
(ps).path
... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/SecureString-Credentials.ps1 | SecureString-Credentials.ps1 |
$cred = get-credential # Dialog box appears...
get-wmiobject -query "SELECT * FROM Win32_BIOS" -computer server3 -credential $cred
# Show the so-called secure string password in plaintext:
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred.password)
[System.Runtime.InteropServ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Select_String.ps1 | Select_String.ps1 | select-string 'K5.*[efg]lex' $env:windir\inf\*.inf |
format-table path,line -autosize
|
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/CSV.ps1 | CSV.ps1 | get-service | export-csv -path services.csv
$objects = import-csv -path services.csv
$objects | where-object {$_.status -eq 'Running'} |
ft DisplayName
|
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/References.ps1 | References.ps1 | ######################################################################
# Array and hashtable variables are reference type variables, hence,
# the assignment of an array/hashtable to another variable simply
# creates another reference to that array/hashtable, not a separate
# copy of it.
######################... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/NET_Objects.ps1 | NET_Objects.ps1 | # To see a list of the assemblies currently loaded into PowerShell:
[System.AppDomain]::CurrentDomain.GetAssemblies() | format-list FullName,Location
# To see a list of all the classes from all the assemblies currently loaded into PowerShell:
[System.AppDomain]::CurrentDomain.GetAssemblies() |
foreach-obje... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Windows_Event_Logs.ps1 | Windows_Event_Logs.ps1 |
# To see a list of all local event logs:
get-winevent -listlog *
# To see a list logs that begin with "s" on the computer named "localhost":
get-winevent -listlog s* -computername "localhost"
# To see the details of just the Security log:
get-winevent -listlog security | format-list *
# ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Static_Methods.ps1 | Static_Methods.ps1 |
get-date | get-member -static
[System.DateTime] | get-member -static
[System.String] | get-member -static
[System.Math] | gm -static
[System.Text.RegularExpressions.Regex] | gm -static
# To show the static members of a class using the simple name of that class:
[DateTime] | get-member -static
[String] | ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/While_FlowControl.ps1 | While_FlowControl.ps1 |
$rabbits = 2
While ($rabbits -lt 10000) {
"We now have $rabbits rabbits!"
$rabbits = $rabbits * 2
}
$rabbits = 20000
Do
{
"We now have $rabbits rabbits!"
$rabbits *= 2
}
While ($rabbits -lt 10000)
# You could also loop forever or until you hit Ctrl-C, whichever c... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Nmap.ps1 | Nmap.ps1 | # Make sure your command shell is in the \Examples
# directory before running these commands.
.\parse-nmap.ps1 -path samplescan.xml |
where {$_.OS -like "*Windows XP*"} |
format-table IPv4,HostName,OS
.\parse-nmap.ps1 -path samplescan.xml |
where {$_.Ports -like "*open:tcp:23*"}
.\parse-nmap.... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/PingWrapper.ps1 | PingWrapper.ps1 | # To pass arguments into the named parameters
# of a script, use the Param keyword, just
# like with a function.
#
# Comments can come first, like these lines,
# and so can blank lines, but the Param keyword
# must be the first executable line of the script.
param ($computer = "localhost")
function pingwrap... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Command_Line_Args.ps1 | Command_Line_Args.ps1 | $args.gettype().fullname # System.Object[]
$args.length # Number of arguments
$args[0] # First argument
$args[1] # Second argument
$args[0..1] # First two arguments
$args[-1] # Last argument
$args[-2..-1] #... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Query-EventLog.ps1 | Query-EventLog.ps1 | ##############################################################################
# Script: Query-EventLog.ps1
# Date: 30.May.2007
# Version: 1.0
# Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505)
# Purpose: Demo how to search remote event logs with *server-side* WMI queries.
# Legal:... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Convert-DMTFtoDateTime.ps1 | Convert-DMTFtoDateTime.ps1 | ##############################################################################
# Script: Convert-DMTFtoDateTime.ps1
# Date: 30.May.2007
# Version: 1.0
# Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505)
# Purpose: WMI encodes date and time information in a special way that is
# ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/SnapIns.ps1 | SnapIns.ps1 |
get-pssnapin | format-list *
# To see which snap-in makes a given cmdlet available, such as the get-process cmdlet:
get-command get-process | format-list Name,DLL
# The following won't work unless you have Quest's snap-in installed:
add-pssnapin Quest.ActiveRoles.ADManagement
# Then to see a lis... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Creating_NET_Objects.ps1 | Creating_NET_Objects.ps1 | # To create an object whose parent assembly is already loaded:
$object = new-object System.Int32
$object = new-object System.DateTime
$object = new-object System.Net.WebClient
$object = new-object System.Net.Mail.SmtpClient
# But if the assembly containing the class hasn't been loaded, you'll have to load ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Regular_Expressions.ps1 | Regular_Expressions.ps1 |
ipconfig.exe | select-string "IP.*Address" -casesensitive
select-string -pattern "p[at]t*rn" -path *.log -list |
foreach-object { copy-item $_.path .\test }
"some input string" | select-string "(in|out)put" -quiet
if ($env:username -match "admin|root|super") { "Careful!" }
if ( "billy@corgan.edu"... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Parameters.ps1 | Parameters.ps1 | get-member -inputobject $x -membertype property -static
get-member -input $x -m property -static
gm -i $x -m property -s
get-process -name "powershell"
get-process -n "powershell"
get-process "powershell"
get-childitem c:\ | format-table
get-process "powershell" | get-member
dir | tee-object ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Parse-Nmap.ps1 | Parse-Nmap.ps1 | ####################################################################################
#.Synopsis
# Parse XML output files of the nmap port scanner (www.nmap.org).
#
#.Description
# Parse XML output files of the nmap port scanner (www.nmap.org) and
# emit custom objects with properties containing the ... |
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Drives.ps1 | Drives.ps1 | dir c:\
dir hklm:\
dir hkcu:\
dir variable:\
dir alias:\
dir cert:\
dir env:\
dir function:\
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.