Users

All Posts (11)

avatar

jveenhuis

Disabled

Connecting to Office 365 Powershell

avatar
avatar
avatar
avatar
avatar
jveenhuis
Disabled

Here's the script we're currently using, def less convient then without MFA but better then nothing.

#region Connect-Office365

function Connect-Office365

{

<#

.NOTES

===========================================================================

Created on: 2/4/2019 10:42 PM

Created by: Bradley Wyatt

E-Mail: Brad@TheLazyAdministrator.com

GitHub: https://github.com/bwya77

Website: https://www.thelazyadministrator.com

Organization: Porcaro Stolarek Mete Partners; The Lazy Administrator

Filename: Connect-Office365.ps1

Version: 1.0.4

Contributors: /u/Sheppard_Ra

Changelog:

1.0.4

- Host title will add a service or services you are connected to. If unable to connect it will not display connection status until connection is valid

===========================================================================

.SYNOPSIS

Connect to Office 365 Services

.DESCRIPTION

Connect to different Office 365 Services using PowerShell function. Supports MFA.

.PARAMETER MFA

Description: Specifies MFA requirement to sign into Office 365 services. If set to $True it will use the Office 365 ExoPSSession Module to sign into Exchange & Compliance Center using MFA. Other modules support MFA without needing another external module

.PARAMETER Exchange

Description: Connect to Exchange Online

.PARAMETER SkypeForBusiness

Description: Connect to Skype for Business

.PARAMETER SharePoint

Description: Connect to SharePoint Online

.PARAMETER SecurityandCompliance

Description: Connect to Security and Compliance Center

.PARAMETER AzureAD

Description: Connect to Azure AD V2

.PARAMETER MSOnline

Type: Switch

Description: Connect to Azure AD V1

.PARAMETER Teams

Type: Switch

Description: Connect to Teams

.EXAMPLE

Description: Connect to SharePoint Online

C:\PS> Connect-Office365 -SharePoint

.EXAMPLE

Description: Connect to Exchange Online and Azure AD V1 (MSOnline)

C:\PS> Connect-Office365 -Service Exchange, MSOnline

.EXAMPLE

Description: Connect to Exchange Online and Azure AD V2 using Multi-Factor Authentication

C:\PS> Connect-Office365 -Service Exchange, MSOnline -MFA

.EXAMPLE

Description: Connect to Teams and Skype for Business

C:\PS> Connect-Office365 -Service Teams, SkypeForBusiness

.EXAMPLE

Description: Connect to SharePoint Online

C:\PS> Connect-Office365 -Service SharePoint -SharePointOrganizationName bwya77 -MFA

.LINK

Online version: https://www.thelazyadministrator.com/2019/02/05/powershell-function-to-connect-to-all-office-365-services

#>

[OutputType()]

[CmdletBinding(DefaultParameterSetName)]

Param (

[Parameter(Mandatory = $True, Position = 1)]

[ValidateSet('AzureAD', 'Exchange', 'MSOnline', 'SecurityAndCompliance', 'SharePoint', 'SkypeForBusiness', 'Teams')]

[string[]]$Service,

[Parameter(Mandatory = $False, Position = 2)]

[Alias('SPOrgName')]

[string]$SharePointOrganizationName,

[Parameter(Mandatory = $False, Position = 3, ParameterSetName = 'Credential')]

[PSCredential]$Credential,

[Parameter(Mandatory = $False, Position = 3, ParameterSetName = 'MFA')]

[Switch]$MFA

)

$getModuleSplat = @{

ListAvailable = $True

Verbose = $False

}

If ($MFA -ne $True)

{

Write-Verbose "Gathering PSCredentials object for non MFA sign on"

$Credential = Get-Credential -Message "Please enter your Office 365 credentials"

}

ForEach ($Item in $PSBoundParameters.Service)

{

Write-Verbose "Attempting connection to $Item"

Switch ($Item)

{

AzureAD {

If ($null -eq (Get-Module @getModuleSplat -Name "AzureAD"))

{

Write-Error "SkypeOnlineConnector Module is not present!"

continue

}

Else

{

If ($MFA -eq $True)

{

$Connect = Connect-AzureAD

If ($Connect -ne $Null)

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: AzureAD"

}

Else

{

$host.ui.RawUI.WindowTitle += " - AzureAD"

}

}

}

Else

{

$Connect = Connect-AzureAD -Credential $Credential

If ($Connect -ne $Null)

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: AzureAD"

}

Else

{

$host.ui.RawUI.WindowTitle += " - AzureAD"

}

}

}

}

