Microsoft Graph | Powershell Script from Scratch

Concepts Work
5 Dec 202021:42

Summary

TLDRThis video tutorial guides viewers through writing a script from scratch to query Microsoft Graph using the client credential flow. It covers registering an app in Azure AD, granting necessary permissions, obtaining an access token, and making API calls to fetch user and device information.

Takeaways

  • πŸ˜€ The video series focuses on Microsoft Graph and scripting to query it.
  • πŸ”‘ To access Microsoft Graph, you need an application registered in Azure Active Directory.
  • πŸ“ The script is being written to query Microsoft Graph using the client credential flow, which requires no user interaction.
  • πŸ‘€ The video demonstrates registering a new app in Azure AD and obtaining a client ID and client secret.
  • πŸ“Ž Understanding the OAuth client credential flow is a prerequisite for the script.
  • πŸ‘€ The script requests permissions from Microsoft Graph, specifically 'User.Read.All' for accessing user information.
  • πŸ”— The token endpoint for OAuth is accessed using the well-known configuration of the tenant.
  • πŸ“š The script uses PowerShell to interact with Microsoft Graph, prompting the user for their tenant domain name.
  • πŸ”‘ The access token is obtained by sending a POST request to the token endpoint with client ID, client secret, and other required parameters.
  • πŸ”Ž The script queries Microsoft Graph to retrieve user information, demonstrating how to use the access token in the authorization header.
  • βš™οΈ Additional permissions may be required for accessing different resources, such as devices, and must be granted in the Azure portal.

Q & A

  • What is the first step in accessing Microsoft Graph?

    -The first step in accessing Microsoft Graph is to create an application in Azure Active Directory. This application will be used to authenticate and gain access to the protected information.

  • Why is client credential flow important in this context?

    -Client credential flow is important because it allows an application to authenticate and access resources without user interaction. This is crucial when writing scripts that need to query Microsoft Graph without user involvement.

  • What is the purpose of registering a new app in Azure Active Directory?

    -Registering a new app in Azure Active Directory is necessary to create an identity for the application that can be used to authenticate and request access to Microsoft Graph API.

  • What permissions are needed for the app to access user information in Microsoft Graph?

    -The app needs to have application permissions, specifically the 'User.Read.All' permission, to access user information in Microsoft Graph.

  • Why is it necessary to grant admin consent for the app?

    -Admin consent is necessary because the app is using application permissions, which require administrative approval to access the resources on behalf of the organization.

  • How can you find the token endpoint for Microsoft Graph?

    -You can find the token endpoint for Microsoft Graph by accessing the well-known configuration of your tenant, which can be found in the 'Endpoints' section of your app registration in Azure Active Directory.

  • What information is required to request an access token using client credential flow?

    -To request an access token using client credential flow, you need to provide the client ID, client secret, redirect URI, grant type (set to 'client_credentials'), and the resource URL (Microsoft Graph).

  • How does the script interact with the Microsoft Graph API to query user information?

    -The script uses a REST method to send a POST request to the token endpoint with the necessary credentials to obtain an access token. It then uses this token to make a GET request to the Microsoft Graph API endpoint to query user information.

  • What happens if the script tries to access device information without the necessary permissions?

    -If the script tries to access device information without the necessary permissions, it will receive an error indicating insufficient privileges.

  • How can you customize the script to display specific information from the Microsoft Graph API?

    -You can customize the script by using PowerShell cmdlets like 'Select' to choose specific properties from the returned data, or by using 'ConvertTo-JSON' to structure the data in a JSON format.

Outlines

00:00

πŸ“ Registering a New App in Azure AD

The video begins with the process of registering a new application in Azure Active Directory (AD) to access Microsoft Graph. The presenter demonstrates how to sign in as a global admin, navigate to Azure AD, and register a new app named 'craft script'. This involves selecting the 'Web' option and specifying 'localhost' as the redirect URI. The application is then registered, and the presenter emphasizes the importance of understanding the OAuth client credential flow, which is a prerequisite for accessing the Graph API. The client ID and client secret are generated and noted for use in the script.

05:02

πŸ”— Configuring API Permissions for the App

