A Cmd/Windows/Powershell Rosetta

Here’s a copy of some Onenote notes I  made about 4 years ago when I was a Linux user desperately trying to learn Windows (and this was before WSL). Back in my day we were forced to use Cygwin or MinGW! There are some other similar guides out there. Hopefully this helps someone! I’ve done some light editing, but this is mostly my notes in raw form.

A powershell survival guide:



Powershell Linux/Unix Windows CMD PS Alias
get-acl whoami whoami whoami
get-alias aliases   gal
clear-host clear cls clear
get-volume df    


fdisk chkdisk  
enter-pssession ssh   etsn
Get-ChildItem ls dir ls, dir
Remove-Item rm del rm, del


ps tasklist ps
Get-Location pwd   pwd
Move-Item mv move mv
Stop-Process kill taskkill kill
Get-History h [f7] h,history
Set-Location cd cd cd
Get-Content cat type cat,gc,type
Copy-item cp copy cp
Tee-Object tee   tee
New-Item -type file touch   ni
Get-ChildItem Env:/gci Env: env set env (sometimes)
Get-Help man help man, help
Select-String grep findstr sls
  logout shutdown /l


Get-ChildItem find where gci
Sort-Object sort   sort
Get-Content -totalcount

Select-Object -first

head   gc


Get-Service update-rc.d/chkconfig sc config gsv
start-service service start /etc/init.d/<service>start net start/sc start sasv
get-content <file> -tail <n>

select -last <x>

tail -n <x>   gc
Get-Service service –status-all/   Gsv
Get-Netipaddress/New-NetIpAddress Ifconfig ipconfig  
Get-NetAdapaterStatistics ifconfig    
adduser   net user  
Get-Command which, alias <command> where gcm
Test-NetConnection ping ping  
Test-NetConnection -Traceroute traceroute tracert  
Test-Netconnection -Port tcping    
Test-Connection ping ping  


dumpbin /dependents “file.exe”

(dumpbin comes with visual studio)

foreach {“{0}” -f ($_ -split ‘\s+’)} or

foreach {($_ -split ‘\s+’)[0]}

awk ‘{ print $1}’    

measure-object -line

wc -l   measure
measure-command time    


shutdown -h now shutdown /s /t 0  


set-alias alias command=   sal
get-culture locale    


  dd if=/dev/random of=/temp/file size=1gb  fsutil file createnew 1gbtest (1gb)  
write-eventlog logger eventcreate  
Rename-computer newhostname hostname  new-hostname    
Add-Computer -DomainName ADDOMAIN Joindomain-cli ADDOMAIN adminuser (using powerbroker) otherwise…winbind    
Test-ComputerSecureChannel -credential domain\admin -Repair      
New-netfirewallrule iptables    


$wmi = Get-WmiObject -Class Win32_OperatingSystem;$wmi.ConvertToDateTime($wmi.LocalDateTime) – $wmi.ConvertToDateTime($wmi.LastBootUpTime)




Process Magic

Get a process with a listening port:

netstat -aon|sls LISTENING|sls  port

Use WMI to get a procid

get-wmiobject win32_process -filter "ProcessID like '1234'"

Use WMI to get a process with owners

Get-WMIObject Win32_Process -filter 'name="explorer.exe"' -computername 'localhost' | ForEach-Object { $owner = $_.GetOwner(); '{0}\{1}' -f $owner.Domain, $owner.User } | Sort-Object | Get-Unique

Use WMI to get something similar to ps auxww

Get-WmiObject Win32_Process -Filter "Name like '%java%'" | select-Object ProcessId,CommandLine|format-list

qwista, query session


Powershell Commands are in Verb-Noun form. You can search for them:

get-command (list of commands)

get-command -Verb Get (your verb choice)

get-command -Noun String (your noun choice)

Get-Help man (man works)


Get detailed info about a drive

Fsutil fsinfo ntfsinfo c:

GUI: Computer Management

# Like du -s

gci . | %{$f=$_; gci -r $_.FullName| measure-object -property length -sum | select @{Name=”Name”; Expression={$f}} , @{Name=”Sum (MB)”; Expression={ “{0:N3}” -f ($_.sum / 1MB) }}, Sum } | sort Sum -desc | format-table -Property Name,”Sum (MB)”, Sum -autosize


