Skip to content

Commit

Permalink
Merge pull request #20 from blindzero/feature/posh-az
Browse files Browse the repository at this point in the history
#7 Support MS Azure POSH module
  • Loading branch information
blindzero authored May 9, 2020
2 parents ba29d06 + ecaf3b0 commit bd37c79
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 179 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Powershell module to connect to all MS365 services and install required packages

- [#15 Module Updater](https://github.com/blindzero/Connect-MS365/issues/15)
Comparing installed and available module version and prompt to update.
- [#7 Support MS Azure](https://github.com/blindzero/Connect-MS365/issues/7)
Uses Az module and Connect-AzAccount

### Fixes

Expand Down
11 changes: 9 additions & 2 deletions docs/02-USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ When installed properly (see 01-INSTALLATION.md), the module Connect-MS365 shoul
Start Connect-MS365 by using

```powershell
Connect-MS365 -Service <list of services> [-SPOOrgName <name of sharepoint org>] [-MFA]
Connect-MS365 -Service <list of services> [-SPOOrgName <name of sharepoint org>]
```

The service you want to connect is selected by `-Service` parameter, followed by one of the supported services
Expand Down Expand Up @@ -50,9 +50,16 @@ The service you want to connect is selected by `-Service` parameter, followed by

See the CmdLet reference for all available commands.

* __AZ__ - Microsoft Azure Platform

Uses [Az](https://docs.microsoft.com/de-de/powershell/azure) module to connect to Microsoft Azure ActiveDirectory.

See the [CmdLet reference](https://docs.microsoft.com/de-de/powershell/module/?view=azps-3.8.0) for all available commands.

### Multi Factor Authentication (MFA)

If you have to use MFA you may get errors when connection with standard options. Add `-MFA` switch to your Connect-MS365 command.
By version 1.1.0 modern authentication usage is default, incl. MFA functionality.
Passing PSCredential object was removed.

### Module Installations

Expand Down
54 changes: 13 additions & 41 deletions docs/Connect-MS365.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ Connects to a given online service of Microsoft.
Connect-MS365 [-Service] <String[]> [[-SPOOrgName] <String>] [<CommonParameters>]
```

### MFA
```
Connect-MS365 [-Service] <String[]> [[-SPOOrgName] <String>] [-MFA] [<CommonParameters>]
```

### Credential
```
Connect-MS365 [-Service] <String[]> [[-SPOOrgName] <String>] [[-Credential] <PSCredential>]
Expand All @@ -38,57 +33,51 @@ Supports connection handling for
- SharePoint Online (SPO)
- Security and Compliance Center (SCC)
- Azure ActiveDirectory (AAD) v2
- Azure Platform (AZ)

## EXAMPLES

### EXAMPLE 1
```
Description: Connect to Microsoft Online without using MFA
Description: Connect to Microsoft Online
```

Connect-MS365 -Service MSOL

### EXAMPLE 2
```
Description: Connect to Microsoft Online by using MFA
Description: Connect to Microsoft Online and Exchange Online
```

Connect-MS365 -Service MSOL -MFA
Connect-MS365 -Service MSOL,EOL

### EXAMPLE 3
```
Description: Connect to Microsoft Online and Exchange Online by using MFA
Description: Connect to SharePoint Online to connect to MyName-admin.sharepoint.com
```

Connect-MS365 -Service MSOL,EOL -MFA
Connect-MS365 -Service SPO -SPOOrgName MyName

### EXAMPLE 4
```
Description: Connect to SharePoint Online without MFA to connect to MyName-admin.sharepoint.com
Description: Connect to Security and Compliance Center
```

Connect-MS365 -Service SPO -SPOOrgName MyName
Connect-MS365 -Service SCC

### EXAMPLE 5
```
Description: Connect to SharePoint Online with MFA to connect to MyName-admin.sharepoint.com
Description: Connect to Azure ActiveDirectory
```

Connect-MS365 -Service SPO -SPOOrgName MyName -MFA
Connect-MS365 -Service AAD

### EXAMPLE 6
```
Description: Connect to Security and Compliance Center with MFA
Description: Connect to Microsoft Azure platform
```

Connect-MS365 -Service SCC -MFA

### EXAMPLE 7
```
Description: Connect to Azure ActiveDirectory with MFA
```

Connect-MS365 -Service AAD -MFA
Connect-MS365 -Service AZ

## PARAMETERS

Expand Down Expand Up @@ -124,22 +113,6 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -MFA
Toggles MFA usage.
Not requesting PSCredential object.
```yaml
Type: SwitchParameter
Parameter Sets: MFA
Aliases:

Required: False
Position: 4
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -Credential
Credential parameter to receive previously created PSCredential object.
Primarily needed for testing calls
Expand All @@ -161,10 +134,9 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## INPUTS
### None. You cannot pipe objects to Add-Extension.
### None. You cannot pipe objects to Connect-MS365.
## OUTPUTS
### // <OBJECTTYPE>. TBD.
## NOTES
## RELATED LINKS
Expand Down
5 changes: 3 additions & 2 deletions src/Connect-MS365.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ ModuleList = @('.\Connect-MS365.psm1')
# List of all files packaged with this module
FileList = @(
'Connect-MS365.psd1','Connect-MS365.psm1',
'LICENSE','README.md','RELEASENOTES.md'
'LICENSE','README.md','RELEASENOTES.md',
'docs/Connect-MS365.md','en-us/Connect-MS365-help.xml'
)

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
Expand All @@ -103,7 +104,7 @@ PrivateData = @{
'Microsoft_Teams','Teams',
'Skype_for_Business','SfB','S4B','Skype4B',
'SecurityComplianceCenter','IPP','SCC',
'Azure','Microsoft_Azure',
'Azure','Microsoft_Azure','Az',
'AzureAD','Azure_AD','AAD')

# A URL to the license for this module.
Expand Down
109 changes: 36 additions & 73 deletions src/Connect-MS365.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,37 @@ One or multiple service names can be chosen. Supports connection handling for
- SharePoint Online (SPO)
- Security and Compliance Center (SCC)
- Azure ActiveDirectory (AAD) v2
- Azure Platform (AZ)
.PARAMETER Service
Specifies the service to connect to. May be a list of multiple services to use.
.PARAMETER MFA
Toggles MFA usage. Not requesting PSCredential object.
.INPUTS
None. You cannot pipe objects to Add-Extension.
.OUTPUTS
// <OBJECTTYPE>. TBD.
None. You cannot pipe objects to Connect-MS365.
.EXAMPLE
Description: Connect to Microsoft Online without using MFA
Description: Connect to Microsoft Online
Connect-MS365 -Service MSOL
.EXAMPLE
Description: Connect to Microsoft Online by using MFA
Connect-MS365 -Service MSOL -MFA
Description: Connect to Microsoft Online and Exchange Online
Connect-MS365 -Service MSOL,EOL
.EXAMPLE
Description: Connect to Microsoft Online and Exchange Online by using MFA
Connect-MS365 -Service MSOL,EOL -MFA
.EXAMPLE
Description: Connect to SharePoint Online without MFA to connect to MyName-admin.sharepoint.com
Description: Connect to SharePoint Online to connect to MyName-admin.sharepoint.com
Connect-MS365 -Service SPO -SPOOrgName MyName
.EXAMPLE
Description: Connect to SharePoint Online with MFA to connect to MyName-admin.sharepoint.com
Connect-MS365 -Service SPO -SPOOrgName MyName -MFA
Description: Connect to Security and Compliance Center
Connect-MS365 -Service SCC
.EXAMPLE
Description: Connect to Security and Compliance Center with MFA
Connect-MS365 -Service SCC -MFA
Description: Connect to Azure ActiveDirectory
Connect-MS365 -Service AAD
.EXAMPLE
Description: Connect to Azure ActiveDirectory with MFA
Connect-MS365 -Service AAD -MFA
Description: Connect to Microsoft Azure platform
Connect-MS365 -Service AZ
.LINK
https://github.com/blindzero/Connect-MS365
Expand All @@ -64,7 +55,7 @@ function Connect-MS365 {
#service parameter to define to which services to connect to
#are validated against available / implemented services
[Parameter(Mandatory=$True, Position = 1)]
[ValidateSet('MSOL','EOL','Teams','SPO','SCC','AAD')]
[ValidateSet('MSOL','EOL','Teams','SPO','SCC','AAD','AZ')]
[string[]]
$Service,
#spoorg parameter for connection to SPO service
Expand All @@ -73,100 +64,78 @@ function Connect-MS365 {
[string]
[Alias('SPOOrg')]
$SPOOrgName,
#mfa parameter if mfa authentication is necessary
#used later to determine different connection commands and is not using PScredential object
[Parameter(Mandatory=$False, Position = 3, ParameterSetName = 'MFA')]
[Switch]
$MFA,
#Credential parameter to receive previously created PSCredential object.
#Primarily needed for testing calls
[Parameter(Mandatory=$False, Position = 3, ParameterSetName = 'Credential')]
[PSCredential]
$Credential
)

# dont gather PSCredential object if MFA is set
If (($MFA -ne $True) -and (!($Credential))) {
Write-Verbose "Gathering PSCredentials object for non MFA sign on"
$Credential = Get-Credential -Message "Please enter your Office 365 credentials"
}

# TODO #10: changing to settings array containing module names making switch unnecessary

# iterating through each service listed in service parameter
# each service is passing PSCredential object if MFA not set or leaves it out if set
ForEach ($ServiceItem in $Service) {
Write-Verbose "Create session to Service $ServiceItem"
Switch($ServiceItem) {
# Microsoft Online service
MSOL {
$ServiceName = "Microsoft Online / AzureAD v1"
$ModuleName = "MSOnline"
$ModuleFindString = $ModuleName

if ($MFA) {
Connect-MSOL
}
else {
Connect-MSOL -Credential $Credential
}
Connect-MSOL
continue
}
# Exchange Online service
EOL {
$ServiceName = "Exchange Online"
$ModuleName = "ExchangeOnlineManagement"
$ModuleFindString = $ModuleName

if ($MFA) {
Connect-EOL
}
else {
Connect-EOL -Credential $Credential
}
Connect-EOL
continue
}
# Teams service
Teams {
$ServiceName = "Microsoft Teams"
$ModuleName = "MicrosoftTeams"
$ModuleFindString = $ModuleName

if ($MFA) {
Connect-Teams
}
else {
Connect-Teams -Credential $Credential
}
Connect-Teams
continue
}
# Security and Compliance Center
SCC {
$ServiceName = "Security & Compliance Center"
$ModuleName = "ExchangeOnlineManagement"
$ModuleFindString = $ModuleName

if ($MFA) {
Connect-SCC
}
else {
Connect-SCC -Credential $Credential
}
Connect-SCC
continue
}
# AzureAD
AAD {
$ServiceName = "AzureAD v2"
$ModuleName = "AzureAD"
$ModuleFindString = $ModuleName

if ($MFA) {
Connect-AAD
}
else {
Connect-AAD -Credential $Credential
}
Connect-AAD
continue
}
# Azure
AZ {
$ServiceName = "Azure"
$ModuleName = "Az"
$ModuleFindString = "Az.*"

Connect-AZ
continue
}
# SPO service
SPO {
$ServiceName = "SharePoint Online"
$ModuleName = "Microsoft.Online.SharePoint.PowerShell"
$ModuleFindString = $ModuleName

If (!($SPOOrgName)) {
Write-Error 'To connect to SharePoint Online you have to provide the -SPOOrgName parameter.'
Expand All @@ -178,21 +147,15 @@ function Connect-MS365 {
Write-Verbose "Created $SPOOrgUrl"
}

if ($MFA) {
Write-Verbose "Connecting to SharePoint Online at $SPOOrgUrl without Credential"
Connect-SPO -SPOOrgUrl $SPOOrgUrl
}
else {
Write-Verbose "Connecting to SharePoint Online at $SPOOrgUrl with $Credential"
Connect-SPO -SPOOrgUrl $SPOOrgUrl -Credential $Credential
}
Write-Verbose "Connecting to SharePoint Online at $SPOOrgUrl"
Connect-SPO -SPOOrgUrl $SPOOrgUrl
continue
}
}
Write-Verbose "Create session to Service $ServiceItem done."
}

Write-Verbose "Connect-MS365 terminated."
Write-Verbose "Connect-MS365 done."
}

# Export only the functions using PowerShell standard verb-noun naming.
Expand Down
Loading

0 comments on commit bd37c79

Please sign in to comment.