The presenter continues by explaining how to configure the newly registered app to access the Microsoft Graph API. This involves granting the app the necessary permissions, specifically the 'User.Read.All' permission, which allows the app to query user information without user interaction. The presenter also discusses the importance of granting admin consent for the tenant, which is required since there is no user interaction in this scenario. The video also covers how to find the token endpoint for the OAuth client credential flow by accessing the well-known configuration of the tenant.

10:04

πŸ’» Writing the Script to Access Microsoft Graph

The video script then shifts to writing a script from scratch to access Microsoft Graph. The presenter introduces the concept of defining a variable for the tenant domain and prompts the user to enter their domain name. The script is saved and run in PowerShell, demonstrating how the user input is captured. The script then uses REST methods to access the well-known configuration endpoint to determine the token endpoint. The presenter also explains how to display the token endpoint in the console and how to save this information for later use in the script.

15:06

πŸ”‘ Requesting an Access Token

The presenter proceeds to explain how to request an access token using the client credential flow. This involves constructing a body object with the client ID, client secret, redirect URI, and grant type set to 'client_credentials'. The resource is specified as 'graph.microsoft.com', and the tenant is included as an optional parameter. The script uses a REST method to post this information to the token endpoint, and the access token is displayed in the console. The presenter emphasizes the importance of entering the values correctly as expected by Azure AD.

20:08

πŸ”Ž Querying Microsoft Graph for User Information

With the access token obtained, the presenter demonstrates how to query Microsoft Graph for user information. This involves creating an API variable that invokes a REST method with the authorization header containing the access token. The script is then used to query the '/users' endpoint of Microsoft Graph. The presenter shows how to display the response in the console and how to customize the output by selecting specific properties such as 'userPrincipalName' and 'accountEnabled'. The video also covers how to handle errors related to insufficient privileges and how to grant the necessary permissions to access device information.

πŸš€ Finalizing the Script and Accessing Device Information

The final part of the video script focuses on finalizing the script and accessing device information through Microsoft Graph. The presenter explains how to refresh the permissions and re-run the script to access device information. The video concludes with a reminder that the script is a basic introduction to scripting and accessing Microsoft Graph API, and encourages viewers to explore more efficient methods and customize the script according to their needs. The presenter also invites viewers to ask questions in the comment section and promises to add more scripts and features in the community section.

Mindmap

Keywords

πŸ’‘Microsoft Graph

Microsoft Graph is a unified API endpoint that enables developers to access data from Microsoft 365, Azure AD, and other Microsoft services. In the video, it is the primary focus as the script is designed to query this API to access information. The script demonstrates how to authenticate and make requests to the Microsoft Graph API, which is crucial for accessing user and device data.

πŸ’‘Application

In the context of the video, an 'application' refers to a software entity that needs to be registered in Azure Active Directory to access Microsoft Graph. The video guides through the process of registering a new app, which is a prerequisite for obtaining the necessary permissions to interact with Microsoft Graph. The application ID and client secret are key components used in the script for authentication.

πŸ’‘Client Credential Flow

Client Credential Flow is an OAuth 2.0 authorization grant used by applications to access their own resources or resources on behalf of themselves, not on behalf of a user. The video explains the necessity of understanding this flow, as it is used to authenticate the script with Microsoft Graph without user interaction. The script uses this flow to obtain an access token.

πŸ’‘Azure Active Directory

Azure Active Directory (Azure AD) is a cloud-based identity and access management service that provides a central location for managing application access and security policies. In the video, Azure AD is where the new application is registered and permissions are granted to access Microsoft Graph. It plays a crucial role in managing the security and permissions for accessing Microsoft services.

πŸ’‘Application Permissions

Application permissions, in the context of Azure AD, are the permissions that an application requires to access resources. The video script explains how to grant these permissions to the registered application, specifically the 'User.Read.All' and 'Device.Read.All' permissions, which allow the script to query user and device information from Microsoft Graph.

πŸ’‘Token Endpoint

The token endpoint is a critical component in the OAuth 2.0 authorization framework. It is used to obtain access tokens. In the video, the script dynamically retrieves the token endpoint from the well-known configuration of the tenant. This endpoint is used to request an access token, which is essential for authenticating the script's requests to Microsoft Graph.

