Powershell Functions and Aliases

Save the MINGW32,GITBASH,CYGWIN comments. They are all a little quirky IMHO, and powershell still brings a lot to the table when you're doing windows scripting. Especially over vbs,wsh,cmd. I've found trying to write a shell script that runs on multiple platforms a maddening experience.

So I've chosen the only logical choice. That's the perpetually torment myself by trying to translate some of the more helpful commands I've come to use on unix.

Here is a list of things I've decided to remove from the defaults that powershell as so kindly given me.

Aliases / De-aliases


Hey Microsoft, curl != Invoke-WebRequest

Remove-Item -Path alias:curl



Create a 0 byte file

function touch {
    New-Item -Type File -Name $args[0]


C:\Users\Casey> touch testfile.txt

    Directory: C:\Users\Casey

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        5/26/2016  12:17 PM              0 testfile.txt


Get-Content can pull the last n records off a file to show you. But what if you wanted to do a tail on a log and just watch it? that's what -Wait is for

get-content -tail 1 -wait

Skip / Take example

If you want to skip the first few lines of a file.

Get-content $file | select-object -skip 3

SSH/Remoting Behavior

Tusted Authentication variant
This will connect to a remote powershell instance on the host machine specified. Assumes Trusted/AD authentication

function ps-ssh {
  #Assumes trusted authentication
  if($args.length -ne 1) {
    $computername = Read-Host "Please provide a computer name to connect to"
  } else {
    $computername = $args[0]

  write-host "Connecting to $computername"
  $remoteSession = New-PSSession -ComputerName $computername
  Enter-PSSession $remoteSession