Author Topic: Call powershell cmdlet  (Read 515 times)


  • Newbie
  • *
  • Posts: 2
Call powershell cmdlet
« on: June 11, 2018, 04:37:26 pm »
Ok this is driving me crazy and taking far to long to do and should be simple.  I can run the cmdlet in a ps console and it works but I can't get it called from WB.  It is supposed to create an exchange mbx in an hybrid environment.  I have tried almost every combination of quotes I can think of to get this to work.  Exchsession.ps1 makes that credentialed connection to Exch. and that functions fine.  I used this as a starter  What am I doing wrong?

   FullName="Bilbo Baggins"
   displaynm="Bilbo Baggins"
 ;RunWait("powershell.exe", 'c:\temp\newcsr\exchsession.ps1')

   pwrshl_cmd =  "New-RemoteMailbox -UserPrincipalName '%upn%' -Alias '%samaccountname%' -Name '%fullname%' -FirstName '%first%' -LastName '%last%' -DisplayName '%displaynm%' -OnPremisesOrganizationalUnit '%orgunit%' -Password (ConvertTo-SecureString '%pwd%' -AsPlainText -Force) -ResetPasswordOnNextLogon $true"
   RunWait("powershell.exe", '-command':pwrshl_cmd)


  • Tech Support
  • *****
  • Posts: 2849
    • WinBatch
Re: Call powershell cmdlet
« Reply #1 on: June 11, 2018, 05:16:48 pm »
One possible issue is the lack of a space after the '-command' switch, i.e., '-command '.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade


  • Newbie
  • *
  • Posts: 2
Re: Call powershell cmdlet
« Reply #2 on: June 11, 2018, 06:37:03 pm »
Ok, this probably isn't as straight forward as I thought it would be...
The full story... I have to create user accounts in bulk using an import spec file.  Each user has a line with all the attributes needed to create the account / mbx.
I have to establish a session with 0365, easy enough:
    $UserCredential = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Authentication Kerberos -Credential $UserCredential
    Import-PSSession $Session  -AllowClobber

However I have to continue to use that session for subsequent calls to New-RemoteMailbox which is where I believe this falls short as I use the new-remotemailbox command as a call in a loop that processes all users in the file.


  • Pundit
  • *****
  • Posts: 889
Re: Call powershell cmdlet
« Reply #3 on: June 12, 2018, 02:39:48 am »
Not sure if this helps but the WB CLR can be used to connect to exchange.  The link below illustrates this with a simple email. Possibly it could be modified to process the loop for remote mailbox entries.

Another avenue might be the WB ADSI Extender.