Hi,I am getting an error while trying to run a powershell cmdlet from a custom imported module using staf utility. If I start the powershell from command line and run same command without staf it is working fine, I get the desired output. This is the command with problem:
staf local process start shell "powershell -c %c" command "ipmo 'C:\Program Files\Tivoli\FlashcopyManager\FmModuleExc.dll';Get-DpExcConfig | out-file -FilePath C:\file.txt" wait returnstderr returnstdout workdir "C:\Program Files\Tivoli\flashcopymanager" sameconsole
Response
}
]
}
If I run this command then everything is ok
powershell -command "& {ipmo 'C:\Program Files\Tivoli\FlashcopyManager\FmModuleExc.dll';Get-DpExcConfig | out-file -FilePath C:\file.txt}"
Note: If I am using Powershell default modules from Microsoft using staf utility then everything is fine.So my question is: It is something special that should be set up in Staf.cfg file in order to run successful a cmdlet imported from a custom module. So far I've updated the PsModulePath variable with the path to dll file, but it didn't work.
Any help related to this will be appreciated.
Thanks,
Nicolae Radulet
When you submit a STAF PROCESS START request to run a command, the command will be run in the environment that STAFProc is running in, not in the environment of the command prompt from which you submitted the STAF PROCESS START request. So, my guess is that there is an environment variable set in the environment of your command prompt that allows powershell to find the Get-DpExcConfig dll file (as you are getting error "FullyQualifiedErrorId : Get-DpExcConfig" which appears to indicate that powershell cannot find this file). You said you updated the PsModulePath variable with the path to dll file. Is this an environment variable that allows powershell to find the path to the Get-DpExcConfig file? If so, then you either need update this environment variable in the environment in which STAFProc is running (e.g. set it and then restart STAFProc in this environment), or you can use the ENV option on a PROCESS START request to set an environment variable. See section "8.13 Process Service" in the STAF User's Guide at http://staf.sourceforge.net/current/STAFUG.htm#HDRPROCSRV for more information about the ENV option on a PROCESS START request.
Also, I'm not a PowerShell user, but the command that you said works at the command line without using STAF does not appear to be the same command that you're trying to run via a STAF PROCESS START request as the command you ran via a command prompt started with "& {ipmo".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,I am getting an error while trying to run a powershell cmdlet from a custom imported module using staf utility. If I start the powershell from command line and run same command without staf it is working fine, I get the desired output. This is the command with problem:
staf local process start shell "powershell -c %c" command "ipmo 'C:\Program Files\Tivoli\FlashcopyManager\FmModuleExc.dll';Get-DpExcConfig | out-file -FilePath C:\file.txt" wait returnstderr returnstdout workdir "C:\Program Files\Tivoli\flashcopymanager" sameconsole
Response
{
Return Code: 1
Key : <None>
Files :
{
Return Code: 0
Data :
}
{
Return Code: 0
Data : Get-DpExcConfig : Could not load file or assembly 'DpExcEngine,
Version=1.0.5373.15360, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. The system cannot find the file specified.At line:1 char:65
+ ipmo 'C:\Program Files\Tivoli\FlashcopyManager\FmModuleExc.dll';Get-DpExcConfig ...
+
~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (:) [Get-DpExcConfig, FileNotFoundEx
ception
+ FullyQualifiedErrorId : Get-DpExcConfig,IBM.Tivoli.TSM.Cmdlets.Exchange.
GetDpExcConfig
}
]
}
If I run this command then everything is ok
powershell -command "& {ipmo 'C:\Program Files\Tivoli\FlashcopyManager\FmModuleExc.dll';Get-DpExcConfig | out-file -FilePath C:\file.txt}"
Note: If I am using Powershell default modules from Microsoft using staf utility then everything is fine.So my question is: It is something special that should be set up in Staf.cfg file in order to run successful a cmdlet imported from a custom module. So far I've updated the PsModulePath variable with the path to dll file, but it didn't work.
Any help related to this will be appreciated.
Thanks,
Nicolae Radulet
When you submit a STAF PROCESS START request to run a command, the command will be run in the environment that STAFProc is running in, not in the environment of the command prompt from which you submitted the STAF PROCESS START request. So, my guess is that there is an environment variable set in the environment of your command prompt that allows powershell to find the Get-DpExcConfig dll file (as you are getting error "FullyQualifiedErrorId : Get-DpExcConfig" which appears to indicate that powershell cannot find this file). You said you updated the PsModulePath variable with the path to dll file. Is this an environment variable that allows powershell to find the path to the Get-DpExcConfig file? If so, then you either need update this environment variable in the environment in which STAFProc is running (e.g. set it and then restart STAFProc in this environment), or you can use the ENV option on a PROCESS START request to set an environment variable. See section "8.13 Process Service" in the STAF User's Guide at http://staf.sourceforge.net/current/STAFUG.htm#HDRPROCSRV for more information about the ENV option on a PROCESS START request.
Also, I'm not a PowerShell user, but the command that you said works at the command line without using STAF does not appear to be the same command that you're trying to run via a STAF PROCESS START request as the command you ran via a command prompt started with "& {ipmo".
Hi Sharon,
Sorry for late response but I was working to find a better solution and I think I found it. This is the command that I've used:
C:\STAF>staf local process start shell "powershell -c %c" command ""Invoke-Command -computername localhost {ipmo C:\Program` Files\Tivoli\Flashcopymanager\FmMod
uleExc.dll;Get-DpExcConfig}"" workdir "C:\Program Files\Tivoli\FlashcopyManager" wait returnstderr returnstdout
Response
{
Return Code: 0
Key : <None>
Files : [
{
Return Code: 0
Data :
PSComputerName : localhost
RunspaceId : 6c21e9ed-8b52-4751-9536-49a6bf39ecb3
BACKUPDESTination : TSM
CLIENTAccessserver :
DAGNODe :
DATEformat : 1
LANGuage : ENU
LOCALDSMAgentnode : TOADVM3-EXC2010
LOGFile : tdpexc.log
LOGPrune : 60
MOUNTWait : Yes
NUMberformat : 1
REMOTEDSMAgentnode :
TEMPDBRestorepath :
TEMPLOGRestorepath :
TIMEformat : 1
IMPORTVSSSNAPSHOTSONLYWhenneeded : No
STOREMAILBOXInfo : Yes
STOPservicesonir : Yes
USEADFORALIASSEARCH :
]
}
C:\STAF>