Skip to content

Commit 34ad10d

Browse files
authored
Merge pull request MicrosoftDocs#383 from MicrosoftDocs/authentication-docs
Auth Module
2 parents 7e97389 + 4177acf commit 34ad10d

19 files changed

+2375
-3
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
Param(
4+
$ModulesToGenerate = @(),
5+
[string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot ".\config\ModulesMapping.jsonc")
6+
)
7+
function Get-GraphMapping {
8+
$graphMapping = @{}
9+
$graphMapping.Add("v1.0", "graph-powershell-1.0")
10+
$graphMapping.Add("beta", "graph-powershell-beta")
11+
return $graphMapping
12+
}
13+
14+
function Remove-Invalid-NextLine {
15+
Param(
16+
$ModulesToGenerate = @()
17+
)
18+
19+
$ModulePrefix = "Microsoft.Graph"
20+
$GraphMapping = Get-GraphMapping
21+
$GraphMapping.Keys | ForEach-Object {
22+
$graphProfile = $_
23+
Get-FilesByProfile -GraphProfile $graphProfile -GraphProfilePath $GraphMapping[$graphProfile] -ModulePrefix $ModulePrefix -ModulesToGenerate $ModulesToGenerate
24+
}
25+
26+
}
27+
function Get-FilesByProfile{
28+
Param(
29+
[ValidateSet("beta", "v1.0")]
30+
[string] $GraphProfile = "v1.0",
31+
[ValidateNotNullOrEmpty()]
32+
[string] $GraphProfilePath = "graph-powershell-1.0",
33+
[ValidateNotNullOrEmpty()]
34+
[string] $ModulePrefix = "Microsoft.Graph",
35+
[ValidateNotNullOrEmpty()]
36+
$ModulesToGenerate = @()
37+
)
38+
39+
$ModulesToGenerate | ForEach-Object {
40+
$ModuleName = $_
41+
Get-Files -GraphProfile $GraphProfile -GraphProfilePath $GraphProfilePath -Module $ModuleName -ModulePrefix $ModulePrefix
42+
}
43+
44+
}
45+
function Get-Files{
46+
param(
47+
[ValidateSet("beta", "v1.0")]
48+
[string] $GraphProfile = "v1.0",
49+
[ValidateNotNullOrEmpty()]
50+
[string] $GraphProfilePath = "graph-powershell-1.0",
51+
[ValidateNotNullOrEmpty()]
52+
[string] $Module = "Users",
53+
[ValidateNotNullOrEmpty()]
54+
[string] $ModulePrefix = "Microsoft.Graph"
55+
)
56+
if($GraphProfile -eq "beta"){
57+
$ModulePrefix = "Microsoft.Graph.Beta"
58+
}
59+
$moduleImportName = "$ModulePrefix.$ModuleName"
60+
$moduleDocsPath = Join-Path $PSScriptRoot "$GraphProfilePath\$moduleImportName"
61+
Update-Files -ModuleDocsPath $moduleDocsPath -GraphProfile $GraphProfile -ModuleName $ModuleName
62+
}
63+
64+
if (-not (Test-Path $ModuleMappingConfigPath)) {
65+
Write-Error "Module mapping file not be found: $ModuleMappingConfigPath."
66+
}
67+
if ($ModulesToGenerate.Count -eq 0) {
68+
[HashTable] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json -AsHashTable
69+
$ModulesToGenerate = $ModuleMapping.Keys
70+
}
71+
function Update-Files{
72+
param (
73+
[ValidateNotNullOrEmpty()]
74+
[string] $ModuleDocsPath,
75+
[ValidateSet("beta", "v1.0")]
76+
[string] $GraphProfile = "v1.0",
77+
[ValidateNotNullOrEmpty()]
78+
[string] $ModuleName = "Users"
79+
)
80+
try{
81+
foreach($filePath in Get-ChildItem $ModuleDocsPath){
82+
Refine_File -FilePath $filePath -GraphProfile $GraphProfile -ModuleName $ModuleName
83+
#Special-Escape -FilePath $FilePath -GraphProfile $GraphProfile -ModuleName $ModuleName
84+
#Start-Sleep -Seconds 5
85+
}
86+
}catch{
87+
Write-Host "`nError Message: " $_.Exception.Message
88+
Write-Host "`nError in Line: " $_.InvocationInfo.Line
89+
Write-Host "`nError in Line Number: "$_.InvocationInfo.ScriptLineNumber
90+
Write-Host "`nError Item Name: "$_.Exception.ItemName
91+
}
92+
}
93+
function Refine_File{
94+
param (
95+
[ValidateNotNullOrEmpty()]
96+
[string] $FilePath,
97+
[ValidateSet("beta", "v1.0")]
98+
[string] $GraphProfile = "v1.0",
99+
[ValidateNotNullOrEmpty()]
100+
[string] $ModuleName = "Users"
101+
)
102+
$tempFilePath = "$env:TEMP\$($FilePath | Split-Path -Leaf)"
103+
104+
$replace = ""
105+
try{
106+
$text = Get-Content -Path $FilePath
107+
Write-Host $FilePath
108+
foreach($content in $text){
109+
if($content -match "\\n"){
110+
$text = $text -replace "\\n", $replace
111+
}
112+
}
113+
$text > $tempFilePath
114+
Remove-Item -Path $FilePath
115+
Move-Item -Path $tempFilePath -Destination $FilePath
116+
}catch{
117+
Write-Host "`nError Message: " $_.Exception.Message
118+
Write-Host "`nError in Line: " $_.InvocationInfo.Line
119+
Write-Host "`nError in Line Number: "$_.InvocationInfo.ScriptLineNumber
120+
Write-Host "`nError Item Name: "$_.Exception.ItemName
121+
}
122+
}
123+
124+
125+
# Set-Location microsoftgraph-docs-powershell
126+
# $date = Get-Date -Format "dd-MM-yyyy"
127+
# $proposedBranch = "weekly_v2_docs_update_$date"
128+
# $exists = git branch -l $proposedBranch
129+
# if ([string]::IsNullOrEmpty($exists)) {
130+
# git checkout -b $proposedBranch
131+
# }else{
132+
# Write-Host "Branch already exists"
133+
# $currentBranch = git rev-parse --abbrev-ref HEAD
134+
# if($currentBranch -ne $proposedBranch){
135+
# git checkout $proposedBranch
136+
# }
137+
# git checkout $proposedBranch
138+
# }
139+
Remove-Invalid-NextLine -ModulesToGenerate $ModulesToGenerate
140+
#cd microsoftgraph-docs-powershell
141+
Write-Host -ForegroundColor Green "-------------Done-------------"