πŸ’‘Client ID

The client ID is a unique identifier for an application registered in Azure AD. It is used in the script to identify the application when making requests to the token endpoint. The video script emphasizes the importance of copying the client ID from the Azure AD application settings for use in the script.

πŸ’‘Client Secret

A client secret is a secret known only to the application and the authorization server. It is used in the script to authenticate the application during the client credential flow. The video script includes steps for creating a client secret and using it in the script to obtain an access token from Microsoft Graph.

πŸ’‘REST Method

REST (Representational State Transfer) methods are a set of standard HTTP methods used to perform actions on resources. In the video, the script uses REST methods, specifically the POST method, to send requests to the token endpoint and obtain an access token. Later, the GET method is used to query user and device information from Microsoft Graph.

πŸ’‘Authorization Header

The authorization header is part of the HTTP request header used to pass the access token to the server. In the video, the script sets the authorization header with the access token obtained from Microsoft Graph. This header is crucial for authenticating subsequent requests to access user and device data.

πŸ’‘PowerShell

PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and scripting language. In the video, PowerShell is used to write and execute the script that interacts with Microsoft Graph. The script demonstrates how to use PowerShell cmdlets for REST API calls and data manipulation.

Highlights

Introduction to a series on Microsoft Graph, focusing on writing a script to query Microsoft Graph.

The necessity of an application to access information protected by Microsoft Graph.

Demonstration of registering a new app in Azure Active Directory for script access.

Explanation of the prerequisites, including understanding the OAuth client credential flow.

Step-by-step guide to creating an application and obtaining a client ID and client secret.

Instructions on granting the application access to Microsoft Graph API using application permissions.

Discussion on the importance of client credential flow for non-interactive scripts.

How to access the token endpoint for OAuth client credential flow.

Using PowerShell to write a script that queries user information from Microsoft Graph.

Creating variables for tenant domain names and prompting users to enter their tenant name.

Initiating a REST method to reach the OpenID Connect well-known configuration endpoint.

Displaying the token endpoint on the console for user clarity.

Building the body object with client ID, client secret, redirect URI, and grant type for token request.

Invoking a REST method to request an access token from the token endpoint.

Displaying the access token received from Microsoft Graph API.

Querying Microsoft Graph API using the access token with proper authorization headers.

Selecting specific user information fields to display, such as user principal name and account enabled.

Handling errors related to insufficient privileges when querying devices in Microsoft Graph.

Granting additional permissions for device access and troubleshooting potential delays in permission propagation.

Final demonstration of querying device information from Microsoft Graph after granting necessary permissions.

Encouragement for viewers to ask questions and engage with the community for further learning.

Transcripts

play00:00

hi guys hope you all doing well welcome

play00:03

back to our series of Microsoft graph

play00:04

and in this video we are going to write

play00:07

a script from scratch that will be used

play00:10

to query Microsoft graph now the very

play00:14

first thing that you need to access any

play00:16

information that's being protected by

play00:18

Microsoft graph is an application ok so

play00:23

what I'm going to do is I'm going to

play00:24

switch to my browser where I have signed

play00:26

in as global admin and then I went to

play00:29

Azure Active Directory and now I have

play00:32

selected our precious creation and I'm

play00:35

going to register a brand new app let's

play00:38

say I'm going to access craft through a

play00:40

script so I'll name it as craft script

play00:43

ok I'm not going to make any change here

play00:46

here I will select web option itself and

play00:49

here I'm going to type HTTP and then

play00:53

let's say localhost that's all that's

play00:57

all I need as of now ok and I have

play01:00

clicked on it registered as if now an

play01:01

application is registered in my eyes

play01:03

your ad but still this application

play01:06

doesn't have the required permission to

play01:09

access graph API now there is a

play01:13

prerequisite which is must and that is

play01:16

you should know how Roth client

play01:18

credential flow works so if you have not

play01:21

seen that video by any chance please go

play01:24

ahead and watch that video because there

play01:26

are multiple things which I'm going to

play01:29

use as a reference in this video which I

play01:32