continue

}

Exchange {

If ($MFA -eq $True)

{

$getChildItemSplat = @{

Path = "$Env:LOCALAPPDATA\Apps\2.0\*\CreateExoPSSession.ps1"

Recurse = $true

ErrorAction = 'SilentlyContinue'

Verbose = $false

}

$MFAExchangeModule = ((Get-ChildItem @getChildItemSplat | Select-Object -ExpandProperty Target -First 1).Replace("CreateExoPSSession.ps1", ""))

If ($null -eq $MFAExchangeModule)

{

Write-Error "The Exchange Online MFA Module was not found!

https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps"

continue

}

Else

{

Write-Verbose "Importing Exchange MFA Module"

. "$MFAExchangeModule\CreateExoPSSession.ps1"

Write-Verbose "Connecting to Exchange Online"

Connect-EXOPSSession

If ($Null -ne (Get-PSSession | Where-Object { $_.ConfigurationName -like "*Exchange*" }))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: Exchange"

}

Else

{

$host.ui.RawUI.WindowTitle += " - Exchange"

}

}

}

}

Else

{

$newPSSessionSplat = @{

ConfigurationName = 'Microsoft.Exchange'

ConnectionUri = "https://ps.outlook.com/powershell/"

Authentication = 'Basic'

Credential = $Credential

AllowRedirection = $true

}

$Session = New-PSSession @newPSSessionSplat

Write-Verbose "Connecting to Exchange Online"

Import-PSSession $Session -AllowClobber

If ($Null -ne (Get-PSSession | Where-Object { $_.ConfigurationName -like "*Exchange*" }))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: Exchange"

}

Else

{

$host.ui.RawUI.WindowTitle += " - Exchange"

}

}

}

continue

}

MSOnline {

If ($null -eq (Get-Module @getModuleSplat -Name "MSOnline"))

{

Write-Error "MSOnline Module is not present!"

continue

}

Else

{

Write-Verbose "Connecting to MSOnline"

If ($MFA -eq $True)

{

Connect-MsolService

If ($Null -ne (Get-MsolCompanyInformation -ErrorAction SilentlyContinue))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: MSOnline"

}

Else

{

$host.ui.RawUI.WindowTitle += " - MSOnline"

}

}

}

Else

{

Connect-MsolService -Credential $Credential

If ($Null -ne (Get-MsolCompanyInformation -ErrorAction SilentlyContinue))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: MSOnline"

}

Else

{

$host.ui.RawUI.WindowTitle += " - MSOnline"

}

}

}

}

continue

}

SecurityAndCompliance {

If ($MFA -eq $True)

{

$getChildItemSplat = @{

Path = "$Env:LOCALAPPDATA\Apps\2.0\*\CreateExoPSSession.ps1"

Recurse = $true

ErrorAction = 'SilentlyContinue'

Verbose = $false

}

$MFAExchangeModule = ((Get-ChildItem @getChildItemSplat | Select-Object -ExpandProperty Target -First 1).Replace("CreateExoPSSession.ps1", ""))

If ($null -eq $MFAExchangeModule)

{

Write-Error "The Exchange Online MFA Module was not found!

https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps"

continue

}

Else

{

Write-Verbose "Importing Exchange MFA Module (Required)"

. "$MFAExchangeModule\CreateExoPSSession.ps1"

Write-Verbose "Connecting to Security and Compliance Center"

Connect-IPPSSession

If ($Null -ne (Get-PSSession | Where-Object { $_.ConfigurationName -like "*Exchange*" }))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: Security and Compliance Center"

}

Else

{

$host.ui.RawUI.WindowTitle += " - Security and Compliance Center"

}

}

}

}

Else