Command similar to Linux find:

# This will find mp* files

Get-ChildItem “file_location” -Recurse -Include “*.mp*”,”*.m4*” | foreach-object {$_.Fullname}

Remote session in windows (like ssh)

ssh enter-pssession ComputerName –credential UserName,

Needs port 5985 open

# Open up firewall on the server

netsh firewall add portopening TCP 5985 “Winrm 2.0 port 5985″

or the new way

netsh advfirewall firewall add rule name=”Winrm 2.0 Port 5985″ dir=in action=allow protocol=TCP localport=5985

# Trusting the remote host

winrm set winrm/config/client @{TrustedHosts=”RemoteComputerName”}

Making a profile (equiv edit .profile):

New-Item -path $profile -type file -force

Pipe things:

get-command | select-string -pattern “Start”

Select-String vs Where-Object

Frequently, output of commands is formatted in object columns. Select-string won’t grok it, but where-object (where) will. You’ll just need to specify the object name:

get-service|where {$_.DisplayName -like “*Apache*”}

Additional Info on using “Where-Object” to pass multiple conditions


dir E:\temp | Where-Object { $_.PSIsContainer -and $_.Name -like ‘t*’ }


#You will often need to add parentheses to group expressions on either side of the -and and -or operators

Get some vim

Vim doesn’t really work remotely, nor does any editor.

You can do some fun pipe tricks to download the file, and reupload it, but your best bet is probably just to go into file explorer, and edit the file that way.



Command Shell Overview

Windows Command Line Reference

Powershell Cheatsheet



Switching from Mac to Windows

For a lot of tech geeks, there seems to be a lot of interest lately in switching from Mac to Windows. Especially in light of the fact that Apple is killing off the escape and function keys, and Windows has just added Linux functionality.

I was, like a lot of Linux geeks a Windows hater for years and years. I then got completely burned out by an OSS loving startup and got an offer from Microsoft which, after working there, caused me to reconsider my blind brand loyalty. I use a lot of Microsoft stuff now out of convenience, but I also use a lot of OSS at work. Believe it or not, by and large Microsoft internally has taken a “best tool for the job” approach, with the caveat that you should at least should try theirs first.

That seems to be the first step in switching. A lot of folks consider themselves to be “An Apple Person” or “A Windows Person” or even “A Linux Person”. Lets stop right here and be pragmatic as most geeks are want to be. You want something that gets the job done, right? Who cares if it’s Mac or Linux. Vim or Emacs. Postgres or MySQL. Ruby or Python. You get my point. We live in an age where there are a lot of wonderful tools that we can choose from. So lets celebrate that (and not slag the choices of others).

So after using Windows for a bit, what do I like about the Windows ecosystem? Why else would you want to switch? Here’s some things I enjoy about being a Linux admin that uses Windows

Why Switch?

Hardware choice: This could be a negative, since there are a lot of vendors that produce great hardware that rivals Apple. It also tends to be cheaper. I’ll admit they don’t tend to hold their value as well for resale as Apple because…well it’s easy to pick up newer cheaper hardware. However, you can get a laptop a lot like a Macbook Pro, or you can get a laptop with a built in ethernet and VGA port with a removable battery.

Apps: As any Mac user knows, you still from time to time run into some software or hardware that needs Windows to run or update. The nice thing is that you can run them now! The sad thing is there are a number of Mac apps you may need to find an equivalent to. Oh and you can still run iTunes if you really want to.

Linux: Windows Subsystem for Linux (WSL) makes it possible to now run Linux apps. Which as most Mac folks know is what they really wish they were running on their Mac. Sure homebrew allows you to run a lot of apps on the Unix portion of Mac, but a lot of us know Ubuntu better than some of the non-standard things OS X uses like launchd. That said WSL isn’t perfect (ping doesn’t work yet). And you’ll still need to learn a lot of Windows things to make full use of Windows. You can think of WSL as a native Linux running under Windows, but it’s not exactly Windows aware from an internals perspective.