have already covered specifically the

play01:35

attributes or the values that needs to

play01:37

be present when your request is reaching

play01:40

a specific end point of your Asha area

play01:43

ok so as of now I have just created an

play01:47

application the next step is to copy

play01:51

this application ID because this is

play01:55

something which will which we will be

play01:58

using in our script ok so this is my

play01:59

client ID and then I'll create a client

play02:04

secret as well because again this is

play02:06

something which is required for client

play02:08

credential slow ware and there is no

play02:11

user interaction

play02:12

okay now welcome back to my console

play02:16

where we have access portal Roger comm

play02:19

and in this application what I'm going

play02:22

to do is I'm going to allow this

play02:24

application to access an API which will

play02:26

be Microsoft graph ok and let's assume

play02:30

we will use this script to query user

play02:33

information okay but since we are using

play02:36

client credential flow and there is no

play02:39

user interaction delegated permissions

play02:42

are not going to work so now what you

play02:44

need to do is you have to click on this

play02:46

option which says Microsoft graph and

play02:49

then click on application permissions

play02:51

and then scroll down and go to the user

play02:54

section and here give this permission

play02:58

which says user dot read all that's all

play03:01

you need to do ok now again since there

play03:05

will be no user interaction that means

play03:07

the consent prom will not be shown ok so

play03:11

the fact is that if consent is not shown

play03:13

then the required permission cannot be

play03:16

granted by any user that means as an add

play03:19

many you have to grant us permission for

play03:21

your tenant and that's exactly what I

play03:24

have done by clicking on this option

play03:26

which says grant Ardoin consent for

play03:28

concepts work now as of now the

play03:32

configuration that is required from

play03:33

Azure ad prospective as done that means

play03:36

I need a client ID and I need a client

play03:39

secret that's it but the fact is that if

play03:41

you guys remember when we have discussed

play03:44

about OAuth client credential flow there

play03:46

is a specific endpoint which is used and

play03:49

which is called

play03:50

the token endpoint ok and that can be

play03:53

accessed or you can check that

play03:55

information by going to well-known

play03:58

configuration of a tenant now how to

play04:00

access this particular endpoint just go

play04:03

to your application or go to that

play04:05

section from where you create

play04:07

application click on endpoints and then

play04:10

there will be an option of a well-known

play04:12

configuration for open ID Connect as you

play04:15

can see this is the link which I have

play04:17

opened here but this is we 1.0 now you

play04:21

can use we 1.0 end points or we 2.0

play04:25

endpoints as

play04:26

but honestly speaking using we 2.0

play04:29

endpoints here will not going to make

play04:31

any difference because since there is no

play04:33

consent so there is no fundamental of

play04:36

using an endpoint that uses incremental

play04:38

consent it's very simple but there will

play04:40

be no interaction that can be approved

play04:43

by your application and there is no user

play04:45

interaction so if you will use the v 1.0

play04:48

endpoints as well everything will be in

play04:50

place there will be no difference okay

play04:53

so now let's come back to our visual

play04:55

studio code where we will be writing our

play04:58

first script from scratch okay

play05:01

now let's say you're going to give the

play05:04

script to any of your customer or any of

play05:06

your team members as well and let's say

play05:08

you want to make the script available to

play05:11

anyone who can use this to just query

play05:14

the user information in that case you

play05:17

don't know who is going to access or who

play05:19

is going to use this particular script

play05:20

then what you can do you can just define

play05:22

a variable let's say tenant and you can

play05:25

prompt your user to enter their domain

play05:29

name okay so as of now what it will do

play05:32

it will ask the user to enter the tenant

play05:36

name that's all I have done I have

play05:38

declared a variable button I'm asking

play05:41

the user to enter their tenant name now

play05:44

this script is as of now saved in B

play05:47

script lab on my machine and the script

play05:49

name is graph so I'll go to my

play05:52

PowerShell and I will run the script to

play05:54

see what's exactly happening so this is

play05:57

my PowerShell console and I'm at the

play06:00

same location which is D script lab and

play06:03

now if I'll try to run this let's see

play06:06

what happens nothing is happening as of

play06:08

now because I hope it's not saved so I