{

$newPSSessionSplat = @{

ConfigurationName = 'Microsoft.SecurityAndCompliance'

ConnectionUri = 'https://ps.compliance.protection.outlook.com/powershell-liveid/'

Authentication = 'Basic'

Credential = $Credential

AllowRedirection = $true

}

$Session = New-PSSession @newPSSessionSplat

Write-Verbose "Connecting to SecurityAndCompliance"

Import-PSSession $Session -DisableNameChecking

If ($Null -ne (Get-PSSession | Where-Object { $_.ConfigurationName -like "*Exchange*" }))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: Security and Compliance Center"

}

Else

{

$host.ui.RawUI.WindowTitle += " - Security and Compliance Center"

}

}

}

continue

}

SharePoint {

If ($null -eq (Get-Module @getModuleSplat -Name Microsoft.Online.SharePoint.PowerShell))

{

Write-Error "Microsoft.Online.SharePoint.PowerShell Module is not present!"

continue

}

Else

{

If (-not ($PSBoundParameters.ContainsKey('SharePointOrganizationName')))

{

Write-Error 'Please provide a valid SharePoint organization name with the -SharePointOrganizationName parameter.'

continue

}

$SharePointURL = "https://{0}-admin.sharepoint.com" -f $SharePointOrganizationName

Write-Verbose "Connecting to SharePoint at $SharePointURL"

If ($MFA -eq $True)

{

$SPOSession = Connect-SPOService -Url $SharePointURL

If ($Null -ne (Get-SPOTenant))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: SharePoint Online"

}

Else

{

$host.ui.RawUI.WindowTitle += " - SharePoint Online"

}

}

}

Else

{

$SPOSession = Connect-SPOService -Url $SharePointURL -Credential $Credential

If ($Null -ne (Get-SPOTenant))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: SharePoint Online"

}

Else

{

$host.ui.RawUI.WindowTitle += " - SharePoint Online"

}

}

}

}

continue

}

SkypeForBusiness {

Write-Verbose "Connecting to SkypeForBusiness"

If ($null -eq (Get-Module @getModuleSplat -Name "SkypeOnlineConnector"))

{

Write-Error "SkypeOnlineConnector Module is not present!"

}

Else

{

# Skype for Business module

Import-Module SkypeOnlineConnector

If ($MFA -eq $True)

{

$CSSession = New-CsOnlineSession

Import-PSSession $CSSession -AllowClobber

If ($Null -ne (Get-CsOnlineDirectoryTenant))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: Skype for Business"

}

Else

{

$host.ui.RawUI.WindowTitle += " - Skype for Business"

}

}

}

Else

{

$CSSession = New-CsOnlineSession -Credential $Credential

Import-PSSession $CSSession -AllowClobber

If ($Null -ne (Get-CsOnlineDirectoryTenant))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: Skype for Business"

}

Else

{

$host.ui.RawUI.WindowTitle += " - Skype for Business"

}

}

}

}

continue

}

Teams {

If ($null -eq (Get-Module @getModuleSplat -Name "MicrosoftTeams"))

{

Write-Error "MicrosoftTeams Module is not present!"

}

Else

{

Write-Verbose "Connecting to Teams"

If ($MFA -eq $True)

{

$TeamsConnect = Connect-MicrosoftTeams

If ($Null -ne ($TeamsConnect))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: Microsoft Teams"

}

Else

{

$host.ui.RawUI.WindowTitle += " - Microsoft Teams"

}

}

}

Else

{

$TeamsConnect = Connect-MicrosoftTeams -Credential $Credential

If ($Null -ne ($TeamsConnect))

{

If (($host.ui.RawUI.WindowTitle) -notlike "*Connected To:*")

{

$host.ui.RawUI.WindowTitle += " - Connected To: Microsoft Teams"

}

Else

{

$host.ui.RawUI.WindowTitle += " - Microsoft Teams"

}

}

}

}

continue

}

Default { }

}

}

}

#endregion

#region Customization by Jeffrey Veenhuis 14-10-2019

$exchange = $true

$msonline = $true

$security = $true

$azuread = $false

$skype = $false

$sharepoint = $false

$teams = $false

$optionschosen = $false

