Skip to content

Instantly share code, notes, and snippets.

@rufflabs
rufflabs / Store-Credentials
Created May 23, 2015 14:33
Stores a username/password PSCredential in an XML file
<#
.SYNOPSIS
Stores a username/password PSCredential in an XML file.
.DESCRIPTION
@rufflabs
rufflabs / LSARecovery
Created May 23, 2015 14:26
Retrieve saved passwords from local service accounts
function Enable-TSDuplicateToken {
<#
.SYNOPSIS
Duplicates the Access token of lsass and sets it in the current process thread.
.DESCRIPTION
The Enable-TSDuplicateToken CmdLet duplicates the Access token of lsass and sets it in the current process thread.
The CmdLet must be run with elevated permissions.
.EXAMPLE
@rufflabs
rufflabs / Change-LocalPasswords
Created May 23, 2015 14:20
Changes the passsword for a specific user on multiple PC's
# List of hostnames
$computers = 'e:\computerlist.txt'
# Username and password to change to
$Username = ''
$NewPassowrd = ''
$ExistingCredentials = Get-Credential -Message 'Existing credentials'
foreach($Computer in (Get-Content $Computers)) {
echo "Changing: $($Computer)"
@rufflabs
rufflabs / Write-Log
Created May 23, 2015 13:55
Creates and cycles a log file
function Write-Log {
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)][String]$Message,
[String]$Path = '',
[Int]$MaxFileSize = 1024000, # In bytes
[Switch]$NoNewLine,
[Switch]$Continued
)
@rufflabs
rufflabs / Show-DialogMessage
Created May 23, 2015 13:52
Displays an informational dialog popup
function Show-DialogMessage($message = 'Default message')
{
$null = [Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');
$answer = [System.Windows.Forms.MessageBox]::Show($message, 'Informational Message',[Windows.Forms.MessageBoxButtons]::OK,[Windows.Forms.MessageBoxIcon]::Information);
return [String]$answer
}
@rufflabs
rufflabs / Get-PlainFromSecureString
Created May 23, 2015 13:52
Converts a Secure String into plain text.
#$Secure = <your secure string>
$Plain = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Secure))
@rufflabs
rufflabs / Pause-Wait
Created May 23, 2015 13:50
Emulates pause, waiting for the user to press any key to continue.
Write-Host "Press any key to exit."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludEKeyDown")
@rufflabs
rufflabs / Get-Bittage
Created May 23, 2015 13:48
Returns 32 or 64 depending on the bittage of the OS.
function Get-Bittage {
$Bits = [IntPtr]::size * 8
}