2016-07-13 5 views
0

次のスクリプトが自動にすべてexample*のプロセスを停止する必要がなく、.txtファイルにあるものはno_stop.txt呼び出されていないことを停止します。例が含まれているプロセスを停止し、それ

$no = get-content no_stop.txt; 
$yes = get-process example* | Select-Object name >> text2.txt; 

if($no) 
{ 
for($i1=0; $i1 -le $no.length; $i1++) 
{ 
    for($i2=0; $i2 -le $yes.length;$i2++) 
    { 
     if($no[$i1] -eq $yes[$i2]) 
     { 
      $yes[$i2]=''; 

     } 
     if($yes[$i2] -eq 'Name' >> text2.txt) 
     { 
      $yes[$i2]=''; 
     } 
     if($yes[$i2] -eq '-' >> text2.txt) 
     { 
      $yes[$i2]=''; 
     } 
    } 
} 
} 

for($i1=0; $i1 -le $yes.length;$i1++) 
{ 
if($yes[$i1]) 
{ 
     $yes[$i1] = $yes[$i1] -replace '\s','' >>test.txt; 
     Stop-Process $yes[$i1] -Force >>test.txt; 
} 
} 
$yes >> test.txt; 

どういうわけか、このdoesnの `tなぜ、私に説明することができますか?

答えて

0

$no = @(Get-Content C:\File\Path\no_start.txt) -join '|' Get-Service example* | ?{$_.Name -notmatch $no} | Start-Service -PassThru

も正常に動作し、それが乗算ラインを読むことができます。

1

あなたはこのロット簡素化することができます:

$no = get-content no_stop.txt; 
Get-Process example* | Where { $no -notcontains $_.Name } | kill -Force 
+0

no_stop.txtのパスを完全修飾する必要があります。エラーを取得するには、PowerShell_ISEを起動し、スクリプトを開いてF5キーを押してください。 –

+0

次に、powershellからスクリプトを実行してください: '&" path_to_your_script.ps1 "' –

+0

no_stop.txtの内容を私達に教えてください。 –

関連する問題