jblackburnHWGA Posted November 16, 2021 Posted November 16, 2021 I'm having trouble with a very simple script. I'm failing at the first hurdle lol I think its how i'm going about the ps session We're using exchange online I want to switch a rule on and off without having to do it manually as i keep forget to do it. The rule is a simple one to stop the kids e-mailing each other. With prohibit this in the day as it causes issues. We disable it at night so the students can share resources etc. My code is $UserCredential = Get-Credential$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirectionImport-PSSession $SessionEnable-TransportRule "Student email block" I got this from a few sources one being from this forum. So far i'm not able to connect to the exchange session. Am i using an our of date line. Any help would be really appreciated. Scripts aren't my strong suit
Cache Posted November 16, 2021 Posted November 16, 2021 So it should work, not sure if it's just the way you've copied it but it should be like this: $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session Enable-TransportRule "Student email block" If you have MFA enabled on your account then this won't work as you'll need to use the Exchange Online v2 Powershell: https://docs.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps#install-and-maintain-the-exo-v2-module Once that's installed, the script would change slightly to become something like below: import-module ExchangeOnlineManagement $UserCredential = Get-Credential Connect-ExchangeOnline -Credential $UserCredential Enable-TransportRule "Student email block" I'm having trouble with a very simple script. I'm failing at the first hurdle lol I think its how i'm going about the ps session We're using exchange online I want to switch a rule on and off without having to do it manually as i keep forget to do it. The rule is a simple one to stop the kids e-mailing each other. With prohibit this in the day as it causes issues. We disable it at night so the students can share resources etc. My code is $UserCredential = Get-Credential$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirectionImport-PSSession $SessionEnable-TransportRule "Student email block" I got this from a few sources one being from this forum. So far i'm not able to connect to the exchange session. Am i using an our of date line. Any help would be really appreciated. Scripts aren't my strong suit
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now