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

Get | Set | Start

Retro Controls

12/19/2017

0 Comments

 
Navigating around PowerShell can be made easier using keystrokes. I remember the old DOS and Commodore 64 games that I used to play with the keyboard. It reminds me of the good ole days. Enough reminiscing though, on to the good stuff. Here are some keyboard controls to make things more efficient:
Tab complete - typing the first part of a Cmdlet, Function, Parameter, Path ect. followed by hitting the Tab key will employ PowerShell to complete it for you. The ensures that the command or path is both present and available as well as spelled correctly.
Up Arrow/Down Arrow History - Use the up arrow to scroll through the history of commands you have used as well as the down arrow to reverse direction. Once you have the one you want simply hit enter to rerun it.
Ctrl + R - In the ISE environment you can toggle between a full screen console and the split screen by simply pressing "Ctrl + r". This is handy if you are working on a script and need to see a lot of output.
0 Comments

All the Facts

12/19/2017

0 Comments

 

When researching a command to discover if it is Cmdlet, Function, Alias, etc.; it helps to get as much information as possible. To do this combine the powers of help and the command cmdlets.

Picture
Here we lookup mkdir with Get-Help and it pulls the help file for New-Item. We might assume that it is an alias, but lets use Get-Command to get the full story.
Picture
Now with this added information, we see that it is indeed a function that uses New-Item. Using Get-Help and Get-Command together can help us learn and better understand what we have to work with and how exactly it is working.
0 Comments

Updating Help Help

11/27/2017

0 Comments

 
Picture
Make sure once in awhile to update your help in PowerShell to make sure you have all the help available. Get-Help is one of the best tools within PowerShell to determine what Cmdlets can do and how to get them to do it. In order to update your help, simply run the command:
Get-Help
But remember to open PowerShell as an administrator in order for it to fully work.
0 Comments

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

What Language are You Speaking?

8/29/2016

1 Comment

 
My 4 year old son and I were playing the other day when he asked me something and I replied with silly gibberish. He promptly informed me to stop speaking Spanish. My gibberish in no way resembled Spanish or any language for that matter. However, to him it was foreign and he did not like it. PowerShell or any new technology can be like a foreign language. Scary, unknown gibberish. As a student of German, I understand that one of the best tactics to overcoming the fears and tackling the challenge is to face it head on and lean into it. If you want to learn a language, use it. If you want to learn PowerShell, use it. Find a few cmdlets that you can use daily and start. Force yourself to look for ways of conducting Windows administration using PowerShell. It will be slow and cumbersome in the beginning. You will start to realize the more you force yourself to be immersed in it, the more you will understand it's language. Here are some cmdlets to get going with:
Get-Service
Get-Process
Get-Help
Use Get-Help and then any cmdlet such as Get-Service to see what you can do with it.
Example: Get-Help Get-Service -ShowWindow
The -ShowWindow parameter will give you a nice thorough help article with examples
1 Comment
Forward>>

    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.