I am trying to add user in a group but I am getting error:
Add-MsolGroupMember -GroupObjectId $group1.ObjectId -GroupMemberType "User" -GroupMemberObjectId 077cf65b-4b9f-44e4-9f34-6c96a063a0df
As bunzab said, we should use Add-DistributionGroupMember to add member.
First, we should connect to exchange online powershell:
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
After that, we can use this powershell to add member, like this:
More information about connect to exchange online powershell, please refer to this link.
Related
Following is the script I used to fetch the shared mailbox list by getting adminId and password. But I want to fetch the details using the service account, can anyone help me out
$Credentials = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited | ft Name,WindowsEmailAddress
With the following command with my user admin and role impersonation can access to my account:
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking -AllowClobber
Once the connection is made, can I switch to another account?
I am trying to create folders and filters to execute the commands using New-MailboxFolder but doesn't work directly from my account. It's possible?
Thanks
Yes you can change current user. You will create another script to do what you want to do as another user. Then in your current script use this:
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Start-Process powershell.exe -Credential $UserCredential -NoNewWindow -ArgumentList "-noexit -command TheNewCreatedScriptFullPath.ps1"
What are the modules that has to be imported for this error in powershell ?
The term 'remove-distributiongroupmember' 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.
Connect to Exchange Online PowerShell
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
#Your code here
Remove-PSSession $Session
Connect to Exchange servers using remote PowerShell
Note: Substitute mailbox01.contoso.com for your own exchange server.
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mailbox01.contoso.com/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session
#Your code here
Remove-PSSession $Session
I get the error:
Remove-MsoLGroupMember : You cannot update mail-enabled groups using
this cmdlet. Use Exchange Online to perform this operation
But i have connected to a remote session and imported the exchange online module, why does it still throw error?
$credential = Get-Credential
$lyncSession = New-CsOnlineSession -Credential $credential
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Get-PSSession
Import-PSSession $exchangeSession
Remove-MsoLGroupMember -GroupObjectId $Group_GUID -GroupMemberType User -GroupmemberObjectId $GroupMembers.ObjectId
I was following this link to setup my remote connection to exchange, but i must be doing something wrong. https://technet.microsoft.com/en-us/library/dn362787(v=ocs.15).aspx
Use Remove-DistributionGroupMember instead if you are working with mail enabled security group as Remove-MsoLGroupMember works with regular security groups.
check this: https://technet.microsoft.com/en-us/library/aa998016(v=exchg.160).aspx
So I'm checking for an approach on a problem I have.
I have an e-mail from my school (Office 365) and I wanted to print the email subject of each email that's located in my inbox with PowerShell.
I already have found the method to lay a connection
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://smtp.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
function Connect-O365 {
$session365 = New-PSSession `
-ConfigurationName Microsoft.Exchange `
-ConnectionUri "https://smtp.office365.com/powershell-liveid/" `
-Credential $UserCredential
-Authentication Basic `
-AllowRedirection
Import-Module (Import-PSSession $session365 -AllowClobber) -Global
}
And have found the Get-Mailbox cmdlet.
The problem now however is that I haven't found any real examples or methods that continue to help me printing the email subjects.
I have done quite some research and didn't manage to find something like:
Get-Mailbox -Identity "user" |Select-MailBox * |Where-Object $_.MailBoxName = "Inbox"
Is this not possible or do I have to use another method?
If you have an Office365 subscription you could use the Office 365 api via their graph api endpoint
Since this is basically a REST endpoint you can use the Invoke-Webrequest or Invoke-RestMethod cmdlets.
Or more specificaly the Outlook api.
Both give you json back with you messages content like subject, to, from, and whatever.