play06:10

saved it again and now let's let me run

play06:13

this so as you can see as a user now I'm

play06:16

getting the prompt okay and the expected

play06:18

behavior is that this value will just

play06:20

get saved in this particular variable

play06:23

okay now since we need to know which

play06:27

endpoint we have to reach okay that

play06:30

means we have to access this particular

play06:33

end point from our script to know the

play06:36

token end point because that is

play06:38

something which will be

play06:39

used inclined credential flow but since

play06:42

the naming convention of this particular

play06:44

endpoint ends up with open ID so let's

play06:47

declare a variable and name it as open

play06:49

ID okay and then what we will do is

play06:52

we'll ask partial to initiate a rest

play06:55

method and reach this particular URI

play07:00

which is the open ID connect well-known

play07:04

configuration so if I'll copy the

play07:06

squally from here and I'll come back to

play07:09

my script let me save that value here

play07:12

and instead of concepts were calm what

play07:16

you should use use the value which the

play07:18

user has entered okay so this was pretty

play07:22

much simple that we have just declared a

play07:24

variable and this variable will be used

play07:27

to access a particular link and the

play07:31

value of tenant is the same value which

play07:34

the user will be entering okay now let's

play07:37

display this variable on the console and

play07:42

let's see what all we get okay

play07:44

so file again pre initiate the script

play07:48

and if all do concepts work.com let's

play07:52

see what happens perfect we are getting

play07:54

all the endpoint list but the fact is

play07:57

that this is the endpoint which we have

play08:00

to reach so now instead of displaying

play08:02

everything what will say just display

play08:06

the access token or sorry the token

play08:10

endpoint okay will again save this and

play08:14

now we're again the initiate our script

play08:17

and let's see perfect this is what we

play08:21

are getting okay to make it more

play08:23

interactive what you can do is you can

play08:26

display it like this let's say right -

play08:29

host the token endpoint of your

play08:38

directory yes and then this endpoint

play08:42

okay let's say concepts were calm the

play08:49

token point of directory is this one

play08:51

does not see even if I type

play08:53

Microsoft comm here it is going to work

play08:56

you see the squid value is getting

play08:58

changed so we have done the first step

play09:02

of just creating the endpoint that we

play09:05

have to reach that's all we have done as

play09:08

of now okay but we are going to use this

play09:11

value multiple times so let save this

play09:14

let's save this value as well - let's

play09:17

say token endpoint itself let's name it

play09:20

a new variable where we are requesting

play09:22

the access token and let's save this

play09:25

value here okay now if you guys remember

play09:30

when we were talking about OAuth client

play09:32

credential flow there is a specific set

play09:36

of information that should reach this

play09:38

endpoint which is the token endpoint and

play09:41

the artists client ID client secret

play09:43

redirect URI and then the grant type ask

play09:47

line credential because then only we are

play09:49

letting the azure ad know that we are

play09:51

using client credential flow today so

play09:54

now what we are going to do is we are

play09:55

going to declare an object let say body

play09:58

because this is going to include

play10:01

multiple set of information and in this

play10:04

I'm going to add my client ID and client

play10:08

ID is the same value which we have

play10:11

already copied from our ad okay and I'll

play10:15

paste that value here then the next

play10:20

thing that we need is client secret okay

play10:24

and that is also something which we have

play10:26

already copied so what I'll do is I'll

play10:29

name a new value here as client on the

play10:34

sword

play10:34

secret and then I will give my client

play10:39

secret value okay

play10:42

now there is a specific value which is

play10:47

required and that is redirect URI which

play10:50

we have already saved in our

play10:52

configuration so we will again declare

play10:55

the same value redirect URI and what it

play10:58

was STD PS localhost now the method that

play11:03

we are going to use is client credential

play11:05

so a new value which will be grant

play11:08

underscore type and then it will be

play11:12

client credential okay now make sure

play11:17

that you enter the values similarly as I

play11:22

am entering them right now or as I am

play11:25

typing them because everything is as a

play11:28

test that means it has to be used like

play11:30

this this is something which is defined

play11:33

or which as your IDI expects okay so

play11:36

don't customize these values you may end