While(!$optionschosen){

Clear-Host

Write-Host "Which services do you want to connect to?

You will need the modules for each service you want to connect to.

[$(If ($exchange) {"X"} Else {" "})] 1. Exchange Online

[$(If ($msonline) {"X"} Else {" "})] 2. MSOnline (AzureAD v1)

[$(If ($security) {"X"} Else {" "})] 3. Security and Compliance Center

[$(If ($azuread) {"X"} Else {" "})] 4. AzureAD v2

[$(If ($skype) {"X"} Else {" "})] 5. Skype For Business

[$(If ($sharepoint) {"X"} Else {" "})] 6. Sharepoint

[$(If ($teams) {"X"} Else {" "})] 7. Teams

"

$key = Read-Host "Use any of the number keys to change which service you want to connect to, otherwise just press enter"

switch($key){

1 {$exchange = !$exchange; break}

2 {$msonline = !$msonline; break}

3 {$security = !$security; break}

4 {$azuread = !$azuread; break}

5 {$skype = !$skype; break}

6 {$sharepoint = !$sharepoint; break}

7 {$teams = !$teams; break}

default {$optionschosen = $true}

}

}

$services = @()

If ($exchange) {$services += "Exchange"}

If ($msonline) {$services += "MSOnline"}

If ($security) {$services += "SecurityAndCompliance"}

If ($azuread) {$services += "AzureAD"}

If ($skype) {$services += "SkypeForBusiness"}

If ($sharepoint) {$services += "Sharepoint"}

If ($teams) {$services += "Teams"}

Connect-Office365 -Service $services -MFA

It's slightly adjusted but it's something, and yes you'll have to login multiple times per module, got nothing around it.

Someway to handle UAC better

avatar
avatar
avatar
avatar
avatar
jveenhuis
Disabled

Hey there, I've been checking out Wayk Now as maybe a replacement or addition to our current Teamviewer usage but the only big function that's missing for us is the ability to control UAC prompts.

What I mean by this is consider the following scenario: A user needs support but doesn't have local administrator rights. When he opens up Wayk Now he gets a UAC prompt asking for an administrator password. User doesn't know password and clicks no, Wayk Now continues to start.

I as the engineer connect to his session and needs to do something that requires UAC permissions, for example to install something.

I open the setup file, user gets same UAC prompt and since he doesn't have the password (or isn't allowed to know the password) he can't open it for me.

Since Wayk Now isn't running in UAC mode, we as the engineer also don't see the UAC prompt so we can't input the password for him meaning we're stuck and we're unable to help the user.

If I were to be using Teamviewer I could tell the user please click no and hold on a bit, then I would close my Teamviewer session and reconnect but use Windows Authentication and fill it in with an administrator. Doing this triggers something in Teamviewer to open Teamviewer as Administrator and sometimes only asks user Yes or No in a UAC prompt (which I tell the user to click on Yes). After that I can do everything I need to do as Administrator.

This feature is very important to me if I want to consider switching from Teamviewer to Wayk Now.

Would love to hear your thoughts on this.

With kind regards,

Jeffrey Veenhuis

Add button to sessions -> Autotype password

avatar
avatar
avatar
avatar
jveenhuis
Disabled

Hey Jeff,

It kind of is, the only annoying part is that it's still a multiple step process.

Can we combine the Copy Password with the Type Clipboard button?

Add button to sessions -> Autotype password

avatar
avatar
avatar
avatar
jveenhuis
Disabled

This would probably tie in with the permission to store password in variable and stuff.

Practical usecases include RDPing to a HyperV server and then continueing the session but then you have to type in your password and Microsoft Password boxes don't allow pasting passwords.

I used to use a AHK script to type whatever is in my clipboard but having it in RDM directly would be ideal.

Connecting to Office 365 Powershell

avatar
avatar
avatar
avatar
avatar
jveenhuis
Disabled

Thanks for the script.

Had to fiddle around but for anyone else looking to get this to work this is what I did.

Using this script for now, removed the Sharepoint requirements in my case because we don't use it.

#Created by Reinout.Dorreboom@bevio.nl, edited by Jeffrey Veenhuis

$User = '$USERNAME$'

$PWord = '$PASSWORD$'

$Password = ConvertTo-SecureString -String $PWord -AsPlainText -Force

$creds = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PassWord

#Clean up opened sessions

Write-Host 'Clean up the current sessions on the computer...' -BackgroundColor Black -ForegroundColor Cyan -NoNewline

Get-PSSession | Remove-PSSession

Write-Host 'Done' -BackgroundColor Black -ForegroundColor Green

