• Home
  • About
  • Contact
  • Resources
  • News
  • Home
  • About
  • Contact
  • Resources
  • News
Powershell Newbie

Get | Set | Start

Getting what you want

5/18/2017

0 Comments

 
Sometimes the output you get isn't quiet what you are looking for. Here is an example.
"My machine worked great this morning and started to slow down this afternoon."
So you go the machine and run:
Get-Process
You get a lot of information that could probably be better laid out for your quick troubleshooting. This is where select and sort are your friends.
select is an alias for Select-Object
sort is an alias for Sort-Object
First lets try:
Get-Process | Get-Member
This returns all the properties we have to choose from. Remember in PowerShell you are working with actual objects and that allows for a lot of properties and methods.
For now we will select name, starttime, and cpu:
Get-Process | select name, starttime, cpu
It still needs cleaned up so let's sort it:
Get-Process | select name, starttime, cpu | sort cpu
Better, but I don't really care about the processes using hardly any resources so we are going to flip the results by doing:
Get-Process | select name, starttime, cpu | sort cpu -Descending
Now with a quick glance we can see the biggest resource hogs and what time they started. Using select and sort can get you the preferred layout for your specific taste and purpose at the moment. Remember to use gm or Get-Member to find out what object properties are available to select from.

0 Comments

Play Hard, forget not

5/16/2017

0 Comments

 


As you are getting more familiar with the shell and begin to try more and more and more commands with more and more inputs and more and more parameters you might forget what you did 17 commands ago. Wait.. what was I saying.. Oh yeah. This is what get-history is for. Sure, you could hit the up arrow 17 times to get there. The nice thing about get-History is that it is like a map of where you and your thoughts have been. A map of how you got where you are. I have taken the history from some sessions I really want to remember the whole path of, and output them to a file for reference.
Try it.
Get-process
notepad.exe
Get-process
get-process notepad
get-process Notepad | stop-process
Get-history
Get-History | Out-File C:\users\youruser\history.txt

Great for referencing when you are starting out.

Note: In the newer versions of PowerShell you get to keep your history even after closing sessions. to get just the last 17 items for your history file add:
-count 17 after get-History
Example:
Get-History -Count 17

0 Comments

Yesterday's news

5/11/2017

0 Comments

 

The world of PowerShell moves fast like most of technology today. In order to keep up with the latest and greatest information you want to make sure to update your help files routinely. Make sure to right click PowerShell and run as administrator. Then simply type:

Update-Help

Simple and Sweet. It will update your help files for all installed modules and keep you cooking with the latest information.

0 Comments

A Cmdlet A Day

5/9/2017

0 Comments

 

Remember the desk calendars they would sell at the mall around Thanksgiving time as Christmas gifts. I used to get at least two a year. Hopefully one would be something I actually liked. Well, here is one you can actually use.
We are going to use our Get-COmmand but add a twist and pipe it to Get-Random. Run this once a day and explore different Cmdlets on a daily basis.

Get-Command * | Get-Random

Try it.
Now, let's add some useful information by adding another pipe and Get-Help with some examples.

Get-Command * | Get-Random | get-Help Examples

This will give you a nice 5 minute overview of a random Cmdlet for your exploration enjoyment. Happy exploring!

0 Comments

Get-command of it

5/4/2017

0 Comments

 
What will do what you need to do? This is the exact question that the Get-Command cmdlet answers. Try it. Open PowerShell and type:
Get-Command *process*
Picture
This provides us some possible commands to get, start, or stop a process or multiple processes.
Next we could use Get-Process to find a process that we might want to stop.
Put it in practice(hit enter at the end of each line and learn from watching the results):
Get-Command *process*
Get-Process *notepad*
notepad.exe
Get-Process *notepad*
Get-Process *notepad* | Stop-Process
First you get the commands. Next you use a command to get a result (or in our case, no result until notepad is open. Finally you use the results to cause an administrative action by piping from one command and resulting object to another command.
Now, go have fun and see what other commands you can discover!

0 Comments

Persistence

5/2/2017

0 Comments

 
Persistence: firm or obstinate continuance in a course of action in spite of difficulty or opposition.

If you are going to learn PowerShell; If you are going to be a PowerShell professional; You need to persist. There are going to be challenges and you will hate results and get frustrated at times. Learn to get over it and push through. I want you to succeed. In fact, pretty much the entire PowerShell community wants you to succeed and will gladly weight in and help you with those challenges at PowerShell.org. Go ahead and say a bad word if you need to. Then ask for help and attack the issue again, and again, and again. You can do it, others have. They did because they were persistent. You will do it to, if you persist.

Don't give into temptation and close out that console and lean on the GUI. Go ahead and open the GUI to get work done if time is of the essence. Leave the console open and go back to it to figure it out. Your future self thanks you.

0 Comments

    Joshua B. Jones, VCP6-DCV

    Professional PowerShell Fan, Automation & Virtualization Expert

    Archives

    February 2018
    January 2018
    December 2017
    November 2017
    May 2017
    August 2016

    Categories

    All

    RSS Feed

Powered by Create your own unique website with customizable templates.