play11:39

up a scenario where in your script might

play11:40

not work okay

play11:41

the resource that we will be accessing

play11:43

will be graphed okay so what I'll do is

play11:46

graph dot microsoft.com add this value

play11:50

which I'm going to mention now which is

play11:52

tenant is basically an optional value if

play11:56

you want you can mention it if you don't

play11:58

want it you should leave it so what I'm

play12:00

doing as of now I'm sending the same

play12:02

value which the user has entered okay as

play12:05

of now we know the endpoint we know the

play12:09

values which we have to send okay but

play12:12

the fact is that no token is requested

play12:15

okay so let's say to make it more

play12:17

interactive what I'm doing is right hos

play12:21

requesting access token okay requesting

play12:25

access token and the question comes how

play12:28

to request let's name it a new variable

play12:33

here and name it as a request and then

play12:37

let's ask this variable to invoke a rest

play12:41

method and reach URI which is what our

play12:46

token endpoint

play12:49

what's a dollar dot token and then in

play12:54

the body use all this information so use

play13:00

the body object and then in the method

play13:04

what you have to do is you have to post

play13:09

this information okay that means what

play13:13

this request value sorry this request

play13:17

variable will get some

play13:19

information right so let's write this

play13:22

request variable and the console and

play13:25

let's see what's happening now okay

play13:29

so I will do concepts were calm and as

play13:33

you can see I am getting access token

play13:36

again this is the section which is

play13:38

actually consisting the entire access

play13:41

token

play13:41

so now or I'll say just display the

play13:44

access token part save it clear the

play13:47

screen again run the script and let's

play13:51

see now what we are getting perfect so

play13:55

the token end point of your directory is

play13:57

this one and this is requesting access

play13:59

token this is the access token which we

play14:01

have received now see the agenda of this

play14:05

video is not to let you know how to

play14:07

write the most efficient script the

play14:10

agenda of this video is to let you know

play14:13

how to begin with scripting and how you

play14:16

can use a very small script and the

play14:19

easiest authentication method flow by

play14:22

using client credential to access

play14:24

Microsoft graph API many of you would

play14:28

already know ten thousand different ways

play14:31

to make it more efficient it's

play14:32

absolutely perfect please let me know in

play14:35

the comment section as well but this is

play14:37

exceptionally basic I'm trying to

play14:39

explain each and every line and what

play14:42

exactly I'm doing okay so as of now we

play14:45

have just requested the access token we

play14:48

know the token end point now the final

play14:50

step is to query graph okay now in this

play14:55

variable on going to add the end point

play14:58

which is moreover related for graph

play15:00

let's say graph dot microsoft.com

play15:02

forward slash meter endpoint and then

play15:05

reach users okay but the fact is that

play15:09

there should be some authorization that

play15:11

should be present that means this

play15:13

request that has to reach to this

play15:16

particular endpoint should have the

play15:19

authorization of the access token okay

play15:22

so now what I'm going to do is I'm going

play15:24

to make a new variable as API are in

play15:28

this API variable what I'm going to do

play15:30

is I'm going to invoke a rest method

play15:33

and in this rest method what should be

play15:37

present is the authorization header that

play15:41

should contain the access token okay so

play15:44

now I'm going to use a switch which is

play15:46

named as headers and inside this header

play15:49

I'm going to use a specific keyword

play15:52

called authorization and that what I'm

play15:55

saying that include a keyword named as

play15:58

be error and then include the value

play16:03

inside the token which we have received

play16:06

okay so what I'll do is I'll include

play16:10

that particular value by keeping it in

play16:13

braces and what we have to actually send

play16:16

is this particular access token okay so

play16:21

I'll copy this value here now the next

play16:24

thing is we know the URI where we have

play16:28

to reach so we'll you type URI

play16:30

and then we will say dollar graph okay

play16:35

this is where you have to go okay but

play16:38

still there is something missing and

play16:40

that is the last part where in which

play16:42

HTTP method I should use and that is get

play16:45

so what does this actually mean that get

play16:49

all the users from this particular

play16:52

endpoint by using this access token okay

play16:57

now the question comes that this

play16:59

variable will get something in response

