on 10-05-2012 2:23 PM
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…
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
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
Copyright (C) Microsoft Corporation. All rights reserved.
Server is Windows 2008 R2
IDM 7.2. SP5
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.