[Autogenerated] So let's talk about how we
execute the commands. Well, first off,
let's focus on the SIM session options. So
if we're going to create this session,
what does the session options provide us?
Well, first off, we can specify the
protocol. This will allow us to choose
either the D com option, the default
option or the WS man so we get to control
depending on our environment. We can also
set proxy authentication. So this will
specify the authentication method to use
for that resolution the acceptable values
for this parameter our default digest
Negotiate basic Kerberos anti l m domain
or credit SSP. We could also pass a proxy
credential. This will be the credentials
to use for that authentication. It can
either be a variable that contains API s
credential object or a command that gets
API s credential object such as get
credential. If this option is not set,
then you cannot specify any credentials.
And then, of course, our last one is to
use SSL. This will indicate the SSL should
be used to establish a connection to the
remote computer by default. SSL is not
used. Ws man will encrypt all the content
that is transmitted over the network even
when using HTTP, this parameter However,
let's you specify the additional
protection of HTTP s instead of HTTP If
SSL is not available on the port used for
the connection and you specify this
parameter, then the command will fail. It
is recommended by Microsoft that you use
this parameter only when the packet
privacy parameter is not specified. Okay,
so how do we create a SIM session with
options? Well, first off, I'm going to set
my SIM session and say, I'd like to use do
com So new sim session option protocol. Do
com. I could also change that and say New
SIM session option Ws man, or I could tie
all of this together and say Here are my
session properties So I can say, get my
credentials using get credential which
will prompt you then create the new SIM
session. Set my proxy authentication and
credentials skips, um certificate checks,
but tell it to use SSL. Now we have the
ability to combine SIM commands altogether
so we can execute in new SIM session to
initiate that session that we need to eat
the local machine or the remote we can,
then call get SIM session to retrieve that
created session. Then we can get the
specified Sim instantiate I using gets him
instantiate can see the hierarchy New SIM
session. Get the session, get the
instantiate we can, then execute the SIM
commands by using invoke SIM method. And
then we can retrieve the created SIM
session using get, and then we could
remove it at the end. So we have the
ability to kind of tie all of these
together. So let's have a look at an
example. This is quite a common one where
we can try and retrieve the remote desktop
configuration that's available on a
specified machine. So first off, I'm going
to say going specify a computer. It's
called Trainer. I'm gonna test the
connection to make sure it works. So what
we have here is the computer test.
Variable is going to test the connection
using standard PowerShell by using the
computer name and just make sure that
works. Then I'm going to validate that and
say, Well, if the computer test comes back
with the value, so it's true, then create
a brand new session. So new Sim session
name. This is the key. It's called
Terminal services and then we have the
computer name that I want to pass into.
And then, of course, you can see my
section that says code to execute. That's
where our code is going to go to run. So
that gives us the session, the name of the
session on the remote connection. So
what's our next step? Well, we can then
start to retrieve specific settings so you
can see of populated some variables. So
terminal service setting and terminal
service general setting I'm going to use
get the same session, and I'm using the
variable name of session which we created
previously on I'm getting the name of that
and then I'm piping that out, which we
know how PowerShell pipes the values out
to the sim instantiate cmdlet, which we've
used in the past to retrieve name space
and class values. So now I have two
variables populated. Then if we go to our
final piece, I'm then going to go ahead
and say I want to set some values. So I'm
going t are setting. I've got that value.
Now I'm gonna invoke a method that's going
to make some changes so you can see I'm
setting a method, which is called set
allowed TS connections. Now, as a side
note, we would need to know what those
method names were, so we'd have to query
that first before we did this. Then I'm
passing the arguments, which is allowed
terminal service connections and modify
the firewall to make it work. I'm then
going to set some general settings and say
user authentication is required, some
setting another value. At this point, I'm
then going to retrieve the session and
then close that session out so you can see
we can actually build quite easily. A
PowerShell script that creates the session
allows me to retrieve values, allows me to
set values and invoke methods, and then close.