locked
SCRIPT NOT RUNNING RRS feed

  • Question

  • Hello all,

    I have created a small powershell script to clear the content using the exe file.

    It executed without any error, but when I check the respective logs the exe is not triggered during the execution.

    $computerlist = Get-Content -Path c:\temp\input.txt

    foreach ($computername in $computerlist)

    {
    $filelist = Get-Content -Path C:\temp\list.txt
    ForEach ($value in $filelist)
    {
    $contentname, $contentversion = $value.Split(",")
    $command = "'C:\program files\1e\nomadbranch\cachecleaner.exe' -deletepkg=$contentname -pkgver= $contentversion"


    $process = [WMICLASS]"\\$computername\ROOT\CIMV2:win32_process" 
    $result = $process.Create($command)



    }

    Plese correct the script.

    Thanks 

    Suresh M


    THANKS SURESH M

    Monday, August 13, 2018 6:35 AM

All replies

  • You can't use the single quotes in the double quotes for the $command, it won't launch the application.

    For instance, give this a shot:

    $command = "'C:\Program Files (x86)\Internet Explorer\iexplore.exe' bing.com"
    $process = [WMICLASS]"\\$computername\ROOT\CIMV2:win32_process" 
    $result = $process.Create($command)


    Then try:

    $command = "C:\Program Files (x86)\Internet Explorer\iexplore.exe bing.com"
    $process = [WMICLASS]"\\$computername\ROOT\CIMV2:win32_process" 
    $result = $process.Create($command)

    See how the first codeblock won't open Internet Explorer, and the second codeblock will?

    Monday, August 13, 2018 8:07 AM
  • You could try to stay with pure Powershell syntax. ... like this:
    $computerlist = Get-Content -Path c:\temp\input.txt
    foreach ($computername in $computerlist){
        $filelist = Get-Content -Path C:\temp\list.txt
        ForEach ($value in $filelist){
            $contentname, $contentversion = $value.Split(",")
            Start-Process -FilePath 'C:\program files\1e\nomadbranch\cachecleaner.exe' -ArgumentList "-deletepkg=$contentname -pkgver= $contentversion"
        }
    }
    If that does not change anything you could try to catch the output of the executable with the parameters -RedirectStandardOutput and -RedirectStandardError for the Start-Process. If that does not help either you might re-check the content of your input files.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Monday, August 13, 2018 8:11 AM
    Monday, August 13, 2018 8:10 AM
  • You could try to stay with pure Powershell syntax. ... like this:
    $computerlist = Get-Content -Path c:\temp\input.txt
    foreach ($computername in $computerlist){
        $filelist = Get-Content -Path C:\temp\list.txt
        ForEach ($value in $filelist){
            $contentname, $contentversion = $value.Split(",")
            Start-Process -FilePath 'C:\program files\1e\nomadbranch\cachecleaner.exe' -ArgumentList "-deletepkg=$contentname -pkgver= $contentversion"
        }
    }
    If that does not change anything you could try to catch the output of the executable with the parameters -RedirectStandardOutput and -RedirectStandardError for the Start-Process. If that does not help either you might re-check the content of your input files.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    Start-Process will only work if you add it in a ScriptBlock within an Invoke-Command -ComputerName $ComputerName, since he's trying to execute it remotely.
    Monday, August 13, 2018 8:15 AM
  • Here are several methods for Remotely Invoking Application with PowerShell explained.
    Monday, August 13, 2018 8:17 AM
  • Start-Process will only work if you add it in a ScriptBlock within an Invoke-Command -ComputerName $ComputerName, since he's trying to execute it remotely.
    You are totally right ....  I should not answer questions before I had my first coffee ;-)
    $computerlist = Get-Content -Path c:\temp\input.txt
    foreach ($computername in $computerlist){
        $filelist = Get-Content -Path C:\temp\list.txt
        ForEach ($value in $filelist){
            $contentname, $contentversion = $value.Split(",")
            Invoke-Command -ComputerName $computername -ScriptBlock {
                Start-Process -FilePath 'C:\program files\1e\nomadbranch\cachecleaner.exe' -ArgumentList "-deletepkg=$USING:contentname -pkgver= $USING:contentversion"
            }
        }
    }
    ... this should do the trick ... actually


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Monday, August 13, 2018 8:27 AM
  • Thanks for your response.

    I have tried this method already, but its ending with WINRM error shown below.

    '

    [localhost] Connecting to remote server localhost failed with the following error message: The WinRM client cannot process the request. It cannot determine the content type of the HTTP 
    response from the destination computer. The content type is absent or invalid. For more information, see the about_Remote_Troubleshooting Help topic.
        + CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : -2144108297,PSSessionStateBroken'

    THANKS SURESH M

    Monday, August 13, 2018 8:55 AM
  • Thanks for your response.

    I have tried this method already, but its ending with WINRM error shown below.

    '

    [localhost] Connecting to remote server localhost failed with the following error message: The WinRM client cannot process the request. It cannot determine the content type of the HTTP 
    response from the destination computer. The content type is absent or invalid. For more information, see the about_Remote_Troubleshooting Help topic.
        + CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : -2144108297,PSSessionStateBroken'

    THANKS SURESH M

    Did you enable/configure Windows Remote Management on the target computers? If not you can't manage them remotely.

    Run WinRM Quickconfig or Enable-PSRemoting on the target machines first. 

    Monday, August 13, 2018 11:07 AM