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

curl

Hey Microsoft, curl != Invoke-WebRequest

Remove-Item -Path alias:curl

Functions

touch

Create a 0 byte file

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

Example:

C:\Users\Casey> touch testfile.txt


    Directory: C:\Users\Casey


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

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
}

General Troubleshooting

Get-Item will pretty much show you what's persisted in your current session. It actually usually various providers on the system that provide information to it. This is the part of Powershell I find very cool.