I won’t get into switching to desktop Linux. I’ve tried it myself over the years and for me, it’s just not there yet. I just want to use something that works, and I’ve personally had a lot of issues with desktop Linux that I haven’t had with Windows or OS X. Your mileage may vary of course.

The Geek Learning Curve

So some things you’ll want to do if you switch to Windows:

Learn Powershell: Yes you can use Bash in Windows, but it doesn’t do all the Windows system stuff you’d like (like dive into WMI objects, start/stop windows services, or scheduled tasks). This is a bit easier than you think, but it will make understanding Windows easier. Powershell is very similar to languages like bash and ruby. Though unlike bash, instead of parsing text output all the time, you’ll be parsing objects which you’ll wonder why bash doesn’t do after you’re use to it. Once you realize that Windows, Linux and OS X basically all do more or less the same thing under the hood, it becomes a lot easier. You just need to find the equivalents. Here’s a good place to start.

SysInternals: If you’re a Linux geek, and like to really know what’s going on with your OS. You’ll probably want to use the Windows Sysinternals Suite. Procmon is by far the most useful of all the tools, but the rest will give you better insight to the system that the tools that come with windows lack. There’s even a book just published on this.

Find the apps to make you productive: You can find a lot of equivilants for OS X on the internet, but some essentials I use as a Linux admin are ConEmu, Visual Studio Code, Enabling WSL, enabling chocolatey in the Windows Oneget repository (Oneget is a windows app management repo like apt or yum), vim and git.

Read some Blogs: You’ll probably want to read some blogs to get you up to speed. Hey Scripting Guy is great for learning Powershell. And Scott Hanselman has a lot of great Windows tricks he shares. There are also of course subreddits dedicated to this stuff.

What am I using?

So when I switch off my old Macbook Pro, I wanted something that was a little better than it. My criteria was:

  • Needs to have a fingerprint reader. I wanted Windows Hello, which uses biometric authentication. However, after trying the facial recognition, I found it annoying that it would just unlock without my telling it. That meant the Surfacebook Pro was out for me.
  • Needs to be a 2-in-1 PC. Which means it needs to be able to convert to tablet mode somehow. I like to read PDFs on my computer without it being in “keyboard in front of me” mode. It’s also nice to watch longer videos without the keyboard in front of me.
  • Needs to be touch screen, which the above basically requires. I use touch surprisingly often, though I know people who don’t. It can really save on mouse travelling/targeting to just poke the thing you want. If you go to tablet mode, yes obviously you’ll need this.
  • Runs Windows Signature: This was a nice to have. I could probably take a PC and flatten it with a new version of Windows to remove the crapware, but I’d rather it be ready out of the box.

The winner ended up being a Lenovo X1 Yoga. Now there are many other laptops out there to fit whatever your requirements are. I like the design of Lenovo because it’s tough and tends to favor function slightly over form. I really don’t care about brushed aluminum, but if you do, then vendors like HP, Dell, and Asus and Microsoft also make laptops that you may consider.




Do we really need backups anymore?

Like many good sysadmins I’ve been pretty good about keeping backups at home. I’ve done so for a number of years, going through free solutions like boxbackup a while back, and then trying other big name solutions out such as Mozy, CrashPlan and Carbonite. So I got a notice recently that my backups payment was due again. Costs for backups have risen a bit since I remember. It used to cost me about $75 a year and now it’s closer to $120-$150 which made me think…how badly do I need this service?

Let’s back up a bit (pun intended)…

In the old days before everyone was talking about The Cloud you really needed backups. Your e-mail was stored all pretty much on your computer. Your music collection. All those documents on your computer that formerly were in your file cabinet were there. Your contacts list. Your financial stuff. Your photos. All this stuff was on one big Single Point of Failure.

Times have changed…

All the things above typically aren’t on your computer anymore. A lot of people use Pandora or Spotify making the Music Collection obsolete.  iTunes came out with iTunes Match which stored your music in their cloud for you if you still like things that way. If you use Google or Microsoft, they store your e-mail, they have fairly cheap to free drive solutions you can store your documents away including financial stuff. You can use their bank, or Mint for keeping up with finances. Most people take pictures with their phone and there are options to automatically upload your photos to Onedrive, Google Photo, or Dropbox. And they have nice photo album options anyhow so why not put all your photos there?

