Powershell 4.0 ISE runs scripts accordingly, but Windows Powershell terminal does not

Just when I thought I was done, I get hit with a small bug.  Okay, so I am facing an issue. The script below works fine in Powershell ISE, but when I want to execute it in  plain old Powershell command window, it does not do what it is intended to do. 

The script basically starts a performance counter that I have created. I posted a previous post about it , which I was able to resolve, but know I am left with this final bug. 

$folder = "C:\root"
$servers = @(gc $folder\perfmon_list.txt) # List of remote computers one per line


foreach ($server in $servers){

$servers = @(gc $folder\perfmon_list.txt) # List of remote computers one per line
$startprocess = Invoke-WmiMethod -computerName $server -Class Win32_Process -Name Create -ArgumentList "logman.exe start Triton_perf_$server"

}


September 9th, 2015 3:21pm

Hi,

What do you mean by 'does not do what it is intended to do'?

Perhaps this is a typo, but why are you reading your input file twice (inside of the loop, no less)?

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 3:32pm

I showed you how too start remote counters.  Here it is again:

$servers=gc $folder\perfmon_list.txt foreach ($server in $servers){ logman.exe start Triton_perf_$server -s $server }


You do not want too remote the start.  logman is designed to start counters remotely that is why it has the "-s" option.

September 9th, 2015 3:38pm

Sorry, I do have a type on script I adjusted that before after copying and pasting.  Okay, so in powershell ISE,  the script starts my performance counter as intended, when I right click, and do run with powershell, it does not start my performance counter, and errors out. Unfortunately,  the error opens, and closes immediately, so I am unable to see what is the error. At the moment, I am trying to see how I can prevent the powershell window from closing out so fast. I think I may have to screw around with a registry change.

Thanks,

Jeff 

 
Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 3:42pm

This is your  version of the script:

foreach ($server in $servers){
     $servers = @(gc $folder\perfmon_list.txt) # List of remote computers one per line
     $startprocess = Invoke-WmiMethod -computerName $server -Class Win32_Process -Name Create -ArgumentList "logman.exe start Triton_perf_$server"
}

It is wrong and won't work any

September 9th, 2015 3:44pm

jrv,

I understand that, but I have to use that same concept to create two separate scripts one to start logman and two to  stop logman. These two scripts will then be executed through scheduled task. I am attempting to retrive the error I get. I just don't understand why it works in ISE, but not the command window.

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 3:45pm

jrv,

I understand that, but I have to use that same concept to create two separate scripts one to start logman and two to  stop logman. These two scripts will then be executed through scheduled task. I am attempting to retrive the error I get. I just don't understand why it works in ISE, but not the command window.

Look at your script. It is wrong. are reading the server list.

September 9th, 2015 3:47pm

I will back track and see if I get it to work. I will use your example.  
Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 3:51pm

I was able to fix my problem in the following way: 

I used this as recommended by jrv

$servers=gc $folder\perfmon_list.txt foreach ($server in $servers){ logman.exe start Triton_perf_$server -s $server }

and the error turned out to be that I was missing my $folder variable

after Included the $folder = path

I was able to get this to work.

Thanks a lot jvr and everyone in this thread.

95% completed project.

Thanks, again

September 9th, 2015 4:24pm

what is that that you just posted?

Your explanation has nothing to do with the initial problem.

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 5:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics