Skip to content

Instantly share code, notes, and snippets.

function Add-LazyProperty {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[PSObject]
$InputObject,
[Parameter(Mandatory=$true, Position=1)]
[string]
$Name,
(gwmi win32_product -filter 'Name="name of application in Add/Remove Programs"').Uninstall()
([adsi]'WinNT://domain/username,user').ChangePassword('oldpassword','newpassword')
@sunnyc7
sunnyc7 / IIS_LogFileDir
Created January 28, 2014 16:32
IISLogFileDirectory - interesting behavior
Function Get-IISLogFileDirectory {
[System.Collections.ArrayList]$x = @()
Import-Module "WebAdministration"
foreach($site in (dir IIS:\Sites\*)) {
$x += [System.Environment]::ExpandEnvironmentVariables((Get-ItemProperty IIS:\Sites\$($site.Name) -name logFile.directory).value)
}
$x | select -Unique
}
@sunnyc7
sunnyc7 / Invoke-CommandAST.ps1
Created January 29, 2014 18:39
Invoke-Command as AST, to pass local functions to a remote session. Usually you cannot pass functions defined locally to a remote session
#requires -Version 3
#Usage:
#Invoke-command -computername $server -scriptblock {FunctionName -param1 -param2}
# Author: Matt Graeber
# @mattifestation
# www.exploit-monday.com
function Invoke-Command
{
[CmdletBinding(DefaultParameterSetName='InProcess', HelpUri='http://go.microsoft.com/fwlink/?LinkID=135225', RemotingCapability='OwnedByCommand')]
@sunnyc7
sunnyc7 / Get-InstalledProducts.ps1
Created January 31, 2014 15:22
Get Installed Products using MOF files. Entry for Scripting games
#Get MOF File Method
$mof = @'
#PRAGMA AUTORECOVER
[dynamic, provider("RegProv"),
ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),ClassContext("local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")]
class SG_InstalledProducts {
[key] string KeyName;
[read, propertycontext("DisplayName")] string DisplayName;
[read, propertycontext("DisplayVersion")] string DisplayVersion;
@sunnyc7
sunnyc7 / Get-DefinitionAndHelp.ps1
Created February 5, 2014 19:49
Find all references to Steppable Pipeline in Powershell help file and definitions.
#1 YMMV:
#2 Depends on the number of modules loaded in your session.
$allfunc = Get-Command | where {$_.CommandType -EQ "Function" -or $_.CommandType -eq "CmdLet"} | select -ExpandProperty Name
foreach ($cmd in $allfunc) {
(Get-Command $cmd).Definition | Out-File -Encoding ascii C:\scripts\$cmd-definition.txt
Get-help $cmd -Full| Out-File -Encoding ascii C:\scripts\$cmd-help.txt
}
Get-Content C:\scripts\*.txt | where {$_ -like "*Steppable*"} | select *
@sunnyc7
sunnyc7 / Dependencygroup-1.csv
Last active July 27, 2021 14:49
Powershell Dependency Mapping using Yuml.Me and Netstat
Source Localport Dest
xenapp05 56410 dc1
xenapp05 65387 dc1
xenapp05 65388 dc1
xenapp05 65389 dc1
xenapp05 65390 dc1
xenapp05 65397 dc1
xenapp09 57776 dc1
xenapp11 63367 dc1
xenapp11 63369 dc1
@sunnyc7
sunnyc7 / CodeLikeABoss
Last active August 29, 2015 13:56
They code powershell like a BOSS
Lee Holmes http://www.leeholmes.com/blog/
Oisin G http://www.nivot.org/
Jaykul http://huddledmasses.org/
Vadim Podams http://sysadmins.lv/
Roman Kuzmin http://nightroman.wordpress.com/
Matt Graeber http://www.exploit-monday.com/
Joe Bialek http://clymb3r.wordpress.com/
Glenn Sizemore https://twitter.com/glnsize
Bartek Bielawski http://becomelotr.wordpress.com/
Jim Christopher http://www.beefycode.com/default.aspx
@sunnyc7
sunnyc7 / Get-RipeMDHash.ps1
Created February 28, 2014 16:48
Powershell RipeMD hashing implementation.
Function Get-RipeMDHash {
[cmdletbinding()]
Param(
[Parameter(Mandatory = $True)]
[ValidateScript({Test-Path $_ })]
$file
)
Process {
$reader = [System.IO.File]::OpenText($file)
$RIPEMD160 = [System.Security.Cryptography.RIPEMD160]::Create()