2013-03-19 5 views
0

그래서 저는 IIS 로그를 구문 분석 한 다음 Powershell 스크립트를 작성한 다음 전자 메일, 보고서 및 기타 유용한 정보를 작성합니다. 글쎄, 나는 C# 콘솔 앱에서 그 일을 수행하고있다. 내 코드를 게시하기 전에 한 가지를 명확하게하고 싶었습니다. 로그 파서에서 벗어나 여러 가지 이유로이 로그 원인을 분석하려고했습니다. 특히 구체적으로, 원하는대로 다른 것을 쓸 수있는 이유는 무엇입니까?).C# powershell을 실행하십시오

지금까지
$t1 =(get-date).AddMinutes(-10) 
    $t2 =$t1.ToUniversalTime().ToString("HH:mm:ss") 
    $IISLogPath = "C:\inetpub\logs\LogFiles\W3SVC1\"+"u_ex"+(get-date).AddDays(-3).ToString("yyMMdd")+".log" 
    $IISLogFileRaw = [System.IO.File]::ReadAllLines($IISLogPath) 
    $headers = $IISLogFileRaw[3].split(" ") 
    $headers = $headers | where {$_ -ne "#Fields:"} 
    $IISLogFileCSV = Import-Csv -Delimiter " " -Header $headers -Path $IISLogPath 
    $IISLogFileCSV = $IISLogFileCSV | where {$_.date -notlike "#*"} 
    $tape = $IISLogFileCSV | Format-Table time,s-ip,cs-uri-stem | Out-Host 

의 C# 응용 프로그램 : 그래서 여기 내 코드

PS 스크립트 지금

Runspace runSpace = RunspaceFactory.CreateRunspace(); 
     runSpace.Open(); 
     Pipeline pipeline = runSpace.CreatePipeline(); 
     pipeline.Commands.AddScript(@"D:\PS-Scripts\IIS\IISLogScan.ps1"); 
     Collection<PSObject> results = pipeline.Invoke(); 
     foreach (PSObject obj in results) 
     { 
      Console.WriteLine(results); 

     } 
     Console.ReadLine(); 

내 응용 프로그램을 실행 그냥 앉아 나던 디스플레이 아무것도 난 내 중단 점을 설정하고 그것은 내 foreach 내에서 내가 완벽하게 작동하고 원인을 내 PS1 스크립트를 실행 원인에 완전히 끊어 표시 할 수 없다는 것을 말하고 많은 라인을 보여줍니다. 누구나 제공 할 수있는 통찰력은 훌륭합니다.

답변

1

것은이 .ps1 파일에 변경 시도 :

$global:tape =$IISLogFileCSV | Format-Table time,s-ip,cs-uri-stem 

및 C#에서을

pipeline.Commands.AddScript(@"D:\PS-Scripts\IIS\IISLogScan.ps1"); 
pipeline.Commands.AddScript("$tape"); 
pipeline.Commands.AddScript("out-string"); 

또는이 .ps1에서

:
$tape =$IISLogFileCSV | Format-Table time,s-ip,cs-uri-stem 
$tape 

및 C#에서

pipeline.Commands.AddScript(@"D:\PS-Scripts\IIS\IISLogScan.ps1"); 
pipeline.Commands.AddScript("out-string"); 
+0

Unfortuantly 이러한 시도가 작동하지 않았다 – jladd

+0

@jladd 정확히 무엇이 실패합니까? –

관련 문제