1
00:00:00,240 --> 00:00:01,480
[Autogenerated] So let's talk about how we

2
00:00:01,480 --> 00:00:04,230
execute the commands. Well, first off,

3
00:00:04,230 --> 00:00:06,880
let's focus on the SIM session options. So

4
00:00:06,880 --> 00:00:08,240
if we're going to create this session,

5
00:00:08,240 --> 00:00:10,840
what does the session options provide us?

6
00:00:10,840 --> 00:00:12,780
Well, first off, we can specify the

7
00:00:12,780 --> 00:00:15,980
protocol. This will allow us to choose

8
00:00:15,980 --> 00:00:18,460
either the D com option, the default

9
00:00:18,460 --> 00:00:21,740
option or the WS man so we get to control

10
00:00:21,740 --> 00:00:24,520
depending on our environment. We can also

11
00:00:24,520 --> 00:00:26,770
set proxy authentication. So this will

12
00:00:26,770 --> 00:00:29,490
specify the authentication method to use

13
00:00:29,490 --> 00:00:31,900
for that resolution the acceptable values

14
00:00:31,900 --> 00:00:34,780
for this parameter our default digest

15
00:00:34,780 --> 00:00:38,610
Negotiate basic Kerberos anti l m domain

16
00:00:38,610 --> 00:00:42,510
or credit SSP. We could also pass a proxy

17
00:00:42,510 --> 00:00:44,430
credential. This will be the credentials

18
00:00:44,430 --> 00:00:47,530
to use for that authentication. It can

19
00:00:47,530 --> 00:00:50,070
either be a variable that contains API s

20
00:00:50,070 --> 00:00:53,430
credential object or a command that gets

21
00:00:53,430 --> 00:00:55,980
API s credential object such as get

22
00:00:55,980 --> 00:00:58,720
credential. If this option is not set,

23
00:00:58,720 --> 00:01:01,440
then you cannot specify any credentials.

24
00:01:01,440 --> 00:01:02,840
And then, of course, our last one is to

25
00:01:02,840 --> 00:01:06,020
use SSL. This will indicate the SSL should

26
00:01:06,020 --> 00:01:09,300
be used to establish a connection to the

27
00:01:09,300 --> 00:01:12,610
remote computer by default. SSL is not

28
00:01:12,610 --> 00:01:16,160
used. Ws man will encrypt all the content

29
00:01:16,160 --> 00:01:18,550
that is transmitted over the network even

30
00:01:18,550 --> 00:01:21,410
when using HTTP, this parameter However,

31
00:01:21,410 --> 00:01:23,760
let's you specify the additional

32
00:01:23,760 --> 00:01:27,350
protection of HTTP s instead of HTTP If

33
00:01:27,350 --> 00:01:29,860
SSL is not available on the port used for

34
00:01:29,860 --> 00:01:31,930
the connection and you specify this

35
00:01:31,930 --> 00:01:34,630
parameter, then the command will fail. It

36
00:01:34,630 --> 00:01:37,130
is recommended by Microsoft that you use

37
00:01:37,130 --> 00:01:38,950
this parameter only when the packet

38
00:01:38,950 --> 00:01:43,440
privacy parameter is not specified. Okay,

39
00:01:43,440 --> 00:01:45,620
so how do we create a SIM session with

40
00:01:45,620 --> 00:01:48,440
options? Well, first off, I'm going to set

41
00:01:48,440 --> 00:01:50,870
my SIM session and say, I'd like to use do

42
00:01:50,870 --> 00:01:54,770
com So new sim session option protocol. Do

43
00:01:54,770 --> 00:01:58,630
com. I could also change that and say New

44
00:01:58,630 --> 00:02:02,210
SIM session option Ws man, or I could tie

45
00:02:02,210 --> 00:02:06,280
all of this together and say Here are my

46
00:02:06,280 --> 00:02:08,800
session properties So I can say, get my

47
00:02:08,800 --> 00:02:10,700
credentials using get credential which

48
00:02:10,700 --> 00:02:13,060
will prompt you then create the new SIM

49
00:02:13,060 --> 00:02:15,540
session. Set my proxy authentication and

50
00:02:15,540 --> 00:02:18,320
credentials skips, um certificate checks,

51
00:02:18,320 --> 00:02:23,530
but tell it to use SSL. Now we have the

52
00:02:23,530 --> 00:02:27,540
ability to combine SIM commands altogether

53
00:02:27,540 --> 00:02:30,460
so we can execute in new SIM session to

54
00:02:30,460 --> 00:02:33,350
initiate that session that we need to eat

55
00:02:33,350 --> 00:02:36,130
the local machine or the remote we can,

56
00:02:36,130 --> 00:02:40,180
then call get SIM session to retrieve that

57
00:02:40,180 --> 00:02:44,070
created session. Then we can get the

58
00:02:44,070 --> 00:02:47,860
specified Sim instantiate I using gets him

59
00:02:47,860 --> 00:02:50,310
instantiate can see the hierarchy New SIM

60
00:02:50,310 --> 00:02:52,320
session. Get the session, get the

61
00:02:52,320 --> 00:02:54,910
instantiate we can, then execute the SIM

62
00:02:54,910 --> 00:02:58,840
commands by using invoke SIM method. And

63
00:02:58,840 --> 00:03:00,690
then we can retrieve the created SIM

