1
00:00:00,240 --> 00:00:04,230
So to get started, let's talk about the PSCredential object,

2
00:00:04,230 --> 00:00:07,740
which is utilized for storing credentials.

3
00:00:07,740 --> 00:00:12,100
The PSCredential object represents a set of security credentials,

4
00:00:12,100 --> 00:00:14,300
so a username and a password.

5
00:00:14,300 --> 00:00:17,580
Now, to populate the PSCredential object,

6
00:00:17,580 --> 00:00:21,020
we obviously need to provide credentials and then the

7
00:00:21,020 --> 00:00:23,840
Credential object is populated.

8
00:00:23,840 --> 00:00:30,550
Once we have that object, it can be passed as a parameter into other commands.

9
00:00:30,550 --> 00:00:33,120
For example, if we wish to connect to a machine,

10
00:00:33,120 --> 00:00:38,240
we can pass the Credential object as part of that.

11
00:00:38,240 --> 00:00:40,920
Now, to create PSCredential objects,

12
00:00:40,920 --> 00:00:45,340
we can create it using what's referred to as the Get‑Credential cmdlet.

13
00:00:45,340 --> 00:00:46,670
Now, you may have seen this before.

14
00:00:46,670 --> 00:00:51,500
This is where we type Get‑Credential, and it prompts a Windows prompt,

15
00:00:51,500 --> 00:00:52,890
like a regular username,

16
00:00:52,890 --> 00:00:56,370
password Windows prompt that we can enter credentials into,

17
00:00:56,370 --> 00:01:01,340
and then that becomes the basis of the PSCredential object.

18
00:01:01,340 --> 00:01:05,280
The second option is to create a SecureString object.

19
00:01:05,280 --> 00:01:05,450
Now,

20
00:01:05,450 --> 00:01:08,640
what this means is we're basically passing in a kind of

21
00:01:08,640 --> 00:01:11,720
free text string value for the username,

22
00:01:11,720 --> 00:01:16,260
but for the password, we basically type a string text value,

23
00:01:16,260 --> 00:01:19,660
but convert that to a SecureString,

24
00:01:19,660 --> 00:01:23,740
so a different approach to the Get‑Credential.

25
00:01:23,740 --> 00:01:28,590
The last one is to actually just create a PSCredential object, which we can do.

26
00:01:28,590 --> 00:01:31,230
We can say New, PSCredential Object,

27
00:01:31,230 --> 00:01:35,500
and then pass in the various pieces that we need to construct the set of

28
00:01:35,500 --> 00:01:40,100
credentials that we wish to utilize going forward.

29
00:01:40,100 --> 00:01:44,220
Now, if we do this within PowerShell and using that Get‑Credential,

30
00:01:44,220 --> 00:01:49,100
if I wish to create some Globomantics kind of user credentials,

31
00:01:49,100 --> 00:01:51,780
I could create a variable called creds, or credentials,

32
00:01:51,780 --> 00:01:55,600
or whatever you wish to call it, and then just type Get‑Credential.

33
00:01:55,600 --> 00:01:59,640
Now, the difference here, when we just use Get‑Credential with no parameters,

34
00:01:59,640 --> 00:02:03,200
it will launch the Windows box with two empty boxes,

35
00:02:03,200 --> 00:02:06,440
so we'll get the username, and the password will be empty.

36
00:02:06,440 --> 00:02:06,780
Now,

37
00:02:06,780 --> 00:02:11,790
when we pass a Credential property, which will be DOMAIN\user, for example,

38
00:02:11,790 --> 00:02:15,860
then that username field is automatically populated for us.

39
00:02:15,860 --> 00:02:18,690
This is actually quite a common approach that used,

40
00:02:18,690 --> 00:02:22,060
for example, when you connect to Microsoft 365 or

41
00:02:22,060 --> 00:02:25,140
Azure Active Directory in the cloud.

42
00:02:25,140 --> 00:02:29,490
Now, we can create the PSCredential object from the two sets of values.

43
00:02:29,490 --> 00:02:31,730
So we could create a user property.

44
00:02:31,730 --> 00:02:35,450
So you can see, I've got a variable here called user, and it's DOMAIN\user,

45
00:02:35,450 --> 00:02:42,800
and then my password will be ConvertTo‑SecureString, which is the cmdlet

46
00:02:42,800 --> 00:02:47,620
that will change my password to a SecureString value, my password is just

47
00:02:47,620 --> 00:02:51,570
password in blue there, and then of course, as plain text, then I'm going

48
00:02:51,570 --> 00:02:57,490
to save that. To create the PSCredential object, we then create a new

49
00:02:57,490 --> 00:03:02,810
object, and the new object is a System.Management.Automation, and there we

50
00:03:02,810 --> 00:03:09,640
have it, PSCredential, and we pass in the $user and the $pwd as the option.

51
00:03:09,640 --> 00:03:13,550
We can also do it a little bit differently by using properties instead,

52
00:03:13,550 --> 00:03:17,210
so we could define the object with a specific type,

53
00:03:17,210 --> 00:03:21,270
which will still be System.Management.Automation.PSCredential, and

54
00:03:21,270 --> 00:03:29,000
then the argument list or the properties that we wish to send to it would be the $user and the $pwd.

