Struggle with how to use PowerShell?
Not sure how to get it set up so it's optimized for you?
I'm going to show you how to get it up
and running in Server 2022.coming up now.
Hello, everybody.
Welcome back.
My name is Adam Gordon, an edutainer here at ITProTV,
coming at you with another interesting episode
for how you can optimize your server 2019 2022
and your server 2016 computing experience.
As we take a look at different options and different ways
in which you can utilize the server platform,
we're focusing on common tasks.
Things that you're probably going to need to do,
or may see other people do
but aren't quite sure exactly what the steps are.
Well, I'm going to walk you through them
and clarify how easy it is.
In this episode, we're going to take a look
at how to set PowerShell up
so that you can be really not only functional with it,
but you can do all sorts of cool stuff,
automate a bunch of things,
and of course, leverage PowerShell
to do day-to-day administrative tasks.
Join me here, if you will.
We're going to take a look
at how to do this on server 2022.
Server 2022 is recently released and made available.
And all of the things that we look at
across this entire series can be done in Server 2016,
server 2019, and or server 2022.
All those things that we talked about
are done the same way, found in the same place,
and of course, ultimately allow you to be productive,
regardless of the operating system platform you run.
So I'm running the latest version of 2022
as a Windows Server VM.
I'm just running as a virtual machine
that way you have an environment
we can play around with, we can demonstrate it.
I'm going to open a PowerShell
or to take a look at two different ways
that you could optimize PowerShell for day-to-day use.
The first one really centers around the built in version
or versions of PowerShell that ship with server.
And we're going to have a standard version,
a command line version we can use.
Let's have a graphical editor something known as ISE,
integrated services environment editor.
We're not going to spend time on that,
but it's there and at least you want to be aware of the fact
that all the commands I'm about to show you
work the same way whichever version
of PowerShell you want to use.
We're going to take a look
at how you can update the help files for PowerShell,
making sure it's got the latest information
to be of assistance to you.
How you can figure out
what version of PowerShell you're running
to make sure you have the latest version.
Microsoft's good about telling you
when there's an update available.
We'll point out where that is.
And how you can modify the execution policy.
The policy that controls what kind of content
can be run in PowerShell,
to make sure you're allowed to run scripts
and content you may download from the Internet,
or perhaps block it depending on what you want to do.
And then secondly, we'll take a look
at how you could install a late version,
latest in many cases version of PowerShell.
In this case, PowerShell Core,
where are you going to download it, how you install it,
and then from there, you can just follow the same steps,
we're going to talk about, about updating it
and modifying the execution policy.
I'm going to go to the Start menu in order to show you
where PowerShell typically can be found.
More often than not, it will be pinned in
or on the Windows Server area here on the start menu
as one or more of the tiles that are available to you.
See I'm highlighting the command line version
of PowerShell that's there.
And the graphical interface,
the Windows PowerShell ISE editor is just off to the right.
Now, we can use one of these shortcuts
to launch PowerShell just by either clicking on it,
or in this case, right clicking.
And more often than not,
you want to choose Run as Administrator
because you want to have the capability
to be able to do a variety of things in PowerShell
that may require administrative command access
in order to execute them,
updating help, modifying the execution policy.
For instance, I would require you to have administrative access
and if you don't, the commands may fail.
And you're going to have to restart the session.
So it's easier to start as an administrator.
And I'll point out how we know that you're running
as an administrator when we take a look up.
But if you have to go look for PowerShell.
Maybe for some reason it's not here,
or you haven't pinned it down on your taskbar
or anything like that,
you can find it up under the menu right here
where it's installed Windows PowerShell.
And you could just open that up.
And you'll see that the different versions of PowerShell
are available to you here as well.
So you can easily access them, wherever you are.
I'm going to right click on Windows PowerShell,
Run as Administrator as I suggested we should.
And I've already done that.
So I have it open.
And you'll notice right up here at the top of the window,
it says Administrator: Windows PowerShell.
It's how I can tell that it's running
under the administrative credential.
So always make sure you check
if you're not sure if it was or was not started with
an administrative credential.
Now I talked about the fact
that Microsoft does a good job of telling us
if there may be an update available.
And you can see right here as we run PowerShell,
this is a newer feature.
Microsoft's been doing this
for several generations of PowerShell
where they post a message
based on the version you're currently running and say,
“Hey, there may be a new version available,
check it out by going to this URL.”
And you can see it's an alias URL aka.ms,
for also known as Microsoft,
and then it is got the alias for PS windows
or PowerShell windows.
And you can go there, and then you could see
what the latest version of Windows PowerShell
that may be available for download from the website
from the GitHub repository is.
But here's the challenge.
How do you know what version
of PowerShell you're currently running,
and whether that new version is the right one for you?
Well, I told you, I'd show you how to find
what version of PowerShell you're running.
And you could see the first command,
which is actually variable that I've typed in.
Right here is $PSversionTable.
Now, $ in PowerShell,
indicates that whatever comes after the $ is a variable.
And so PSVersionTable is a variable,
$PSVersionTable is the name of how,
or rather is the way in which we call that variable by its name.
And what that variable does, it's a system variable,
it's built in and it's declared by Microsoft,
as part of the installation of PowerShell.
You, in other words, don't have to set up that variable.
It's already there for you.
And what that variable does is it contains the information
about the current version of PowerShell, current edition,
and the compatibility for the version
we're running with other versions of PowerShell.
As you can see on the screen right here,
I'm currently running PSVersion
for PowerShell version 5.1.20348.202.
We really just want to know
it's running PowerShell version five something.
And that's the built in version and server,
but it is an older version,
compared to the newest versions of PowerShell,
what we called PowerShell Core,
which are 7.- something, currently version 7x.
And so just by doing this, $PSVersionTable,
I can see that yeah,
I'm a couple of versions off the most recent one
and I probably do want to take advantage
of installing a new version.
I'm going to show you how we do that
by grabbing a download from that URL
in just a couple of minutes.
But before we do that, let's take a look
at the execution policy that I mentioned.
What we are allowed to do
in terms of running code within PowerShell
is controlled by the execution policy.
We want to take a look,
make sure we know how to deal with that.
I'm going to show you how to change it if you want to.
I also want to show you how to update help,
so we have the latest version of help in PowerShell.
And then we'll download the new version
and you'll be able to see how that goes.
So when we want to check
the current version of the execution policy,
whatever that may be,
we can use the Get-executionPolicy commandlet.
Get implies we want information back from the system.
And the execution policy is what we're looking for,
the status of it, in this case.
And it shows right there
that it's currently set to RemoteSigned.
Now you may or may not be familiar
with the different options
associated with the execution policy.
I'm going to show you the help page,
documentation page for it in just a minute.
There's about five or six different options we can use
in order to modify or change this.
But this is the default, RemoteSigned.
The default execution policy for a Windows system
and we are running in Windows on server 2022.
So this is what we would expect to see
when PowerShell is installed
and configured based on its default parameters.
And we have not used another commandlet,
which is the Set-executionPolicy commandlet
in order to modify from RemoteSigned
and change it to one or more of the options
that we're about to take a look at.
And we may very well want to change
from RemoteSigned onto or into a different additional
and take the place of that execution policy
with a different one, and even ones that are listed right here.
Because we may want to modify our ability
to run code that is downloaded from the internet
or code that we get from other places.
And you could see all of our different options there.
The default standing best practices,
you should leave RemoteSigned in place
if you're running a Windows system,
unless you have a reason to modify it.
It's designed to secure your system by requiring,
as it says right there that all scripts
and configuration files downloaded from the internet
must be signed by a trusted publisher.
This is I mentioned is the default way
in which Windows is set up.
Unrestricted, which means that essentially
we apply no restrictions at all,
would be the default for a non-Windows computer.
If you're running PowerShell, for instance, in Linux,
you would be able to see and know that we by default
have an unrestricted solution.
So it varies by operating system.
But you do want to be aware of that.
If you do want to change it,
and we'll just take a look at the options here really quickly,
kind of zoom in.
AllSigned, Bypass, Default.
Default would be our ability
to be able to use RemoteSigned as you can see.
And you can see RemoteSign, Restricted,
Undefined or Unrestricted.
So I have a bunch of different options.
If you do want to set this policy,
and we'll take a look at it up here.
I'm just going to show you the top of the page.
All you do is just look for the Help file
by typing in the name of the command that you want to find.
And you can browse for it on the internet.
You can also look at the help file directly in PowerShell,
as well if you want to.
But set execution policy, as you can see,
is really nothing more than simply saying
set execution policy,
the name of the commandlet, execution policy,
which is the parameter that we are looking to use,
and then the value in this case,
what do I want to set it to.
RemoteSigned is the default,
maybe I want to change it to Unrestricted.
So I would simply go and grab this line of code right here
and I'll just change out RemoteSigned for Unrestricted.
And I can either go ahead and reproduce it
or I can simply just paste it right in there
the way I just did.
And instead of RemoteSigned,
I can put in on unrestricted, if I spell correctly.
And you'll see it then says,
“Hey, are you sure you want to change that?”
And this is expected behavior.
It's prompting us to confirm
that we are happy with our decision.
And we really mean to do that.
And notice [Y] is Yes, [A] is Yes to All,
[N] is No, highlighted, right?
Potentially, so we know that we can make an option change
and get out of this without executing it if we choose to.
[L] for No to All, [S] for Suspend.
And we're able to look for help.
And notice the default is [N] maybe Microsoft assumes
we do not want to make this change
unless we tell them that we do.
We're going to type yes.
We're going to go ahead and do that.
Nothing comes back, but then,
if I do a Get-execution Policy one more time,
you'll notice it's been changed to Unrestricted.
So it's very simple to do that.
We just need to understand how that would work.
And again, you need to get into PowerShell,
really understand the syntax
and how it allows you to be able to do a variety of things
using a specific set of language parameters.
A little bit beyond the scope of what we're talking about
in this particular episode, but certainly worth your time
if you want to think about
automating a variety of day to day,
and also complex administrative functions
in your Windows environment.
All right.
I did mention that I also would show you
how to update your help file.
Let me just do this by first just clearing my screen.
CLS will clear the screen
and give us a nice area to work with.
And what I'm going to do is type in update-help.
And when I do that, I have to wait a moment,
be patient with it.
It's thinking.
You have to be connected
to the internet for this to work, by the way.
And you'll see if there is an update
or updates that may be available,
Microsoft is just going to make it easy for us.
PowerShell is going to go out
and download those for us automatically.
We don't have to do anything.
All we have to do is stand back,
keep our hands off the keyboard.
Make sure nothing gets in the way of that happening.
It may take a 30 seconds, a minute, 2, 3, 4 minutes,
who knows how long.It really depends number one,
on the number of updates that are available.
And you see we're downloading and installing as we go.
So some of these things are quick,
some take a little longer.
It depends on the last time I did update the help file,
and therefore how many updates may be out there and pending.
And it could, as I said, take several minutes.
We're going to let this run, while it's doing its things.
We're not quite sure exactly how long it will take.
But we know it's in process.
When we're done,
we'll be able to come back and see that it's finished.
So we're just going to minimize that while that's running.
What I want to do is show you where we can go
to download new versions of PowerShell.
That URL that was in PowerShell that said,
“Hey, you have some updates available, go take a look,"
takes you out to GitHub, which is the repository
where Microsoft stores their downloadable versions
of PowerShell these days.
And it takes us right here.
And if we scroll down,
we can see we have a little bit of documentation
about PowerShell and PowerShell versioning.
And we can get the newest version of PowerShell
by simply looking here for our supported platform.
Runs in both Windows and a variety of different versions
or distributions of Linux, note x64, x86.
So depending on the version of Windows you're running,
and the operating system version,
you have the right version to download.
And we can run the most recent cutting edge versions as previews.
We could download a stable version
or a long term servicing and stable version
depending on what we want.
We grab the .msi or the equivalent file
for the Linux distribution, we need.
The.deb, and or the .rpm package.
And then we simply just go about executing and installing.
Now, I've done that already.
And I have that right here.
And what we're going to do is just go ahead,
and we're going to install that.
I'm just going to right click and choose Install.
And you'll see it sets up
or brings up the PowerShell installation wizard
for PowerShell seven,
that's our new PowerShell kind of figure, right.
Our icon and or our little Microsoft graphic, I guess,
that they've created as a character that represents PowerShell.
And we're going to go ahead
and just accept the defaults for installation.
Notice we do have some options there
about whether we want to see PowerShell
added to our environment variable path.
Or do we want to register it
so we can look at event logging.
Enableremoting for PowerShell.
You may or may not want to do that
unless you understand what it does.
Allowing PowerShell to connect to other machines
and other machines to connect to this machine
to execute code remotely.
May or may not be a good idea.
Can open up and add and open here, menu items
so as you right click on something, you can open it,
command line for PowerShell right there as you browse.
And you can also run it,
as you can see all from the context menu.
So we'll go ahead and we'll add these in.
We won't enable remoting.
We'll click Next.
We'll go ahead and we'll Install.
It takes just a couple of minutes to install and to configure.
While that's running just before it finishes,
let's go ahead and check.
Looks like our help update is just about done.
It is done, but notice the red text on the screen.
This is usually the one thing
you don't want to see in PowerShell.
But it's not as bad as it could be.
What it actually implies is that help was updated,
but if we read carefully,
it says that while we're able to update help,
it failed to update help for one or more modules
and lists some modules.
And that's because those modules
may or may not be installed,
they may or may not have an update,
they may or may not be configured properly.
But everything else was updated properly.
So we're actually fine with that.
And that's no problem.
And that means that we're good.
So that update for help went well.
We could see PowerShell.
The new version PowerShell seven for PowerShell Core
is completely installed.
Notice we can launch PowerShell right down there
if we choose to and or we can go find it
just by clicking Finish unlaunching
or not launching till we're ready.
And when we go find it,
we'll see it's on the start menu right up there.
Again, recommend that you choose to run
as administrator, as you can see right there.
We try that one more time,
but be focused over here when we do that.
There we go.
You can see, Run as administrator.
And when I open this up,
notice it's a different version of PowerShell.
It's got a black background as opposed to blue.
Notice it is still running as administrator.
But notice it says PowerShell 7 (x64) on the top.
Let's just change the font size on that
so you could see that a little bit more clearly.
While we're taking a look make that as big
as the other version, we were just running.
And I left the other version of PowerShell open.
We can see right there
that I have two versions of PowerShell.
Older, newer, and I can run commands in one or both.
But the newest version of PowerShell
supports some new commands and opportunities,
functions, things like that,
that the older version of PowerShell may or may not.
But the new version of PowerShell
will support all the commandlets
that are available in the old ones.
So the good news is as we go forward,
and we upgrade, we get the same capabilities,
but we tend to add more.
And we leave those versions of PowerShell installed.
So we don't uninstall the old version,
because it still may be valuable.
And whatever we do in the new version
is actually not going to be reproduced in the old version.
These are now individual programs running on their own.
And each version of PowerShell
can be used side by side if you want to
because they're isolated from each other.
And that as a result means that whatever you do in one,
really has no knowledge or have effect on
or impact on the other.
So it makes it very easy to be able to do multiple things
with multiple versions if necessary.
So this is just a high level overview.
Some of the key things we could do to be able
to go ahead and update,
to be able to go ahead and check the version,
to be able to go ahead and have the latest help file,
as well as the execution policy set for PowerShell.
There's a lot more you want to know, but guess what?
You can always check us out over at ITProTV
to take advantage of our not only courses on PowerShell,
but our courses across all sorts of technologies.
Microsoft, as well as Cisco, VMware
and all sorts of additional technologies
that you are probably looking to learn more about.
For now we're going to call this particular episode done.
I'm going to wish you happy Windows Servering
and I'll see you soon.