64
00:03:00,690 --> 00:03:02,690
session using get, and then we could

65
00:03:02,690 --> 00:03:04,750
remove it at the end. So we have the

66
00:03:04,750 --> 00:03:07,010
ability to kind of tie all of these

67
00:03:07,010 --> 00:03:09,230
together. So let's have a look at an

68
00:03:09,230 --> 00:03:11,360
example. This is quite a common one where

69
00:03:11,360 --> 00:03:13,720
we can try and retrieve the remote desktop

70
00:03:13,720 --> 00:03:15,820
configuration that's available on a

71
00:03:15,820 --> 00:03:18,640
specified machine. So first off, I'm going

72
00:03:18,640 --> 00:03:21,260
to say going specify a computer. It's

73
00:03:21,260 --> 00:03:23,970
called Trainer. I'm gonna test the

74
00:03:23,970 --> 00:03:26,060
connection to make sure it works. So what

75
00:03:26,060 --> 00:03:28,080
we have here is the computer test.

76
00:03:28,080 --> 00:03:30,370
Variable is going to test the connection

77
00:03:30,370 --> 00:03:33,140
using standard PowerShell by using the

78
00:03:33,140 --> 00:03:35,170
computer name and just make sure that

79
00:03:35,170 --> 00:03:37,320
works. Then I'm going to validate that and

80
00:03:37,320 --> 00:03:39,580
say, Well, if the computer test comes back

81
00:03:39,580 --> 00:03:42,840
with the value, so it's true, then create

82
00:03:42,840 --> 00:03:45,390
a brand new session. So new Sim session

83
00:03:45,390 --> 00:03:47,600
name. This is the key. It's called

84
00:03:47,600 --> 00:03:49,640
Terminal services and then we have the

85
00:03:49,640 --> 00:03:51,780
computer name that I want to pass into.

86
00:03:51,780 --> 00:03:52,900
And then, of course, you can see my

87
00:03:52,900 --> 00:03:55,440
section that says code to execute. That's

88
00:03:55,440 --> 00:03:58,790
where our code is going to go to run. So

89
00:03:58,790 --> 00:04:01,660
that gives us the session, the name of the

90
00:04:01,660 --> 00:04:04,720
session on the remote connection. So

91
00:04:04,720 --> 00:04:07,090
what's our next step? Well, we can then

92
00:04:07,090 --> 00:04:10,190
start to retrieve specific settings so you

93
00:04:10,190 --> 00:04:12,760
can see of populated some variables. So

94
00:04:12,760 --> 00:04:14,340
terminal service setting and terminal

95
00:04:14,340 --> 00:04:16,530
service general setting I'm going to use

96
00:04:16,530 --> 00:04:18,990
get the same session, and I'm using the

97
00:04:18,990 --> 00:04:21,370
variable name of session which we created

98
00:04:21,370 --> 00:04:24,020
previously on I'm getting the name of that

99
00:04:24,020 --> 00:04:26,310
and then I'm piping that out, which we

100
00:04:26,310 --> 00:04:28,530
know how PowerShell pipes the values out

101
00:04:28,530 --> 00:04:30,940
to the sim instantiate cmdlet, which we've

102
00:04:30,940 --> 00:04:33,210
used in the past to retrieve name space

103
00:04:33,210 --> 00:04:36,080
and class values. So now I have two

104
00:04:36,080 --> 00:04:39,430
variables populated. Then if we go to our

105
00:04:39,430 --> 00:04:41,730
final piece, I'm then going to go ahead

106
00:04:41,730 --> 00:04:44,420
and say I want to set some values. So I'm

107
00:04:44,420 --> 00:04:47,340
going t are setting. I've got that value.

108
00:04:47,340 --> 00:04:49,820
Now I'm gonna invoke a method that's going

109
00:04:49,820 --> 00:04:52,410
to make some changes so you can see I'm

110
00:04:52,410 --> 00:04:54,550
setting a method, which is called set

111
00:04:54,550 --> 00:04:56,650
allowed TS connections. Now, as a side

112
00:04:56,650 --> 00:04:58,910
note, we would need to know what those

113
00:04:58,910 --> 00:05:00,850
method names were, so we'd have to query

114
00:05:00,850 --> 00:05:02,890
that first before we did this. Then I'm

115
00:05:02,890 --> 00:05:04,960
passing the arguments, which is allowed

116
00:05:04,960 --> 00:05:07,170
terminal service connections and modify

117
00:05:07,170 --> 00:05:10,060
the firewall to make it work. I'm then

118
00:05:10,060 --> 00:05:12,110
going to set some general settings and say

119
00:05:12,110 --> 00:05:14,110
user authentication is required, some

120
00:05:14,110 --> 00:05:18,040
setting another value. At this point, I'm

121
00:05:18,040 --> 00:05:20,260
then going to retrieve the session and

122
00:05:20,260 --> 00:05:22,940
then close that session out so you can see

123
00:05:22,940 --> 00:05:25,920
we can actually build quite easily. A

124
00:05:25,920 --> 00:05:28,280
PowerShell script that creates the session

125
00:05:28,280 --> 00:05:30,770
allows me to retrieve values, allows me to

126
00:05:30,770 --> 00:05:34,000
set values and invoke methods, and then close.

