Skip to content

Instantly share code, notes, and snippets.

function Get-RDPUsers ($computers) {
process{
foreach($computer in $computers) {
try {
$quser = quser /server:$computer 2>&1 | Select-Object -Skip 1
foreach($user in $quser) {
$line = [regex]::split($user.Trim(), '\s{2,}')
$o = if ($line[2] -eq 'Disc') { 0 } else { 1 }
@Xainey
Xainey / ResolveDependencies.ps1
Created September 13, 2017 05:53
PowerShell Dependency Resolver for DotSourcing Classes
# Quick Draft to Share
class Node {
[String] $name
[Boolean] $isImported = $false
[System.Collections.Generic.List[Node]] $edges
hidden static [System.Collections.Generic.List[Node]] $resolved = [System.Collections.Generic.List[Node]]::new()
hidden static [System.Collections.Generic.List[Node]] $unresolved = [System.Collections.Generic.List[Node]]::new()
@Xainey
Xainey / Get-ColoredSyntax.ps1
Created July 6, 2017 14:42
Easy to read function arguments from Get-Help
function Get-ColoredSyntax ($command)
{
Write-Host ("{0} " -f (get-help $command).name) -NoNewline -ForegroundColor White
$syn = ((get-help $command).syntax.syntaxitem.parameter) | select name, @{Name='type'; Expression = {$_.type.name}}, required
$width = 170
if ($host.UI.RawUI.WindowSize.Width -notin ("", $null)) {
$width = $host.UI.RawUI.WindowSize.Width
}
$curLength = 0
@Xainey
Xainey / space.ps1
Created February 23, 2017 19:50
Quick and dirty view
function space($pc)
{
Get-WmiObject Win32_LogicalDisk -ComputerName $pc |
Where-Object {$_.DriveType -eq 3} |
Select-Object DeviceID, VolumeName, `
@{n="Size"; e={[math]::round($_.Size / 1GB, 1)}}, `
@{n="FreeSpace"; e={[math]::round($_.FreeSpace / 1GB, 1)}}, `
@{n="PercentFree"; e={[math]::round($_.FreeSpace / $_.Size * 100.0, 1)}} |
Format-Table
}
@Xainey
Xainey / P-P-A-P.ps1
Created February 16, 2017 07:57
Finally got to test PowerShell on my Mac :)
$stack = New-Object System.Collections.Stack
function I {
if($args[$args.Count - 1]){
$stack.push($args[$args.Count - 1])
}
}
function UH! {
if($stack.Count -ge 2){
@Xainey
Xainey / CustomThrow.ps1
Created February 15, 2017 17:39
Testing throwing custom exceptions
# Generate a custom error without C#
function New-ErrorRecord ([string] $ErrorID, [string] $Message, [HashTable] $Custom)
{
$errorCategory = [Management.Automation.ErrorCategory]::InvalidResult
$exception = New-Object Exception $Message
$errorRecord = New-Object Management.Automation.ErrorRecord $exception, $ErrorID, $errorCategory, $Custom
return $errorRecord
}
@Xainey
Xainey / export.ps1
Created February 3, 2017 15:57
Powershell export command
function export
{
try
{
$s = ($args[0]).Split("=", 2)
if($s.Count -ne 2)
{
throw "more finesse please."
}
@Xainey
Xainey / touch.ps1
Created January 18, 2017 17:12
Touch command for PowerShell $Profile
# Add nix-like touch command
function touch
{
$file = $args[0]
if($file -eq $null)
{
throw "No filename supplied"
}
@Xainey
Xainey / PowerShell.svg
Created January 1, 2017 22:02
SVG Vector for PowerShell logo
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Xainey
Xainey / boxstarter.ps1
Last active November 10, 2016 15:54
Boxstarter
# Browsers
cinst googlechrome
# IDE and Extensions
cinst visualstudiocode
cinst vscode-powershell
cinst sublimetext3
cinst SublimeText3.PackageControl
cinst vim