Jump to content

Recommended Posts

Posted

Got an issue connecting to Office 365 to disable activesync for a specific set of users however I don't seem to be able to connect to the URI, any ideas what the URI should be?

 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.com/domain-name.com/"

 

Error:

 

New-PSSession : [outlook.com] Connecting to remote server outlook.com failed with the following error message : WinRM cannot complete the operation. Verify

that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled

 

and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local

 

subnet. For more information, see the about_Remote_Troubleshooting Help topic.

 

At C:\SWSC Office 365 Scripts\Office 365\Students_Provision_Disable_Services.ps1:6 char:12

 

+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "h ...

 

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException

 

+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed

 

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:\SWSC Office 365 Scripts\Office 365\Students_Provision_Disable_Services.ps1:7 char:18

 

+ Import-PSSession $Session

 

+ ~~~~~~~~

 

+ CategoryInfo : InvalidData: (:) [import-PSSession], ParameterBindingValidationException

 

+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand

Posted

I've tried:

 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection

Import-PSSession $Session

Get-User -RecipientTypeDetailsUserMailbox | where {$_.Title -eq "Student User"} | Set-CASMailbox -ActiveSyncEnabled $False

 

Still the same issue

Posted

If you want to connect to both Azure Active Directory & Exchange Online at the same time this will do what you want:

 

Import-Module msonline

$cred = Get-Credential

Connect-MsolService -cred $cred

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection

Import-PSSession $Session

 

Regards,

James.

Posted

If you are running a script that contains variables '$something' and this variable is not set within the script you are running then you need to ensure that before you run the script that the variable is set globally so that when a script is run it can get the variable.

 

The error your getting is stating that $session equal $null and so therefore when the script attempts to carry out the action, because it can't find anything in $session it throws an exception.

 

James.

Posted

Import-Module msonline

$cred

= Get-Credential

Connect-MsolService

-cred $cred

$Session

= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection

Import-PSSession

$Session

 

 

 

Get-User

-RecipientTypeDetailsUserMailbox | where {$_.Title -eq "Student User"} | Set-CASMailbox -ActiveSyncEnabled $False

 

 

Capture.JPG

Posted (edited)

Stephen,

 

The syntax in the command you are using is not correct

 

Get-User -RecipientTypeDetailsUserMailbox

 

This should be

 

Get-User -RecipientTypeDetails UserMailbox | where {$_.Title -eq "Student User"} | Set-CASMailbox -ActiveSyncEnabled $false

 

In terms of the error message your getting, looks like your have connectivity issues more than anything else or/ it's connecting to an on-premise exchange server? :/ anyway above is the correct syntax for the command. :-)

 

James.

Edited by EduTech
Posted (edited)

Haahaa School Boy error:

 

netsh WINHTTP import proxy source =ie

 

 

Now all hunky dory:

Import-Module msonline

$cred = Get-Credential

Connect-MsolService -cred $cred

$Session = New-PSSession -ConfigurationNameMicrosoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-Credential $cred -Authentication Basic -AllowRedirection

Import-PSSession $Session

 

cmdlet Get-Credential at command pipeline position1

Supply values for the following parameters:

WARNING: Your connection has been redirected to thefollowing URI: "https://podXXXXXpsh.outlook.com/powershell-liveid?PSVersion=4.0"

WARNING: The names of some imported commands fromthe module 'tmp_cuyndfqy.jnd' include unapproved verbs that might make themless discoverable. To find the

commands with unapproved verbs, run theImport-Module command again with the Verbose parameter. For a list of approvedverbs, type Get-Verb.

 

ModuleType Version Name ExportedCommands

---------- ------- ---- ----------------

Script 1.0 tmp_cuyndfqy.jnd {Add-AvailabilityAddressSpace, Add-DistributionGroupMember,Add-MailboxFolderPermission, Add-Ma...

 

 

Edited by StephenHardy
Posted
Haahaa School Boy error:

 

netsh WINHTTP import proxy source =ie

 

 

Now all hunky dory:

Import-Module msonline

$cred = Get-Credential

Connect-MsolService -cred $cred

$Session = New-PSSession -ConfigurationNameMicrosoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-Credential $cred -Authentication Basic -AllowRedirection

Import-PSSession $Session

 

cmdlet Get-Credential at command pipeline position1

Supply values for the following parameters:

WARNING: Your connection has been redirected to thefollowing URI: "https://podXXXXXpsh.outlook.com/powershell-liveid?PSVersion=4.0"

WARNING: The names of some imported commands fromthe module 'tmp_cuyndfqy.jnd' include unapproved verbs that might make themless discoverable. To find the

commands with unapproved verbs, run theImport-Module command again with the Verbose parameter. For a list of approvedverbs, type Get-Verb.

 

ModuleType Version Name ExportedCommands

---------- ------- ---- ----------------

Script 1.0 tmp_cuyndfqy.jnd {Add-AvailabilityAddressSpace, Add-DistributionGroupMember,Add-MailboxFolderPermission, Add-Ma...

 

 

 

;-) so it was connectivity then. It's okay you'll be surprised the amount of people that actually have this issue because they forget about the proxy servers.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...