Forum / Remote Desktop Manager - Macro/Script/Tools

Connecting to Office 365 Powershell

  • Create an Issue
  • Cancel

Hello,

What RDM version are you using?

Have you already tried with an account with MFA enabled? If so, are you experiencing any issue?

Best regards,



Érica Poirier

Happy Holiday Season!
Although our various support queues will be monitored during the coming holiday season, Devolutions' offices will be closed from December 24th, 2019, to January 1, 2020, inclusively.

signaturesignature

Clock13 days

Hi epoirier,


Using free edition as of the moment version 2019.2.18.0.
Have try the script but when I press execute it ask me what session to choose but don't know. Also can't find the allow password in variable.


image


Best Regards,
Mark

Clock13 days


Hello Mark,

You can find the Allow password in variable option in the Security Settings tab of the PowerShell entry.

image

As I cannot see your image in your last post, what PowerShell entry type are you using? Is it the PowerShell session entry (PowerShell blue icon) or the PowerShell Macro/Script/Tool (green icon)?

image

Best regards,



Érica Poirier

Happy Holiday Season!
Although our various support queues will be monitored during the coming holiday season, Devolutions' offices will be closed from December 24th, 2019, to January 1, 2020, inclusively.

signaturesignature

Clock12 days

Hi Erica,

It now works but it asked me to login, is there a way it will auto fill the username and password so it can reach MFA window and skip the username and password?

Best Regards,
Mark

Screenshot_156.png
Clock12 days


Hi Erica,

How to bypass Self Signed Certs? it doesn't work with Chrome but I made it work with IE.

Best Regards,
Mark


mard wrote:

Hi Erica,

It now works but it asked me to login, is there a way it will auto fill the username and password so it can reach MFA window and skip the username and password?

Best Regards,
Mark

Clock12 days

Hello Mark,

Could you please send me the PowerShell script entry to investigate why it doesn't properly send the credentials? Please send it to ticket@devolutions.net to open a ticket in our system.

Best regards,



Érica Poirier

Happy Holiday Season!
Although our various support queues will be monitored during the coming holiday season, Devolutions' offices will be closed from December 24th, 2019, to January 1, 2020, inclusively.

signaturesignature

Clock12 days

Hi Erica,

Kindly see below.


#Created by Reinout.Dorreboom@bevio.nl, edited by Jeffrey Veenhuis
$User = 'myusername@username.com'
$PWord = 'mypassword'
$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

Best Regards,
Mark

Clock12 days

Hello,

Could you please try to replace the value of the 2 variables $user and $PWord with the following value to see if it will help to send the credentials? By using the RDM variables $USERNAME$ and $PASSWORD$, it should use the credential set on the entry that is running the PowerShell script.

$User = $USERNAME$
$PWord = $PASSWORD$
$Password = ConvertTo-SecureString -String $PWord -AsPlainText -Force
$creds = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PassWord

Best regards,



Érica Poirier

Happy Holiday Season!
Although our various support queues will be monitored during the coming holiday season, Devolutions' offices will be closed from December 24th, 2019, to January 1, 2020, inclusively.

signaturesignature

Clock11 days

Hi Erica,

I'm encountering now this.


myemailaddress.com : The term 'myemailaddress.com' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:2 char:9
+ $User = myemailaddress.com
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (myemailaddress.com:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

mypassword : The term 'mypassword' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:3 char:10
+ $PWord = mypassword
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (mypassword:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:4 char:44
+ $Password = ConvertTo-SecureString -String $PWord -AsPlainText -Force
+ ~~~~~~
+ CategoryInfo : InvalidData: (smile [ConvertTo-SecureString], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand

New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "userName" is not valid. Change the value of the "userName" argument and
run the operation again."
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:5 char:10
+ $creds = New-Object -TypeName System.Management.Automation.PSCredenti ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (smile [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Clean up the current sessions on the computer...Done
MSOnline Module exists
SkypeOnlineConnector Module exists
Connecting to MS Online Services...Connect-MsolService : Authentication Error: Unexpected authentication failure.
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:26 char:1
+ Connect-MsolService -Credential $Creds |Out-Null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (smile [Connect-MsolService], Exception
+ FullyQualifiedErrorId : System.Exception,Microsoft.Online.Administration.Automation.ConnectMsolServ
ice

Done
Connecting to Exchange Online...New-PSSession : Cannot bind argument to parameter 'Credential' because it is null.
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:31 char:144
+ ... //outlook.office365.com/powershell-liveid/ -Credential $Creds -Authen ...
+ ~~~~~~
+ CategoryInfo : InvalidData: (smile [New-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Command
s.NewPSSessionCommand

Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid
value for the argument, and then try running the command again.
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:32 char:18
+ Import-PSSession $ExOnSession -WarningAction SilentlyContinue -Disabl ...
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (smile [Import-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSess
ionCommand

Done
Connecting to the Compliance Center...New-PSSession : Cannot bind argument to parameter 'Credential' because it is null.
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:37 char:165
+ ... .protection.outlook.com/powershell-liveid/ -Credential $Creds -Authen ...
+ ~~~~~~
+ CategoryInfo : InvalidData: (smile [New-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Command
s.NewPSSessionCommand

Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid
value for the argument, and then try running the command again.
At C:\Users\user\AppData\Local\Temp\RDM\81a88f87-7833-4382-a587-476992faed94.ps1:38 char:18
+ Import-PSSession $ComplianceSession -WarningAction SilentlyContinue - ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (smile [Import-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSess
ionCommand

Done

You are now connected to Office 365, Exchange Online, the Compliance center and Skype for Business Online

Best Regards,
Mark

Clock11 days


Hello,

The first two errors are related to missing quotes. $User = myemailaddress.com should be $User = "myemailaddress.com" and $PWord = "mypassword" should be $PWord = "mypassword". Fixing those two issues should help to get the script running.

Best regards,



Érica Poirier

Happy Holiday Season!
Although our various support queues will be monitored during the coming holiday season, Devolutions' offices will be closed from December 24th, 2019, to January 1, 2020, inclusively.

signaturesignature

Clock4 days

Hi Erica,

Now it is going here in this part it is manual?

Best Regards,
Mark

Screenshot_161.png
Screenshot_162.png
Clock4 days