[Autogenerated] So let's go back into our
environment on Well, first, look at how
we can modify Sim sessions using the
options once we've done that, well, then,
look at how we can executes SIM commands
now when connecting two remote computers
to run the SIM commands. There's obviously
as you've talked about two different
types, one is a temporary session and then
one would be a more permanent session that
we would actually have to close ourself.
So the first thing I want to do is just
create a new variable that we've used
before on. We'll call this local host,
which is just the machine that I'm on. And
then what I'm going to do is do sim
instantiate. Well, actually, what going to
do first is I'm going to say, get sim
session on, then you'll see I have some
sessions here. So what I'm gonna do is a
SIM session sim session, and then I'm
going to say one No, notice what happens.
It doesn't let me delete a SIM session by
using the number. If I do sim or we can
say one, you could see it errors every
single time. So in order for us to clear
the sessions. So if I do get same session,
here is a list. Um, all I need to know
what that same session is so that I could
get rid of it. So if I do, I'm gonna call
it session equals get sim session. And
then, of course, you've got IDE and I can.
Say one, then I can say remove sim session
and apps, not server name. I want it to be
sim Session and I can say session. Okay,
so now if I just look back notice I have
to So I can repeat the same process and,
you know, go through and get the session
I can Then remove the session I can then
go back and get three. And then I could
move this session, and then this time I'm
gonna get against extension and have
nothing. Okay, so we clear. Okay, So let
me go back and create my variable again.
Local host. And now what I want to do is
use the get sim instance command, so I
don't want to create a specific session. I
just want to create an instance. So I'm
going to say computer name and we'll use
my computer if use this command multiple
times And this time my name space. I'm
gonna do a bit of a longer name space. So
Sim, Version two, Terminal services. And
then I'll do class name and we'll do win
32 terminal services setting. Okay, So
going to press center. That gives me all
the information back. Now, what did that
just do? Well, let me do get same session.
There's no session, is there? Nothing
exists because the gets him session
literally just created a temporary session
for the purpose of returning the data on,
then deleted that session. It doesn't keep
that session around now. That doesn't
really help me if I want to make
adjustments to values. So if I connect to
the session or at least use gets, um
instance, it's not going to make any
adjustments because I have no session to
utilize. So what we can do is I'm going to
create another variable here. We'll call
it session name and I'll call it training
session. So I have my computer name
already, and I have my session name. Now
I'm going to say session equals new sim
session. The name for that will be my
session name and then my computer will be
the computer. Now, what does that look
like? If I do get same session, you'll see
it. The session there exists. You notice
the protocol is not decommitted to be s
man. So we have remote connection. So if I
clear that and then just type session,
you'll see it brings back that one too. So
I now have a persisted session or one that
I can execute. That means if I wanted to
say, get same instantiate class, well,
you'll see that we've got okay, let me do
class name win 32 process and then you'll
see you saw that one that was there. I can
then say session and it will go ahead and
bring with that. Let's just go back and
look at this. So I told it to retrieve all
of the processes using that specific class
name. Get me the instances off it. And I
passed the existing session. So this means
that if we're trying to write something,
for example, that's going to execute
against multiple machines, then we can
create sessions on those machines and then
call back into them as we needed then, of
course, one of the things that we can do
so I'm gonna say get Sim session. This
will give you my i D number and then
we can obviously remove the same session.
Now, I already have this one listed here,
So I can say session boom. And if I now do
session, there's nothing there. So those
sessions will hang around until you've
kind of completed. What? The task that
you're trying to kind of run. Now what we
can do is we can actually modify the
session itself. So I'm going to clear that
down on we're going to change the actual
session itself. So, firstly, if I do new
SIM session option and just say a protocol
I can do decomp and enter that now you're
C gives me some values packet, privacy,
packet integrity impersonate etcetera.
Now, what that means is that when I create
that session that's connected to that
session option, it will adopt those that
are there. So if I say new same session,
let me go computer name, dollar computer
and do that. Mm. Wait a minute. This one
connected as ws man, but didn't utilize my
sim session option. So let me clear that
and let me go back to here and loop
through the various values that we have
available to us, and you'll see we have
something called session option. So when
we're defining these, I'm gonna say
options, new SIM session option protocol.
And I'm going to say decomp Now I'm gonna
do my new session session options options
and enter now we can see the difference.
So if I do get SIM session, you can see
there's two. There's the first one that
was the default, which is going to default
to do Bs man, based on the fact that I
passed a computer name but actually with a
SIM session option I can change that and
say, Even though I'm passing a computer
name, I would like you to use a different
protocol to get to it. These key here is
that we have to populate that session
option to make that work, So using the
session options allows me to kind of craft
how I want that session to actually
function. Now. Of course, what we can do
is combine all of this together so we can
go ahead and say, Well, let's retrieve a
value. Let's update a value and then, you
know, let's set a value if needed and this
ties all of those commands together. So,
as an example, we already have the
computer name on Let's say we wanted to
retrieve specific settings. So what I'm
gonna do here is create a new variable.
I'm going to call it terminal service
Settings on. We'll say, gets in session
and then I'm going to say Go and get me
one of those existing sessions. Now, if I
don't have a session, then I can say new
same session and I could give it a name at
this point if I wanted to. So I'm gonna
call this one ts setting, and then I'm
going to do a pipe out of here and say,
Get see him instantiate because remember
that the beauty of PowerShell is that
we can kind of combine these all together.
So I'm gonna say name space on. We'll call
it Route Sim version two slash terminal
services. Then we'll do class name and
we'll say, win 32 terminal services
setting like so. Okay, what does that look
like? Well, let's hope it's got the right
value that we're looking for. And sure
enough, it brings me all the values that
I'm expect him so that command allows me
to initiate a new session with a name. So
if I actually say get sim session, you
should see my tear setting One is listed
here. No, that's great. So let's repeat
that process a little bit and we'll say,
general setting. And I'm going to say new
SIM session because I'm not retrieving
one. I'm gonna call it a name and we'll
say ts general setting like so what I'll
now do is pipe that value out and say, Get
Sim. I'm in capital letters there. Get Sim
instantiate. And then, of course, I can
pass name space and I'm going to do the
same as before. So Route Sim version two
slash terminal services and class name Win
32. T s general setting apps. I have a
plus there. That's not what I wanted.
Like, So So now I should have they would
go the general settings in there. Okay,
It's always good to leave. The are is in
there saying kind of see, I obviously
typed the plus sign when it should have
been nothing. So that gives me my details
that I'm looking for now. Of course, when
we combine all of this together. The
beauty that we have is we have a tear
setting, which is all of the values or the
properties that we could change, Which
means that I can then pass that into the
invoke method itself. So I can say sim
method. And then I would need to know what
the method name would be. So in this one,
it's called Allow t s connections. And
then I'm going to pass. Arguments may
remember arguments are passed inside the
at with scroll your brackets. So I'll say
hello. T s connections equals one. Modify
firewall. Exceptions equals one. So let's
just look at the command for a second. So
I have the terminal service settings that
I retrieved in the past and now being
passed into the invoke method, which is
very much like the previous invoke methods
that we looked at, which is then going to
execute a specific method which is called
Settle Out es connections. And I'm going
to pass arguments to it to then do
something at this point. I can Then pipe
all of that back out. So I can say format
table. I'm gonna say property PS, computer
name, return value and I'll auto size that
impress center now. Of course, What you
can see here is I'm obviously using a
parameter that probably isn't the right
name. I think I've got a s on the end, so
let me just get rid of that. And this is
why you should type all this out first.
There we do. Okay, So it went in, it made
adjustment and returned a value of zero,
which is perfectly fine. I already have
this configuration in. And I could repeat
that process again. That would say Go and
get me the general settings as well. Now,
of course, what we're left with after
running all of this together is a bunch of
sessions. Now, if we dict created the one
session, we could have literally used
session .NET name and it would have
rendered the training session one on. I
could have reused that session over and
over and over again because I didn't do
that. I'm no left with multiple sessions.
So to remove those sessions. So if I say
remove sim session if I loop, I've got
same session Computer name I can say local
host gets him session and they've all
gone. So that was one that I hadn't showed
GUI are is the ability to remove all
sessions by computer name in one sweep. So
that kind of shows you how to modify
existing sessions, how to connect to the
to the machines, using different types of
sessions to create remote sessions and then, of course, to execute commands.