【发布时间】:2016-12-07 22:01:42
【问题描述】:
我正在运行一个 powershell 脚本,当从 ISE 运行时会输出一组值,但当通过任务调度程序运行同一任务时,它似乎添加了第二个值,该值在手动运行时不会显示。正在执行的代码如下:
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)"
手动运行脚本时,返回的输出为:
日期、内存、CPU
2016-08-02T14:09:36,15062687744,0
2016-08-02T14:09:38,15062425600,0
通过任务调度程序运行脚本时,返回的输出是:
日期、内存、CPU
2016-08-02T13:58:25,15065047040 624189440,0
2016-08-02T14:05:01,15061901312 624713728,0
不同之处在于内存,出于某种原因,它增加了额外的价值。有谁知道这是为什么?
【问题讨论】:
-
将 $memused 放到另一个文件中,这样您就可以看到它正在管理的两个进程的详细信息。
-
谢谢,这让我走上了正确的道路
标签: windows powershell scheduled-tasks windows-server-2008 windows-server-2008-r2