我的powershell脚本使用了大量的处理器时间 [英] my powershell script uses a lot of processor time
本文介绍了我的powershell脚本使用了大量的处理器时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的powershell脚本使用了大量的处理器时间。
i每分钟看到100%的峰值,脚本运行每分钟。
任何提示减少处理器饥饿的提示?
这是代码:
$ input_path ='C:\ mango \web \ system \ * .tmp'
$ fileDirectory ='C:\ mango \\ \\ web\system'
$ output_file ='C:\ mango \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\内容C:\ mango\web \A\output1.txt
清除内容C:\ mango \web \A\output2.txt
foreach( Get-ChildItem $ fileDirectory中的$ file)
{
$ filePath = $ fileDirectory +\+ $ file;
$ A =(get-content $ filePath -totalcount 3)[ - 1]
$ B = get-content $ filePath -tail 1
Add-Content $ output_file $ A
$ parts = $ B.split(;)
Add-Content $ output_file $ parts [1]
}
$ yesterday =(Get-Date).date.AddDays( - 1)
Get-ChildItem C:\logs \ -recurse |
Get-ChildItem |其中{$ _。CreationTime.Date -eq $昨天} | get-content -tail 1 |添加内容c:\ mango \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
添加内容C:\ mango \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ output1.txt)-replace',',。 |添加内容C:\ mango \web \A\output2.txt
提前感谢
解决方案
input_path ='C:\ mango \web \ system \ * .tmp'
fileDirectory ='C:\ mango \web \ system'
output_file ='C:\ makeo \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Hi,
my powershell script uses a lot of processor time.
i see peaks of 100% each minute, the script runs each minute.
any tips to make it less processor hungry ?
this is the code:
$input_path = ‘C:\mango\web\system\*.tmp’
$fileDirectory = 'C:\mango\web\system'
$output_file = ‘C:\mango\web\A\output.txt’
Clear-Content $output_file
Clear-Content C:\mango\web\A\output1.txt
Clear-Content C:\mango\web\A\output2.txt
foreach($file in Get-ChildItem $fileDirectory )
{
$filePath = $fileDirectory + "\" + $file;
$A=(get-content $filePath -totalcount 3)[-1]
$B=get-content $filePath -tail 1
Add-Content $output_file $A
$parts = $B.split(";")
Add-Content $output_file $parts[1]
}
$yesterday =(Get-Date).date.AddDays(-1)
Get-ChildItem C:\logs\ -recurse |
Get-ChildItem | where { $_.CreationTime.Date -eq $yesterday } | get-content -tail 1 | Add-Content c:\mango\web\A\output.txt
$c=(Get-Content $output_file) -Join ";"
Add-Content C:\mango\web\A\output1.txt $c
(get-content C:\mango\web\A\output1.txt) -replace ',',"." | Add-content C:\mango\web\A\output2.txt
thanks in advance
解决方案
input_path = ‘C:\mango\web\system\*.tmp’
fileDirectory = 'C:\mango\web\system'
output_file = ‘C:\mango\web\A\output.txt’ Clear-Content
这篇关于我的powershell脚本使用了大量的处理器时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文