V
V
Vertizo2020-04-01 16:48:46
PowerShell
Vertizo, 2020-04-01 16:48:46

Adding users by script to a group in Exchange Online?

Good afternoon!
I'm trying to add a script to office365, to certain groups of new users, but for some reason it returns an error -
The name "Get-DistributionGroupMember" is not recognized as the name of a cmdlet, function, script file or executable program.
The script itself:
$PlainPassword = "********"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
$UserName = "[email protected]"
$Credentials = New-Object System.Management.Automation.PSCredential `
-ArgumentList $UserName, $SecurePassword
$session = New-PSSession -ConfigurationName Microsoft.Exchange - ConnectionUri https://ps.outlook.
$alias="[email protected]"

Get-DistributionGroupMember –identity “[email protected]” | ft name, primarysmtpaddress

Add-DistributionGroupMember -Identity "[email protected]" -Member $alias
Remove-PSSession $Session

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-04-01
@Vertizo

Are you sure the connection was successfully established?
And you missed import-pssession $session -allowclobber

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question