0

PS Version: 2.0

Hi All,

I am trying to run the batch file from a powershell script using psexec.

The script runs fine while triggering manually or using windows task scheduler; however, powershell get triggered from Control-m but do not complete the part where psexec is used. The rest part of powershell script runs fine.

Below is the function which is not working, besides it do not give any error, it just freezes the script:

function Archive_Logs($Server_Name,$Tool_Path,$Name)
{
    foreach($TPath in $Tool_Path){
        C:\Windows\System32\PsExec.exe \\$Server_Name "$TPath\ziplogs.bat"
        if($LastExitCode -eq 0)
        {
            "$Name Server logs archive Started successfully at $(Get-Date)" | Out-File $LOGFILE -Append
        }
    }
 }

The account used by Control-M is local admin on the servers.

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • just taking a shot in the dark here... have you verified what `\\$Server_Name` shows at that step and can you access the server/ip that `\\$Server_Name` is calling. May be a firewall issue or you may need to open PowerShell as an administrator and launch the script. – ShanayL Aug 31 '17 at 14:08

1 Answers1

0

How are you calling the Powershell? When you create a .bat file and invoke it from there it fixes a lot of issues, e.g, bat file contains 1 line -

powershell -command "& C:\MyPSscripts\archiver.ps1"

See -

https://communities.bmc.com/thread/117415

Mark
  • 316
  • 1
  • 5