Skip to content

Instantly share code, notes, and snippets.

@SadProcessor
Last active December 10, 2016 14:22
Show Gist options
  • Save SadProcessor/af9e49b8be443de9bddcd4d0aab54385 to your computer and use it in GitHub Desktop.
Save SadProcessor/af9e49b8be443de9bddcd4d0aab54385 to your computer and use it in GitHub Desktop.
PoShSysX >> External SysInternal toolbox via PowerShell - When you forgot your tools...
##PoShSysX.v1 - WalterLegowski
<#
.Synopsis
PoShSysX: External SysInternal toolbox via PowerShell
.DESCRIPTION
This cmdlet generates a powershell string that can be run on the localhost (default) or used as scriptblock for other tool (via clipboard).
When executed, connects \\live.sysinternals.com\tools\ as PSDrive and runs .exe from that path.
Always latest version of tools. No install to disk. (But slower...)
.EXAMPLE
SysX psping 8.8.8.8
.EXAMPLE
Invoke-SysExternals -Search *
.EXAMPLE
SysX -Search *64
.EXAMPLE
Invoke-SysX psping.exe '-?'
.EXAMPLE
SysX psping '8.8.8.8 -nobanner' -Drive X -Clip
.INPUTS
Search Item | Tool (+ Params) (+ DriveLetter)
.OUTPUTS
Search result | Command to clipboard | Command result
.NOTES
Some SysInternals require GUI|Admin
.FUNCTIONALITY
When you forgot your tools...
#>
Function Invoke-SysExternals(){
[CmdletBinding(DefaultParameterSetName='Run',HelpUri='https://technet.microsoft.com/en-us/sysinternals/bb545027.aspx')]
[Alias('Invoke-SysX','SysX')]
Param(
# NameOfTool(.exe)
[Parameter(Mandatory=$true,Position=0,ParameterSetName='Run')]
[String]$Tool,
# 'ParamString -with Quotes -If Needed'
[Parameter(Mandatory=$false,Position=1,ParameterSetName='Run')]
[String]$Params='',
# -Drive 'X' (DriveLetter for Temp PSDrive. Default is T)
[Parameter(Mandatory=$false,ParameterSetName='Run')]
[String]$Drive='T',
# -Clip >> output to clipboard
[Parameter(Mandatory=$false,ParameterSetName='Run')]
[Switch]$Clip=$false,
# -Search >> search tool by name (accepts wildcard*)
[Parameter(Mandatory=$false,ParameterSetName='Search')]
[String]$Search
)
## ACTION
# If -Search
if($Search){
# Search tool
$ToolList = @('')
$ToolList += (iwr "https://live.sysinternals.com/tools/").Content.split(' ') -match 'HREF' | %{(($_.split('>')[1]).split('<')[0])}
$ToolList = $ToolList -match '.exe'
echo ($ToolList -like "$Search*")
Break
}
# Else
# Append '.exe' if needed
if(!($tool -like "*.exe")){$tool += '.exe'}
#Generate string command
$String = "`$Null = ndr -N $Drive -PS 'FileSystem' -R '\\live.sysinternals.com\tools\'; iex `"${Drive}:\$Tool --% /accepteula $Params`""
# Copy to clipboard...
if($Clip){$String | clip.exe}
# ... or Run command
if(!($Clip)){iex ($String)}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment