viewpoint-particle

Author Topic: Call powershell cmdlet  (Read 151 times)

DGOODALE

  • 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 http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/How~To+Run~PowerShell~Command.txt  What am I doing wrong?

   samaccountname="bilbba"
   FullName="Bilbo Baggins"
   UPN="Bilbo.Baggins@vsp.com"
   pwd="asdfasdf"
   first="Bilbo"
   last="Baggins"
   displaynm="Bilbo Baggins"
   alias="bilbba"
   orgunit="domain.com/users"
 ;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)

td

  • Tech Support
  • *****
  • Posts: 2538
    • 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 '.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


DGOODALE

  • 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 http://someserver.domain.com/PowerShell/ -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.

stanl

  • Pundit
  • *****
  • Posts: 777
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.


http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/getarticle.web+WinBatch/dotNet/EWS/Mail+Simple~EWS~Email~Message.txt

Another avenue might be the WB ADSI Extender.