play17:02

okay so let's display this particular

play17:04

variable on the console I have just

play17:08

saved my script I'll come back partial

play17:11

and I'll again initiate the same script

play17:15

and let's see what happens and as you

play17:20

can see I'm getting the value but again

play17:22

the entire details is in the value

play17:25

section so what I'll do is I'll say show

play17:28

me the values inside value okay I'll

play17:32

again initiate the same script concepts

play17:36

were calm and let's see what happens and

play17:39

as you can see I'm getting all the

play17:42

information now let's say I don't want

play17:44

all this information to be displayed

play17:46

so what I can do is I can say select

play17:49

let's say user principal name and let's

play17:55

say account enabled okay

play17:59

I'll save this and I'll again come back

play18:01

and I'll again be initiate my script

play18:04

let's say concepts were calm and let's

play18:07

see what happens

play18:08

perfect I'm getting much more organized

play18:11

information okay now not only this those

play18:16

who are super awesome with partial

play18:19

scripting they can use different methods

play18:21

likewise you can simply do convert - to

play18:23

JSON depending upon your requirement

play18:25

what kind of information you need how

play18:28

you want it to be structured now these

play18:31

are all different methods which are

play18:32

available with PowerShell so if you

play18:34

already have good knowledge of scripting

play18:36

you can do n number of customization in

play18:39

terms of the data that your script is

play18:41

getting back from this particular API

play18:43

these are some very small options which

play18:46

I'm trying to showcase you guys to query

play18:48

all the set of information now let's say

play18:51

we have discussed how to access users

play18:53

okay then you can do all the

play18:55

customization but let's say if now you

play18:57

try to access devices okay I have saved

play19:00

this let's see what happens and the most

play19:04

expected error is that I will get a

play19:07

prompt which will say n sufficient

play19:09

privileges but let's see what happens as

play19:11

you can see this is exactly what I'm

play19:13

getting okay so now if I'll go back to

play19:16

my portal okay and let's say I am

play19:21

granting this permission as well so I'll

play19:24

go to API permission section and then

play19:28

I'll click on add permission and again

play19:30

I'll click on Microsoft graph and then

play19:32

I'll click on application permission and

play19:35

I'll go to the devices section and let's

play19:38

see I'm giving this permission to device

play19:40

read all and then again click on this

play19:46

option which is grant admin consent

play19:48

click on yes wait for 20 30 seconds and

play19:51

then again the initiate your script if

play19:54

it is still giving you error and you

play19:56

have to just wait for a couple of

play19:58

minutes provided you have ground

play19:59

the right permission it should work so I

play20:03

again got the error let's wait for 10

play20:05

seconds or let's just give it one more

play20:07

try without waiting let's see what

play20:10

happens

play20:12

no it's still there's there is a lag

play20:14

let's go back here let's just refresh

play20:18

this permission and let's come back here

play20:22

in the screen draw concepts were calm

play20:28

and let's see perfect ok so you see this

play20:33

data which I'm getting is disorganized

play20:35

now the reason behind that is the

play20:38

devices object will not have these

play20:40

attributes right so I'll remove this

play20:43

I'll save this and I'll again come back

play20:46

clear screen again run the script

play20:49

concepts were calm that's it now I'm

play20:54

getting the device information ok so as

play20:57

we move along with this entire playlist

play20:59

I'll let you know different methods that

play21:01

you can use to access different kind of

play21:03

information through Microsoft graph ok

play21:09

so this was all about knowing how to

play21:12

begin what writing a script you know

play21:15

that you can use to access Microsoft

play21:16

graph API if you guys have any questions

play21:18

please feel free to ask me in the

play21:21

comment section and as we move along

play21:24

with this entire playlist whatever

play21:26

script I will be creating or I will be

play21:28

using to demonstrate any of the feature

play21:30

that is something that I'm going to add

play21:31

in the community section ok so if you

play21:34

guys have learned something new please

play21:36

let me know in the comment section thank

play21:39

you so much thanks for your time but

play21:40

what

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Microsoft GraphScriptingAPI AccessClient CredentialsOAuth FlowPowerShellUser QueryAzure ADAuthenticationREST API