cancel
Showing results for 
Search instead for 
Did you mean: 

Running VBSript / Powershel from IDM Shell Execute - nothing happens

Former Member
0 Kudos

Running Powershell command from IDM

I have a situation where I would need to run some powershell commands as different user as Logged in user in IDM server… (Exchange server rights)

I manage to get following to work from command line – but that is not working from IDM as toShell pass or ad Generic pass…

  1. Start VisualBasic script to run powershell script as different users rights
  2. Visual basic script start Powershell
  3. Powershell sets ExchangeCustomAttribute4 for user to allow automatical Mail Archival for leaver..

Commandline

cscript s:\IDM-importfiles\ExMerge\1-Start\Exmerge-start.vbs DOMAIN\Exchadmin password USERtoREMOVE ArchiveMail

VBS Script Exmerge-start.vbs

Option explicit

Dim WshShell, var1, var2, var3, var4, cmd

Set WshShell = WScript.CreateObject("WScript.Shell")

var1 = WScript.Arguments.Item(0)

var2 = WScript.Arguments.Item(1)

var3 = WScript.Arguments.Item(2)

var4 = WScript.Arguments.Item(3)

cmd = "runas /user:" & var1 & " /noprofile ""powershell S:\IDM-importfiles\ExMerge\1-Start\Exmerge-start.ps1 " & var3 & " " & var4

  1. WshShell.Run(cmd) 'Run Powershell command 
  2. WScript.Sleep 100
  3. WshShell.SendKeys var2&"~" 'send password  
  4. WScript.Sleep 100

Powershell script Exmerge-start.ps1

# Load of Exchange management Snapins for Exchange 2007

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

# Process Commandline Arguments

$username = $args[0]

$customattribute4 = $args[1]

#Run Exchange command

Set-Mailbox -Identity $username -CustomAttribute4 $customattribute4

----------------------------------------------------------------------------------------------------

---- As I said this is successfully ran if started from Command prompt --------

----------------------------------------------------------------------------------------------------

---------------------------------- But not from IDM -----------------------------------------

----------------------------------------------------------------------------------------------------

And here is two alternative ways I have tried to start command from IDM

To Shell Execute

Does not give any error – looks from log that it has done well but nothing changed on Exchange

Repository constants and whole command line looks OK ..

toGeneric

exmerge_start javascript

// Main function: exmerge_start

function exmerge_start(Par){

      //Example calling DSE internal function

//uStop("Terminated by user");

     usermskey = Par.get("MSKEY");

      usermskeyvalue = Par.get("MSKEYVALUE");

      user = Par.get("USER");

      password  = Par.get("PASSWORD");

      exmerge  = Par.get("EXMERGE");

      startcommand = Par.get("STARTCOMMAND");

      uInfo("User to be ExMerged: " + usermskeyvalue);

      uInfo("Username to start command: " + user);

      uInfo("Value to ExhangeCustomAttribute4: " + exmerge);

      uInfo("Start command: " + startcommand)

      command = "cscript " + startcommand + " " + user + " " + password + " " + usermskeyvalue + " " + exmerge

      uInfo("Command to run: " + command);

      Outstring = uShell(command, 1, 2);

      uInfo("Result: " + Outstring);

      return ;

}

And log for this

  1. 05.10.2012 12:52:46 :I:User to be ExMerged: USERtoREMOVE
  2. 05.10.2012 12:52:46 :I:Username to start command: DOMAIN\exchadmin
  3. 05.10.2012 12:52:46 :I:Value to ExhangeCustomAttribute4: ArchiveMail
  4. 05.10.2012 12:52:46 :I:Start command: s:\IDM-importfiles\ExMerge\1-Start\Exmerge-start.vbs
  5. 05.10.2012 12:52:46 :I:Command to run: cscript s:\IDM-importfiles\ExMerge\1-Start\Exmerge-start.vbs DOMAIN\exchadmin password USERtoREMOVE ArchiveMail
  6. 05.10.2012 12:52:47 :I:Shell function output: Microsoft (R) Windows Script Host Version 5.8

Copyright (C) Microsoft Corporation. All rights reserved.

  1. 05.10.2012 12:52:47 :I:Shell function 'cscript s:\IDM-importfiles\ExMerge\1-Start\Exmerge-start.vbs DOMAIN\exchadmin password USERtoREMOVE ArchiveMail' terminated with exit code 0
  2. 05.10.2012 12:52:47 :I:Result: 0
  3. 05.10.2012 12:52:47 :X:exit ToGeneric exitPass
  4. 05.10.2012 12:52:47 :X:To Generic time spent in init 0.393 seconds.
  5. 05.10.2012 12:52:47 :X:To Generic time spent in fetchEntries 0.069 seconds.
  6. 05.10.2012 12:52:47 :X:To Generic time spent in preparing data 0.0090 seconds.
  7. 05.10.2012 12:52:47 :X:To Generic time spent in putNextEntry 0.851 seconds.
  8. 05.10.2012 12:52:47 :X:To Generic time spent in setEntryOK/SetEntryFailed 0.0060 seconds.
  9. 05.10.2012 12:52:47 :X:To Generic total time spent in scripts 0.849 seconds.
  10. 05.10.2012 12:52:47 :I:To Generic pass completed in 1.361 seconds.
  11. 05.10.2012 12:52:47 :I:Handled: 1 Added: 1

Server is Windows 2008 R2

IDM 7.2. SP5

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member2987
Active Contributor
0 Kudos

Veli-Matti,

Have you tried running the script under a different dispatcher with the credentials you require for this script?

Also, I just scanned the scripts, but is it possible to run everything from just powershell and not from the VB wrapper?

Matt

Former Member
0 Kudos

Reason I started with VB Script was to get elevated rights...

But your suggestion running with different Dispatcher sounds good - I must try that ...

Thanks

V-M

former_member2987
Active Contributor
0 Kudos

Any time.  Did this help?

M