microsoftgraph/breadcrumb/toc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
tocHref: /powershell/microsoftgraph/
1111
topicHref: /powershell/microsoftgraph/overview
1212
- name: Microsoft Graph PowerShell
13-
tocHref: /powershell/module/Microsoft.Graph.Applications
14-
topicHref: /powershell/module/Microsoft.Graph.Applications/?view=graph-powershell-1.0
13+
tocHref: /powershell/module/Microsoft.Graph.Authentication
14+
topicHref: /powershell/module/Microsoft.Graph.Authentication/?view=graph-powershell-1.0
1515
- name: Microsoft Graph PowerShell Beta
1616
tocHref: /powershell/module/Microsoft.Graph.Beta.Applications
1717
topicHref: /powershell/module/Microsoft.Graph.Beta.Applications/?view=graph-powershell-beta
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
external help file: Microsoft.Graph.Authentication.dll-Help.xml
3+
Module Name: Microsoft.Graph.Authentication
4+
online version: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/add-mgenvironment
5+
schema: 2.0.0
6+
---
7+
8+
# Add-MgEnvironment
9+
10+
## SYNOPSIS
11+
Adds Microsoft Graph environment to the settings file.
12+
13+
## SYNTAX
14+
15+
```
16+
Add-MgEnvironment [-Name] <String> [-AzureADEndpoint] <String> [-GraphEndpoint] <String> [-WhatIf] [-Confirm]
17+
[<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
Adds Microsoft Graph environment to the settings file.
22+
23+
## EXAMPLES
24+
25+
### Example 1: Add user defined environment
26+
```powershell
27+
PS C:\> Add-MgEnvironment -Name "Canary" -GraphEndpoint "https://canary.graph.microsoft.com" -AzureADEndpoint "https://login.microsoftonline.com"
28+
Name AzureADEndpoint GraphEndpoint Type
29+
---- --------------- ------------- ----
30+
Canary https://login.microsoftonline.com https://microsoftgraph.com User-defined
31+
```
32+
33+
Adds user defined environment.
34+
35+
## PARAMETERS
36+
37+
### -AzureADEndpoint
38+
The base URL for Azure AD endpoint to get access tokens for Microsoft Graph endpoint.
39+
40+
```yaml
41+
Type: String
42+
Parameter Sets: (All)
43+
Aliases: AzureADUrl
44+
45+
Required: True
46+
Position: 1
47+
Default value: None
48+
Accept pipeline input: True (ByPropertyName)
49+
Accept wildcard characters: False
50+
```
51+
52+
### -GraphEndpoint
53+
The service root endpoint for Microsoft Graph.
54+
55+
```yaml
56+
Type: String
57+
Parameter Sets: (All)
58+
Aliases: GraphUrl
59+
60+
Required: True
61+
Position: 2
62+
Default value: None
63+
Accept pipeline input: True (ByPropertyName)
64+
Accept wildcard characters: False
65+
```
66+
67+
### -Name
68+
The environment name.
69+
70+
```yaml
71+
Type: String
72+
Parameter Sets: (All)
73+
Aliases:
74+
75+
Required: True
76+
Position: 0
77+
Default value: None
78+
Accept pipeline input: True (ByPropertyName)
79+
Accept wildcard characters: False
80+
```
81+
82+
### -Confirm
83+
Prompts you for confirmation before running the cmdlet.
84+
85+
```yaml
86+
Type: SwitchParameter
87+
Parameter Sets: (All)
88+
Aliases: cf
89+
90+
Required: False
91+
Position: Named
92+
Default value: None
93+
Accept pipeline input: False
94+
Accept wildcard characters: False
95+
```
96+
97+
### -WhatIf
98+
Shows what would happen if the cmdlet runs.
99+
The cmdlet is not run.
100+
101+
```yaml
102+
Type: SwitchParameter
103+
Parameter Sets: (All)
104+
Aliases: wi
105+
106+
Required: False
107+
Position: Named
108+
Default value: None
109+
Accept pipeline input: False
110+
Accept wildcard characters: False
111+
```
112+
113+
### CommonParameters
114+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
115+
116+
## INPUTS
117+
118+
### System.String
119+
120+
## OUTPUTS
121+
122+
### Microsoft.Graph.PowerShell.Authentication.Models.GraphEnvironment
123+
124+
## NOTES
125+
126+
## RELATED LINKS
127+
128+
[https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/add-mgenvironment](https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/add-mgenvironment)
129+

0 commit comments

Comments
 (0)