Well did the first 4 Modules of the CBT Nuggets I have to say I do like the Don Jones Videos easy to listen to and so far they have all been superb. Its not exciting stuff, but I think its stuff that will get me going I posted my notes below as its good
info.
I have a ProLiant 380P G7 with around 100GB of RAM and a couple of processors and like 5TBs that I setup with VMware Cloud, and then installed Three - Four Server 2012 Enterprise, and Two windows 8.1 Enterprise and one windows 7 Enterprise
as well as a few other OS. Connected it all up to the some Cisco Switches and setup network access to the internet, as well as a Sandbox network to work as my Lab.
I have a few more things besides PowerShell that I want to work with but PowerShell is now one of my priorities.
Anyway below is my notes, not something you can just watch and then move on so the first four videos took way longer than just the 20+ minutes as I had to stop them work on things and rewind them as needed.
CBT NUGGETS POWERSHELL NOTES:
Good to get your font changed when working on a PowerShell console.
Consolas is good and then increase font size to 18 or so.
Next go to layout and to Window size and change windows size height: to around 150 it will stretch out screen.
However on screen buffer size change to match the window size height.
If you do not then you will get an annoying scroll bar which can be a pain to work with.
Importing modules and snapins; Searching for commands
Extend the Shell with snapin (legacy not used much now)
Get-PSSnapin
Registered
Add-PSSnapin
Name <somename>
Another way is as follows: (note this is a per window if you opened up a new window or close the current one it goes away.)
Get-Module
ListAvailable
Import-Module
-Name <TroubleshootingPack>
: You can use command to get command but also if you want to filter it you can use the commandtype see below:
Get-Command
-Name
*pack*
-CommandType
Cmdlet,
function
: naming conversion is Verb
singular Noun example service, log, not services or logs.
Get-Command
-Verb
Get
-Noun
*serv*
Get-Command
-Verb
get
-Noun
proc*
Get-Command
-Verb
stop
-Noun
proc*
Get-Command
-Verb
stop
: cmdlet is a search word that is specific to powershell, can use something like bing to search for cmdlet and then the command.
HELP:
Use Get-Help command along with the Name of what you want help with.
Example:
Get-Help
-Name dir
:
if you dont like it that you have to scroll up you can use just the help command which pipes it to the more and you can then hit space bar to look at each screen:
Help
-Name dir
:you can use the help command or get-help command
with wild cards the difference is that help does not have a Verb or a Noun parameter its only searching on the name, and its just doing a string pattern match. Its also not searching for command names its searching for help file names. For the most
part its a one to one mapping meaning every command maps to a help file.
help
*service*
:there are some help files not about commands kind of like power shell user manual/help files for example:
help
about*
:once find the file you want you can run the following command
Get-Help
-Name about_Hash_Tables
:Now if PowerShell cannot find a help file it will search inside the actual files.
For example there is no file or cmdlet called breaking if you did help *breaking* it would search the files and pull up any files with that string in them.
:you could also have it pull it up if there was only one with that name by using the wild card
Get-Help
-Name about_H*
:If windows powershell cannot find a help file that has the string or word in it then it will check the content of the file for it here is an example using breaking which is not a file.
Get-Help
*breaking*
:If you want all the details then you can ask for full help
Get-Help
dir -Full (we talk about this later but notice we are doing positional parameter here where we left out the -Name)
:To get the most up to date information use the
-Online command which will open up web page straight to the internet.
Get-help
dir -Online
:First thing you see looking at the description below is that there is two parameter sets(I marked second one with yellow) Once you go down the path of one set then you cannot use parameters from
the other set.
You should note some of the following things.
If it has a minus sign in front of it then its a Parameter. Lets look at the Parameter [-LogName] you see <String> in brackets afterwords.
This is the value of the Parameter. Next look at [[-instanceId] <Int64[]>] you see that the Parameter and its value are surrounded with square brackets
this means its optional.
If you look at the first one you see that [LogName] <String> is not surrounded by brackets, so
its not optional.
SYNTAX
Get-EventLog [-LogName] <String> [[-InstanceId] <Int64[]>] [-After <DateTime>] [-AsBaseObject] [-Before <DateTime>] [-ComputerName
<String[]>] [-EntryType <String[]>] [-Index <Int32[]>] [-Message <String>] [-Newest <Int32>] [-Source <String[]>] [-UserName
<String[]>] [<CommonParameters>]
||||
Get-EventLog [-AsString] [-ComputerName <String[]>] [-List] [<CommonParameters>]
Now you might ask why is there brackets around the parameter [-LogName] This means the parameter is optional. This means you could type:
Get-EventLog
application -Newest
5
:See the
Value for the Parameter can be used instead of the parameter in a way abbreviating it, because the Parameter is optional when used in this way. These are called positional paramters you can see that [-LogName] is in the first position as is
its Value so when we put the Value in the first position PowerShell knows what we mean.
We have did this already with such things as
help
dir , which is a positional parameter.
If we typed it out fully it would be: Help
-Name dir
: If youre going to use positional parameters its up to you to get them in the right order.
What you cannot do is something like: Get-EventLog newest 5 Application Here you would be putting the logname value in the second position which is incorrect.
Best Practices is just to type out the full convention its not a lot of extra typing as you can use Tab completion to assist.
This brings up another important fact.
If you did something like Get-EventLog Sec and you tried to Tab complete you will not be able to, the reason being that the - only works with Parameters and you just tried to put it in front of a value.
So it can tell you when something is wrong as well.
Then what you can do is just fall back to the -, for example:
Get-EventLog -?
(see that I put a question mark there) it will then pull up the help so you can see the correct syntax so you can finish it correctly.
In PowerShell 3.0 and newer it does not ship with Help but you can update the help by typing in, you can use
-force to make it update sooner as it normally checks every 24 hours.
Update-Help
:If you ever need to get help on a computer not connected to the internet you run the command:
Save-Help
:This will download the file to a PC with internet then you can move those files to the computer without internet(via shared network folder or some
other means) and then when you run Update-Help, and specify an alternative
path using a parameter.
:Another really cool feature is the ability to use help and then popup a windows its cool because you can pop it up and then move it to the side as
its a floating window and so you can use it while you work, there is a bit of a bug where if it has a lengthy description only the first paragraph of the description will show up.
In that case go back to the power shell windows and review the paragraph if there was something in it that you needed.
This looks like it may have been fixed now in powershell 4.0, but just be aware as it was mentioned in the video.
help
-Name dir
-ShowWindow
:Something similar to the above is using the show-command see below:
Show-Command
-Name Get-EventLog
:This pops up a window that is gui based and you can actually see both parameter types. You would choose one, fill out the part you wanted then either
run or copy. If you copy it would paste to the powershell.
Also notice the following below [-List] there is no value listed for the parameter.
This means its a switch.
Its either there or its not, but it does not take a value.
Another thing notice on the [-ComputerName <String[]> those empty brackets
means it accepts multiple values.
Get-EventLog [-AsString] [-ComputerName <String[]>] [-List] [<CommonParameters>]
:An example of using multiple values is as follows, here we pull event logs from two different servers:
Get-EventLog
-LogName Security
-Newest 5
-ComputerName DM2,DM3
PS C:\Windows\system32> Get-EventLog -LogName Security -Newest 5 -ComputerName DC2,DM2
Index Time
EntryType Source
InstanceID Message
----- ----
--------- ------
---------- -------
3165081 Sep 13 22:04
SuccessA... Microsoft-Windows...
4634 An account was logged off....
3165080 Sep 13 22:04
SuccessA... Microsoft-Windows...
4624 An account was successfully logged on....
3165079 Sep 13 22:04
SuccessA... Microsoft-Windows...
4672 Special privileges assigned to new logon....
3165078 Sep 13 22:04
SuccessA... Microsoft-Windows...
4634 An account was logged off....
3165077 Sep 13 22:03
SuccessA... Microsoft-Windows...
4634 An account was logged off....
207663 Sep 13 22:02 SuccessA... Microsoft-Windows...
4634 An account was logged off....
207662 Sep 13 22:02 SuccessA... Microsoft-Windows...
4634 An account was logged off....
207661 Sep 13 22:02 SuccessA... Microsoft-Windows...
4624 An account was successfully logged on....
207660 Sep 13 22:02 SuccessA... Microsoft-Windows...
4672 Special privileges assigned to new logon....
207659 Sep 13 22:02 SuccessA... Microsoft-Windows...
4634 An account was logged off....
PS C:\Windows\system32>
: As you can see above it pulled 5 from each showing that you can pull from multiple values.