I started to think about what would happen if I lost my computer right now. What would I freak out about? What would I lose? The answer started to quickly become “not much”. Looking through my hard drive, I realized my computer is turning more and more turn into a client in the cloud server world, and I’m alright with that. I uninstalled my backup software, and didn’t look back.

SSH in Windows the Linux Way

Everyone that uses Windows ends up using putty, which bothers me because putty (and it’s fork, kitty) has its own separate program, with its own terminal. I’m used to being in the command line doing whatever it is.

These days my console is ConEmu. If you’re suffering through the stock powershell console, I highly recommend trying it out along with PSReadLine. Once you’ve set those up you’ll start to have a console closer to the one you loved in Linuxland (if that’s what you’ve longed for).

For ssh, there are a couple options:

  • Install MinGW+MinGW-Get
  • Install Cygwin with openssh.

You may have one of these things installed. If not it’s easy enough to use chocolatey to install them.

You’ll want to verify the ssh your %PATH% is directing you to. MinGW-Get, Conemu, and Github will all install ssh for you and it may be unclear which one you’re using:

which ssh

If you’re a powershell user you may want to set an alias to the ssh you prefer in your Profile.ps1. I prefer the cygwin one, but of course it’s your choice.

set-alias ssh C:\cygwin64\bin\ssh.exe

ssh configs

If you use cygwin, you can edit your ssh configs in:


Git’s ssh will look for your things in:

C:\Program Files (x86)\Git\etc\.ssh\
 I ended up using procmon from Sysinternals to find these config locations, which for you Linux people does a lot of the same thing that lsof does. Enjoy!

Fixing Onenote’s “Sorry, another account from your organization is already signed in on this computer” on OS X

I spent this afternoon fixing this, so I thought I’d share what I found.

It seems that when trying to sign into OneNote on OS X using Office 365, one can run into trouble signing in, especially if you’ve used OneNote on the system before with another Office 365 account.

I’d originally tried to find the files that OneNote was using using lsof on the command line. While I still recommend this, truthfully I don’t think this is what fixed it. I’d start doing this with Office Uninstalled is that Office and OneNote are somewhat intertwined, and you’ll probably hork up your Office install by performing these steps and will need to reinstall it anyhow.

In any case, you should get a list of files that OneNote is hanging on to when in runs. With OneNote15 on OS X Yosemite I found the following:

'/Users/kris/Library/Group Containers/UBF8T346G9.Office'
'/Users/kris/Library/Saved Application State/com.microsoft.onenote.mac.savedState'
'/Library/Logs/DiagnosticReports/Microsoft OneNote'

For the command line savvy, just do the following to find your OneNote files, on my system, using locate seemed to ignore many of the directories in question:

find / -iname onenote

This will find the directories above for your user. Uninstall OneNote. I installed mine from the app store, so that required me to go to launchpad, find onenote, hold down the mouse button till it jiggles and press the circle x that appeared.

Afterwards, delete the directories you discovered since the uninstall process won’t.

Next is the step that I think really fixed the issue.
* Open up the Keychain Access app.
* Select “Passwords” on the right under “Categories”
* Search for “Office”
* Delete everything you find in there, you’ll likely see a few items such as:
** Microsoft Office Identities Cache 2
** Microsoft Office Identities Settings 2
** A credential key with a GUID for a name. It’ll have a blue @ sign.

After that, install OneNote, and try to sign in. In my case, the error was no longer present, and I was able to sign in using my Office 365 account.

How to use your own domain with outlook.com

I’ve been around the e-mail block a few times. I’ve used Google apps with Gmail, Office 365, and Outlook.com. Outlook.com seems to have a pretty interesting offering I’ve been happy with so after a lot of going around trying to figure out some of how it works, I decided to share some of my discoveries.

There are some blogs that say use domains.live.com to register a new account with Outlook.com. Stop. Don’t do it. Why? Because you’ll only get to register that one e-mail address, verifying others will be impossible. Plus I’ve discovered, it’s not really the “right” way to do things. Domains.live.com is likely only around for legacy reasons.

