Useful DOS/Powershell Commands

In this blog, I wanted to document some of the nice DOS/powershell commands that I frequently use.
  • nslookup - query the domain name service (DNS) to get information about domain names and ip addresses. For ex. nslookup www.microsoft.com or nslookup xxx.xxx.xxx.xxx
  • tracert - tracks the path a packet of information will take from your computer to the destination. It also gives the timing information. For ex. tracert www.microsoft.com
  • pathping - similar to tracert but it also pings each hop and gets additional information about timing, packets lost percentage etc. For ex. pathping www.microsoft.com
Most of the commands in powershell are a combination of "verb-noun" components. Common verbs are Get, Set, Out, Start, Stop, Restart, Add. Common nouns are Help, Command, Service, Computer, Location, ChildItems. Some of the more useful commands are described below:
  • get-alias
    all commands in powershell have aliases. For ex. dir or ls (from linux based systems) both point to the same alias get-childitems. get-alias gets the aliases for all the commands.
  • get-childitem
    similar to dir or ls in linux
  • get-command
    lists all the commands
  • get-command -verb "get"
    lists all commands with the verb get in it
  • get-command -noun "service"
    lists all commands with the noun service in it
  • get-help dir
    displays help for dir command
  • get-help dir -examples
    displays help for dir with examples
  • get-help dir -detailed
    displays a more detailed help
  • get-help dir -full
    displays the full help
  • get-command | where-object {$_.Name.Contains("Cult")}
    This example demonstrates pipelining. The output of get-command is fed into where-object command. where-object loops through each of the objects provided by get-command. $_ represents the "this" object in the .net context. So, this command will list all the commands whose name contains the word "Cult" in it.
  • get-command -verb "write" | sort-object length
    sorts the input of get-command based on its length.
  • dir | select-object name, lastwritetime
    select-object selects just the name and lastwritetime attributes from the input. The input is provided by the dir command.
  • clear-host
    same as cls in cmd.
  • Finding number of lines of code
    (dir -include *.cs,*.cpp,*.h,*.idl,*.asmx -recurse | select-string .).Count
Team Explorer Commands
  • To check permissions
    tf perf <tfs folder> /recursive > out.txt
  • To remove/allow permissions
    tf perm <tfs folder> /allow:Checkin /group:"[AI Fund]\Contributors"