0

我正在运行powershell脚本,当从ISE运行时输出一组值,但是当通过任务计划程序运行同一任务时,它似乎添加了第二个值在手动运行时不显示。多数民众赞成被执行的代码如下:powershell脚本通过计划任务执行时产生的奇怪结果

import-module WebAdministration 

$app_pool_name = <<app_pool_name_goes_here>> 

$memused = "" 
$cpuused = "" 

$datetime = get-date -format s 
$memused = Get-WmiObject Win32_process | where CommandLine -Match "$app_pool_name" 
$id = dir IIS:\AppPools\$app_pool_name\WorkerProcesses\ | Select-Object -expand processId 
$cpuUsed = Get-WmiObject Win32_PerfFormattedData_PerfProc_Process | where IDProcess -Match $id 

Add-Content -path C:\Winsys\PSOutput\$app_pool_name-CPU-RAM_test.txt -value "$datetime,$($memUsed.workingsetsize),$($cpuUsed.PercentProcessorTime)" 

运行脚本时手动返回的输出是:

日期,MEM,CPU

2016-08-02T14:09:36,15062687744 ,0

2016-08-02T14:09:38,15062425600,0

当通过任务调度运行该脚本返回的输出是:

日期,MEM,CPU

2016-08-02T13:58:25,15065047040 624189440,0

2016-08-02T14:05:01,15061901312 624713728,0

的区别作为Mem,出于某种原因它增加了额外的价值。有人知道为什么吗?

+1

下降$ memused到另一个文件,所以你可以看到这两个过程的细节是管理回暖。 –

+0

谢谢,这让我走上了正轨 – Saf

回答

0

原来这是我自己的错误,有两个名称非常相似的应用程序池,-match正在捕获两者。但它仍然没有解释为什么它只显示在任务调度程序中,而不是在ISE中显示。嗯,现在通过添加“ - and -notmatch”文本部分来解决。

E.g.

Get-WmiObject Win32_process | where {$_.CommandLine -Match "$app_pool_name" -and $_.CommandLine -notmatch "<<text in other command line>>"} 

添加注释