So what’s the right way?

If you want to host your own domain there are a few options. These days Office 365 and Google Apps are your best “business class” options. Both are great. However, your Google Apps account will be a Google account like any other home google account, with access to the same services as any normal Google user. Microsoft decided not to do that, so in the Microsoft world, you have two choices for e-mail:

     * Microsoft accounts: These are evolutions from previous microsoft account types. Such as live.com, hotmail.com, msn.com. Microsoft has made many attempts at a single sign in (much like Google has) and this is the current term for them. You can also have a domain based account through domains.live.com much like you could with Google. This service isn’t available any longer to non-paying customers with Google. However, Google doesn’t have the dual accounts paradigm that Microsoft does.

     * Office 365 accounts: These are domain based accounts which you’ll use do sign into office 365. It it useful only within the Office365 realm that you create when you have the service. Also, multiple sign on doesn’t work so well so if you have two Office 365 accounts to sign in at once, you’ll need to create a separate browser session.

What does Office 365 have?
With even a basic Office 365 account (NOT counting Home Premium, that is a weird service not really related to Office 365 at all). You get
* Domain based e-mails
* Webmail with mail, calendar, contacts, etc
* Your own web hosting service
* Lync messaging within your business or domain
* Onedrive for Business (which is basically just a Sharepoint filesystem NOT linked to consumer Onedrive at all)
* Internal Sharepoint site
* Powershell integration so you can script creation and reporting commands
* 5 downloads of MS Office per user (with Small Business Premium)
* Office Online (Microsoft’s answer to Google Apps…which was Google’s answer to Office)
* Mobile integration is just exchange. Though they have a neat iPad/iPhone app: OWA.
* 2 factor authentication only for Midsize plans or higher.
* Supports Exchange, IMAP, and POP
* Real support
* 99.9% uptime guarantee

For e-mails it’s pretty much just Hosted Exchange:
* Shared mailboxes
* Distribution lists (external, or forced internal only)
* All the aliases you want for users

So if you’re wanting to host your domain there, that’s what you get for your money. Unfortunately it’s overkill for me in some areas and lacking in others.

What does Outlook.com have?
* Outlook.com mail app for Android
* 2 factor authentication
* Webmail with mail, calendar, contacts, etc
* Supports Activesync, IMAP, and POP
* Chat integration with Skype, Google Chat, and Facebook

It’s a lot less, but the important things for me were:
* The android app
* Skype integration
* The webmail for Outlook.com just seems better.

In other words, Outlook seems tailored for the home user, using Office 365 can be an awkward fit.

So how DO you use outlook.com with your own domain?
Really the best way is to go to your domain registrar and use a forwarding service. If not use one from someone like dyn.com or dnsmadeeasy.com. Neither require you host the domain there, and they have ok rates. Otherwise you could set up your own, but I’m guessing you’re trying to get out of the hosting your own e-mail business if you’re reading this. I use name.com which suits my needs.

So create a normal outlook.com account (Which is really a Microsoft Account) with a name of your choice. The beauty is you can your account name very easily, and if you verify your e-mail, you can actually switch your account to use that e-mail to log in. This is why using domains.live.com isn’t really with it.

Once you log into your outlook.com account.Click on the top right to “Account Settings”.
From here you should see an overview page, with the option to create aliases. As long as you can receive e-mail to that address, you can verify it as an alias, and you can start forwarding that e-mail to your outlook.com address later.

You may have some assumptions about what an alias is…

Fun facts about Outlook.com aliases:
* They allow the user to use that address to log into Microsoft services
* They allow the user to send e-mail from that address
* Your primary alias is use as your default “From:” address.
* You can have 1 primary alias and a limit of 10 other aliases.

If you create an alias on one account and need to transfer it.
* One you let the alias go, it ends up in limbo for 30 days.
* Old Microsoft accounts themselves will lay dormant for 270 days (9 months).

You do NOT need to create an alias to receive forwarded e-mails to that account.

