Run Powershell Activity Issue

ravish2
Giga Expert

I am trying to run a powershell script through run powershell activity. i am using 2 powershell run activity in my workflow first one is working fine but the second one is not executing and giving some error. but when i am executing it on my mid server powershell then its working

P.S. - I have already checked the ecc queue and copied the script path to my mid-powershell its working there but not through run activity.

1 ACCEPTED SOLUTION

ravish2
Giga Expert

Actually the issue was with mid server account which was set to run locally. i changed it to Administrator now the script is working fine. the previous does not require any admin related jobs so that was running fine.


View solution in original post

5 REPLIES 5

michael_toresco
Kilo Explorer

Can you please give us more details about what you are trying to run and what happens?



Can you give us:


  • The Powershell script thats working
  • The powershell script thats failing
  • The error message your getting on the mid server logs
  • Any other relevant information


Thanks


########################CONTENT OF RUN POWERSHELL##############################################


E:\STC\SCRIPTS\USER_ACCOUNT_MANAGEMENT\AddPST_Outlook.ps1 ${workflow.scratchpad.hostname} ${workflow.scratchpad.username} ${workflow.scratchpad.pst}


######################################END##########################################################



###################SCRIPT WHICH IS NOT WORKING IN RUN ACTIVITY#####################################


$ComputerName=$args[0]


$user=$args[1]


$name=$args[2]


$username="STC\Administrator"


$pw = "pass@word1"


$securepw = ConvertTo-SecureString $pw -asplaintext -force


$cred = new-object -typename System.Management.Automation.PSCredential -argument $username, $securepw  


IF (!(TEST-PATH \\$ComputerName\C$\NewShare)) {NEW-ITEM \\$ComputerName\C$\NewShare -type Directory}


write-host "Folder Created"


$share = Get-WmiObject Win32_Share -List -ComputerName $ComputerName


$x=$share.create("C:\NewShare","NewShare",0)


#write-host "Share Folder Created"


Copy-Item -Path E:\STC\SCRIPTS\USER_ACCOUNT_MANAGEMENT\Client_PSTcreation.ps1 -Destination "\\$ComputerName\c$\NewShare\"


$RETDESC="File Transfer Success"


$str="`"<body><RETDESC>$RETDESC</RETDESC></body>`""


$str


#write-host "Entering into the Client Session"


Enter-PSSession -ComputerName $ComputerName -Credential $Cred


invoke-command -computername $ComputerName -filepath "\\$ComputerName\NewShare\Client_PSTcreation.ps1" -Argumentlist $ComputerName,$user,$name


Remove-Item -path "\\$ComputerName\c$\NewShare\Client_PSTcreation.ps1" -Force -Recurse


#Write-host "Files Deleted Successfully"


Exit-PSSession


###################################################END##############################################


#########################################ERROR SHOW IN ECC QUEUE###############################


<?xml version="1.0" encoding="UTF-8"?><results probe_time="10842"><result><error/>


<output>


Folder Created


</output>


<error>New-Item : Access to the path 'NewShare' is denied.At E:\STC\SCRIPTS\USER_ACCOUNT_MANAGEMENT\AddPST_Outlook.ps1:17 char:56+ IF (!(TEST-PATH \\$ComputerName\C$\NewShare)) {NEW-ITEM &lt;&lt;&lt;&lt;   \\$ComputerName\C$\NewShare -type Directory}+ CategoryInfo                   : PermissionDenied: (\\WIN7\C$\NewShare:String) [New-Item], UnauthorizedAccessException+ FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommandGet-WmiObject : Could not get objects from namespace root\cimv2. Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))At E:\STC\SCRIPTS\USER_ACCOUNT_MANAGEMENT\AddPST_Outlook.ps1:21 char:23+ $share = Get-WmiObject &lt;&lt;&lt;&lt;   Win32_Share -List -ComputerName $ComputerName+ CategoryInfo                   : ObjectNotFound: (:) [Get-WmiObject], UnauthorizedAccessException+ FullyQualifiedErrorId : INVALID_NAMESPACE_IDENTIFIER,Microsoft.PowerShell.Commands.GetWmiObjectCommandYou cannot call a method on a null-valued expression.Stack Trace:       at System.Management.Automation.ParserOps.CallMethod(Token token, Object target, String methodName, Object[] paramArray, Boolean callStatic, Object valueToSet)at System.Management.Automation.MethodCallNode.InvokeMethod(Object target, Object[] arguments, Object value)at System.Management.Automation.MethodCallNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)at System.Management.Automation.AssignmentStatementNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList&amp; resultList, ExecutionContext context)</error></result><parameters><parameter name="queue" value="output"/><parameter name="from_sys_id" value=""/><parameter name="aka" value="10.53.223.44"/><parameter name="state" value="ready"/><parameter name="sys_created_on" value="2015-05-20 06:44:48"/><parameter name="debug" value="true"/><parameter name="probe" value="ca9edfec0a0a0baa011fe82922346887"/><parameter name="skip_sensor" value="true"/><parameter name="ecc_queue" value="ad6c05c70f880a00f3df6519b1050e81"/><parameter name="name" value="Windows - Powershell (nodes: 3)"/><parameter name="table_name" value="ecc_queue"/><parameter name="agent_correlator" value="rba.632c05c70f880a00f3df6519b1050e9b"/><parameter name="topic" value="Powershell"/><parameter name="error" value=""/><parameter name="probe_name" value="Windows - Powershell"/><parameter name="sys_id" value="ad6c05c70f880a00f3df6519b1050e81"/><parameter name="from_host" value=""/><parameter name="agent" value="mid.server.STC- Backup"/><parameter name="workflow" value="2d6c05c70f880a00f3df6519b1050e81"/><parameter name="processed" value=""/><parameter name="response_to" value=""/><parameter name="source" value="localhost"/><parameter name="sequence" value="14d701141a00000001"/><parameter name="script.ps1" value="E:\STC\SCRIPTS\USER_ACCOUNT_MANAGEMENT\AddPST_Outlook.ps1 WIN7 user2 user2_05.20.2015"/></parameters></results>


#



####################################################################################################


ravish2
Giga Expert

Actually the issue was with mid server account which was set to run locally. i changed it to Administrator now the script is working fine. the previous does not require any admin related jobs so that was running fine.


Can you please elaborate what you mean by "the issue was with mid server account which was set to run locally"?



Do you mean you had it set to a local user on the MID server?