$Modules = @("MSOnline","SkypeOnlineConnector")

$Modules | foreach{

if (Get-Module -ListAvailable -Name MSOnline) {

Write-Host "$_ Module exists" -ForegroundColor green

} else {

Write-Host "$_ Module does not exist" -ForegroundColor red

$answer = Read-Host -Prompt "Do you want to continue? Yes (y) / No (n)"

If($answer -eq "n"){exit}

}

}

#Connect to the MS Online Services

Write-Host 'Connecting to MS Online Services...' -BackgroundColor Black -ForegroundColor Cyan -NoNewline

Connect-MsolService –Credential $Creds |Out-Null

Write-Host 'Done' -BackgroundColor Black -ForegroundColor Green

#Login to Exchange Online Remote Powershell and import the MS Exchange Module

Write-Host 'Connecting to Exchange Online...' -BackgroundColor Black -ForegroundColor Cyan -NoNewline

$ExOnSession = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Creds -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue

Import-PSSession $ExOnSession -WarningAction SilentlyContinue -DisableNameChecking |Out-Null

Write-Host 'Done' -BackgroundColor Black -ForegroundColor Green

#Login to the Compliance Center Remote Powershell and import the Compliance center Module

Write-Host 'Connecting to the Compliance Center...' -BackgroundColor Black -ForegroundColor Cyan -NoNewline

$ComplianceSession = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $Creds -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue

Import-PSSession $ComplianceSession -WarningAction SilentlyContinue -DisableNameChecking |Out-Null

Write-Host 'Done' -BackgroundColor Black -ForegroundColor Green

Write-Host "`nYou are now connected to Office 365, Exchange Online, the Compliance center and Skype for Business Online" -BackgroundColor Black -ForegroundColor Yellow

Use the following options:

Written a miniguide for my colleagues

1. Install msoidcli_64.msi (https://www.microsoft.com/en-us/download/details.aspx?id=28177)

2. Run Powershell as Admin and run: Set-ExecutionPolicy Unrestricted

3. Run Powershell as Admin and run: (Y to everything): Install-Module MSOnline

Everything combined should make it work for people :)

Allow sorting entries per folder by type

avatar
avatar
avatar
jveenhuis
Disabled

Yes.

For example: I have a customer with a bunch of RDP servers, a couple of Web Browser sessions and iDracs etc.

If you do it alphabetically all the different types of entries are a bit of a mess.

I know it's possible to make folders and put them under there again but I want to prevent overcomplicating our structure.

Some automatic sorting or maybe some manual sort button that does it once for you per type or some other property/column would be great!

Custom VPN "Wait for exit" option

avatar
avatar
avatar
avatar
avatar
jveenhuis
Disabled

In this instance Draytek and a custom built automation.

Can you tell me how you use Draytek VPN, is it the SmartVPN.

We still have one customer on a Draytek and any way to automate it would be godlike for us.

Allow sorting entries per folder by type

avatar
avatar
avatar
jveenhuis
Disabled

Hey there guys.

I've heard there isn't any feature that allows you to sort by type or other properties.

I've only heard about manually sorting which can be a pain if you have a lot of entries to manage for 1 customer.

Hope you guys can add it :)

Custom Password Lists

avatar
avatar
avatar
jveenhuis
Disabled

This could be decent but not as good as having it as a custom password list :)

Hope you can get it in for RDM14, any ETA in mind for RDM14?

Thumbnails for RDP Connections?

avatar
avatar
avatar
avatar
avatar
jveenhuis
Disabled

This feature sounds really awesome for patch purposes. Would like to see it eventually :)

Custom Password Lists

avatar
avatar
avatar
jveenhuis
Disabled

Hey there guys.

Just had a nice session with Mark and he referred me to this forum to submit my request :)

So basically I was wondering if you guys can make a feature similiar to the password list but be able to change what columns/properties you have.

This feature could be very helpful to group together a bunch of Office 2016 Keys (with machine service tag/token/keys) or other types of information that you don't regularly need. This also could prevent clutter in your treeview per customer.

Currently my workaround is to use the password list anyway but I put the Token in User and the Key in Password and the Servicetag or name of the user in the Description but I want to do it properly :)

Kind regards,

Jeffrey Veenhuis

1 - 11 of 11 items