You may find that forwarding your e-mail to outlook.com from certain forwarders results in bounces from what I’m guessing are SPF restrictions. In my testing so far, name.com doesn’t seem to have this issue, but I’ve had this issue forwarding from Office365 to Outlook.com. Some of these include Facebook, Twitter, Linkedin, Living Social, and others. I recommend extensive testing before cutting things over. One workaround of course is just use your Microsoft Account for these periodic spam notifications. It’s not like your friends are going to see it.

An Introduction to Sensu

Sensu is an open source monitoring service for the cloud by Sonian the diagram below explains most of how it works quite well, but it has several components in order to make it scalable:
RabbitMQ is really the central “server” in terms of where checks come from, and where the results go. Here’s the flow of a rabbitmq check.
  • Server gets a new check that the client needs to execute. It puts that into rabbitmq.
  • Client checks rabbitmq for any checks to execute, it sees a check it should perform, so it gets the data from rabbitmq, and executes the command.
  • Client takes the results of the command, and puts that into rabbitmq
  • Server checks for command results, sees that a client put in a result. It posts it to the dashboard.
Metrics (Graphite):
  • Server sees a metric, as directed by the handler, it puts it into the rabbitmq for Graphite’s carbon service.
  • Carbon takes that data from rabbitmq and puts it into graph.
Built for the cloud. Sensu is made to have clients just magically appear. There is no individual client specification in the config files in Sensu. Likewise, Sensu has a REST based API where clients can be just as easily removed.
Scalable. Since the central service uses rabbitmq, which itself is quite scalable and can be run HA if necessary, It also has discrete components which can all also be made redundant.
Integration with Graphite. Sensu checks by design, integrate with graphing engines like graphite. Also no clients need to be registered in graphite for them to appear.
Server Components:
Sensu server has 4 chief server components:
The server initiates checks on clients, receives the output of the checks feeds them to handlers. (As of version 0.9.2, clients can also execute checks that the server doesn’t know about and the server will still process their results, more on these ‘standalone checks’ in a future article.)
Sensu-server relies on a Redis instance to keep persistent data. It also relies heavily (as do most sensu components) on access to rabbitmq for passing data between itself and sensu-client nodes.
A REST API that provides access to various pieces of data maintained on the sensu-server in Redis. You will typically run this on the same server as your sensu-server or Redis instance. It is mostly used by internal sensu components at this time.
A minimal dashboard providing an overview of the current state of your Sensu infrastructure and the ability to perform actions, such as temporarily silencing alerts.
A better web dashboard providing an overview of the current state of your Sensu infrastructure and the ability to perform actions, such as temporarily silencing alerts.
  • There are two types of plugins that checks run: metrics (handled by graphite), and checks (handled by sensu).
  • Clients get groups of checks called subscriptions. Subscriptions are defined on the server. Clients can get multiple subscriptions.
  • Clients must have the plugin that they are running locally. The plugin must by executable.
  • Clients must be able to reach the rabbitmq server defined in /etc/sensu/config.json
  • Client’s definitions are in /etc/conf.d/client.json. Any *json files in this directory will be parsed.
  • Client definitions are ruled by chef.
Sample client.json
   “client”: {
“name”: “app0”,
“address”: “”,
“subscriptions”: [ “linux” ]
When adding server checks you’ll need to restart the server. At times this can be painful and you need to kill -9 the process.
Fast facts about checks:
  • Server Check Configurations: netmon1.pointinside.com:/etc/sensu/conf.d
  • Check Format: JSON
Sample metric check (JSON):
“vmstat_metrics”: {
“type”: “metric”,
“handlers”: [“graphite”], 
“command”: “/etc/sensu/plugins/vmstat-metrics.rb –scheme stats.:::name:::”,
“interval”: 60,
“subscribers”: [ “linux” ]
Sample alert check:
“mem_check”: {
    “handler”: “default”,
      “command”: “/etc/sensu/plugins/check-mem.sh -w 10 -c 5”,
      “interval”: 60,
      “subscribers”: [ “linux” ]
The handler defines what happens with the check output. There are many custom handlers out there. Of course the standard is an e-mail handler:
   “email_techops”: {
      “type”: “pipe”,
      “command”: “mail -s ‘sensu alert’ techops@pointinside.com”