I could have stored the process object in a variable, and then used a dotted notation to reference the StartInfo property. (Get-Process -id 1360).StartInfo | select -ExpandProperty environmentvariablesĪs shown in the figure that follows, this command opens an entire page of additional information.Įarlier, I needed to hone in on the StartInfo property of my process. This results in the command that is shown here. In the example that follows, I use the Select alias for the Select-Object cmdlet. Unfortunately, it seems that nothing can return all of this information-that is until I use the Select-Object cmdlet with the ExpandProperty parameter. I illustrate this technique here.ĮnvironmentVariables : When I do this, the ProcessStartInfo object will be revealed. To access this object, all one needs to do is to use “dotted notation,” which means I put parentheses around the command, and directly access the property. The applicable line from the output is shown here. The object is an instance of the ProcessStartInfo object. In the previous output, the StartInfo property returns an object. PS C:\> Get-Process -id 1360 | fl * -Force To hone in on one of those processes, I use the process ID and pipe the results to the Format-List cmdlet. Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName For example, on my laptop I use Get-Process to look for processes that begin with the letters wu and are followed by zero or more letters. Some of these objects are rather obvious others are not.
#Cool cmd hacking tricks windows#
Let me explain, many Windows PowerShell cmdlets return objects that contain other objects. What do I mean by “hidden” objects? Well, perhaps I could have called them “embedded” objects. As shown in the following image, the command and output correspond directly. It might be interesting to compare the output from the transcript log file with the commands typed in the Windows PowerShell console. Notice the header portion that gives user, computer, OS version, and time created information. A sample of transcript output is shown in the following image. The transcript shows the commands that are run and the results of those commands. In addition, it is useful as a record of changes that I may have made to a system. If I did find something useful, I have built in documentation for the commands. By having a transcript, I have a complete record of everything I did. Why do I like the transcript? Well, if I am exploring, I am simply trying out different commands to see if I can find something useful. To stop the transcript, use the Stop-Transcript cmdlet, or simply close the Windows PowerShell console. The file name is based on the current date and time that the transcript was created. The transcript is a text file that is stored in your user profile location. The Start-Transcript cmdlet will create a transcript file that contains every command you type and the output associated with that command.
When I am exploring Windows PowerShell, the first thing I do is create a transcript. I talk about tricks 5 – 7 tommorow, and tricks 8-10 the following day.
#Cool cmd hacking tricks series#
NOTE: This is part 1 of a three part series of articles on my Top Ten Favorite PowerShell Tricks. Woops! Mark had a question about environmental variables, and that led to me showing him one of my favorite Windows PowerShell tricks. When I looked at my watch, I saw what had made her curious-it was 7:30 at night, and the session had been over for two hours. “I was answering a couple of questions he had about Windows PowerShell.” “Well, I was talking to Mark after the session,” I said. “I went to Mark’s session on data mining,” I replied. Would you like to meet me in the lobby so we can go get dinner?” I asked. The conversation went something like this: On Friday evening, following the last session of SQL Rally in Orlando, I sent a text message to the Scripting Wife to join me in the lobby of our hotel so we could go do dinner. Whenever two or more Windows PowerShell devotees get together, it is not very long before one of them drags out a laptop and begins to share something they have figured out using Windows PowerShell. In addition, I get to talk to people from all over the world who are as excited about using Windows PowerShell as I am. I get to play around with Windows PowerShell all day, and I get to do it every day.
Without a doubt, I have the perfect job-at least for me. Microsoft Scripting Guy, Ed Wilson, is here. Summary: Microsoft Scripting Guy, Ed Wilson, shares four of his top ten favorite Windows PowerShell tricks in this first of three blogs. Create a Record of PowerShell Commands and Output, Find Hidden Objects, and Expand Properties