在试图设计一个简化的脚本供office 365图形API使用时,我似乎无法从一开始就找到任何方法来调用它。
为了达到我的目的,我真的不想花时间来构建和编译一个实际的程序,因为其他的一切都可以通过powershell或批处理脚本来完成。
具体而言,我只希望能够调用组列表的图形API,并将结果存储在数组或文本文件中。可以从powershell或命令行调用图形API吗?如果可以,如何调用?
发布于 2016-05-11 02:13:40
具体而言,我只希望能够调用组列表的图形API,并将结果存储在数组或文本文件中。
如果您只需要导出一个组列表。我建议你使用Azure Active。
$msolcred = get-credential
connect-msolservice -credential $msolcred
Get-MsolGroup | Out-File C:\Workbench\temp\tests\export.txt
是否可以从powershell或命令行调用图形API ?如果可以,如何调用?
是的,可以调用REST:
首先,您需要获取访问令牌
然后,使用Invoke-RestMethod方法调用Graph。
Invoke-RestMethod -Uri $uri -Headers @{Authorization = "Bearer {your_access_token}"}
发布于 2019-02-22 21:12:19
您可以为此使用PSMSGRAPH模块。可以从画廊下载。
您必须在Azure中注册应用程序,以验证并将必要的权限委托给您的应用程序。您可以在appreg 门户上这样做。
一旦完成,您只需执行和运行您的请求。在运行代码时,必须提供授权凭据。
$username = 'entertheappidhere'
$password = 'entertheapppaswordhere' | ConvertTo-SecureString -AsPlainText -Force
$ClientCredential = New-Object -TypeName
System.Management.Automation.PSCredential($username,$password)
$GraphAppParams = @{}
$GraphAppParams.Add('Name','Office365TenantMigration')
$GraphAppParams.Add('ClientCredential',$ClientCredential)
$GraphAppParams.Add('RedirectUri','https://localhost/')
$GraphAppParams.Add('Tenant','yourtenant.onmicrosoft.com')
$GraphApp = New-GraphApplication @GraphAppParams
# This will prompt you to log in with your O365/Azure credentials.
$AuthCode = $GraphApp | Get-GraphOauthAuthorizationCode
$GraphAccessToken = $AuthCode | Get-GraphOauthAccessToken -Resource 'https://graph.microsoft.com/'
$GraphAccessToken | Export-GraphOAuthAccessToken -Path 'f:\O365Report\AccessToken.XML'
$GraphAccessToken = Import-GraphOAuthAccessToken -Path 'f:\O365Report\AccessToken.XML'
$GraphAccessToken | Update-GraphOAuthAccessToken -Force
### Run the query
Invoke-GraphRequest -Uri "https://graph.microsoft.com/v1.0/groups"-Method GET -AccessToken $GraphAccessToken
https://stackoverflow.com/questions/37147953
复制相似问题