hi ,the following is the script to create new user mail box in office 365 trail
-------------------------------------------------------------------------------------------------------------------
$secpasswd=ConvertTo-SecureString "${AdminPassword}" -AsPlainText -Force;
$mycreds=New-Object System.Management.Automation.PSCredential("${AdminUserId}",$secpasswd);
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
https://ps.outlook.com/powershell/ -Credential $mycreds -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue;
Import-PSSession $Session -CommandName Remove-mailbox, Get-mailbox, New-Mailbox -AllowClobber -DisableNameChecking -WarningAction SilentlyContinue
| Out-Null;
get-mailbox '${Name}' | select-object name | out-null;
if($? -eq "True")
{remove-PSSession $Session; Write-Host "This mailbox already exist"; exit 1;}
else
{
get-mailbox '${UserPrincipalName}' | select-object name | out-null;
if($? -eq "True")
{remove-PSSession $Session;Write-Host "This mailbox already exist"; exit 1;} else { New-Mailbox -Alias '${Alias}' -Name '${Name}'
-FirstName '${FirstName}' -LastName '${LastName}' -DisplayName '${DisplayName}' -MicrosoftOnlineServicesID '${UserPrincipalName}' -Password (ConvertTo-SecureString -String '${UserPassword}' -AsPlainText -Force) -ResetPasswordOnNextLogon $false -WarningAction
SilentlyContinue | out-null;
if($? -eq "True") {remove-PSSession $Session; exit 0;} else {remove-PSSession $Session; write-host "Mailbox could not be created.
Check for password or UserPrincipalName."; exit 1;}
}
}
--------------------------------------
- The error which i am getting is :
Failed
Cause:
New-PSSession :
At line:3 char:17
+ $Session = New-PSSession -ConfigurationName
Microsoft.Exchange -ConnectionU ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (
https://ps.outlook.com/powershell/:Uri) [New-PSSession], PSInvalidOperationException
+ FullyQualifiedErrorId : CreateRemoteRunspace,Microsoft.PowerShell.
Commands.NewPSSessionCommand
Import-PSSession : Cannot validate argument on parameter 'Session'. The
argument is null. Supply a non-null argument and try the command again.
At line:4 char:23
+ Import-PSSession $Session -CommandName Remove-mailbox,
Get-mailbox, New-Mai ...
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBi
ndingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.ImportPSSessionCommand
get-mailbox : The term 'get-mailbox' 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 line:5 char:6
+ get-mailbox 'vinod' | select-object name | out-null;
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-mailbox:String) [], Command
NotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
get-mailbox : The term 'get-mailbox' 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 line:10 char:6
+ get-mailbox 'vinod@pesit.onmicrosoft.com' |
select-object name | out-null;
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-mailbox:String) [], Command
NotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
New-Mailbox : The term 'New-Mailbox' 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 line:12 char:90
+ ... xit 1;} else { New-Mailbox -Alias 'vinod' -Name 'vinod' -FirstName
'vinod' -Last ...
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-Mailbox:String) [], Command
NotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Remove-PSSession : Cannot validate argument on parameter 'Id'. The argument is
null. Supply a non-null argument and try the command again.
At line:13 char:84
+ ... move-PSSession $Session; write-host "Mailbox could not be created. Check
for pas ...
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Remove-PSSession], ParameterBi
ndingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.RemovePSSessionCommand
Mailbox could not be created. Check for password or UserPrincipalName.
---------------------------------------------------------------------------------------------------------
- pre requisites which i am using is:
- Microsoft Online Services Sign-in Assistant
- Windows Azure Active Directory Module
-Windows Management Framework 3.0
-SharePoint Online Management Shell
-SSH Server (Version 3.0)
-Set-ExecutionPolicy Unrestricted
Please help