header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Launching a powershell script from vbscript with different credentials
Last Post 06 Jul 2010 06:47 AM by PoSherLife. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
Robert KirchhofUser is Offline
New Member
New Member
Posts:13
Avatar

--
06 Jul 2010 05:12 AM
    Finally after many attempts, the line below does what it should.  Now I need to get the correct syntax to run it with alternate credentials.

    objShell.Run("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command C:\Create2007Mailbox.ps1 " + "'" + strCanonicalName + "'" + " " + "'" + strUser + "'")

    All I want to do is launch the powershell shell (From a VBS script) as a different user.

    The PowerShell Script "Create2007Mailbox.ps1" uses the enable-mailbox cmdlet to create a exchange 2007 mailbox.  It’s launched from within a VBScript that creates new users accounts.  The vbscript has imbedded credentials it uses to create the account, but the PowerShell script is executed under the current users credentials.  How can I modify the line above to call the script as another user?

     

    Any assistance would be greatly appreciated.

    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    06 Jul 2010 06:47 AM
    you could utilize RunAs.exe in your vbs:

    Const conUser = "DOMAIN\user"
    Const conPwd = "password~" 'The tild(~) simulates an enter key press.

    objShell.Run("runas /user:" & conUser & " " & chr(34) & "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
    -noexit -command C:\Create2007Mailbox.ps1 " & "'" & strCanonicalName & "'" & " " & "'" & strUser & "'")

    objShell.AppActivate "Runas"

    WScript.Sleep 100

    objShell.SendKeys conPwd
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer