2017-10-06 12 views
0

特定のtxt構造をCSVに変換するための小さなスクリプトを作成しました。入力は常に次のようにダッシュ線(引用符なし)で区切られ、何度も何度も繰り返されます。テキストからCSVへの変換用Powershellが機能しない

"------------------- -------------------------------------------------- ---------」

winlogon.exeのpidを:880

コマンドライン:winlogon.exeの

ベースサイズパス

0x000000008a7c0000 0xb1000 C:\ WINDOWS \ SYSTEM32 \ winlogon.exe

確認済み:Microsoft Windowsの

発行元:マイクロソフト株式会社

説明:Windowsログオンアプリケーション

製品:Microsoft®Windows®オペレーティングシステム

バージョン:10.0.15063.608

ファイルバージョン:6.2.15063.608

Crea TE時間:月9月17日1時47分05秒1979

0x000000005c830000 0x1db000 C:\ WINDOWS \ SYSTEM32 \ ntdll.dllの

検証:Microsoft Windowsの

発行元:マイクロソフト株式会社

説明: NTレイヤDLL

製品:Microsoft®Windows®オペレーティングシステム

バージョン:10.0.15063.608

ファイルのバージョン:6.2.15063.608

時間を作成します:水曜日5月11日午前1時39分23秒203

「-------------------を-------------------------------------------------- ---------」

LSASS.EXEのPID:960

コマンドライン:C:\ WINDOWS \ SYSTEM32 \ lsass.exeを

ベースサイズパス

0x00000000d2c30000 0x11000 C:\ WINDOWS \ system32 \ lsass。exeファイル

確認済み:Microsoft Windowsの出版社

発行元:マイクロソフト株式会社

説明:ローカルセキュリティ機関プロセス

製品:Microsoft®Windows®オペレーティングシステム

バージョン:10.0.15063.483

ファイルのバージョン:6.2.15063.483

時間を作成します。木1月9日午前8時26分10秒2048

0x000000005c830000 0x1db000 C:

確認済みntdll.dllの\ WINDOWS \ SYSTEM32 \:Microsoft Windowsの

発行元:マイクロソフト株式会社

説明:NTレイヤDLL

製品:Microsoft®Windows®オペレーティングシステム

バージョン:10.0.15063.608

ファイルのバージョン:6.2.15063.608

時間を作成します:水曜日5月11日午前一時39分23秒2039

私のスクリプトは次のとおりです。

[IO.File]::ReadAllText("C:\users\rummaan\Downloads\ListDlls\listdlls.txt") | 
Select-String -Pattern "(---------------------------------------...)[\s\S]*?(?=(---------------------------------------...)|($))" -AllMatches | % {$_.Matches} | % {$_.Value} | 
% { ` 
    @([PSCustomObject]@{ 
     "pid" = Select-String -InputObject $_ -Pattern "(?<=pid:).*?(?=\r)" | 
% {$_.Matches} | 
% {$_.Value}; 
    "Command_line" = Select-String -InputObject $_ -Pattern "(?<=Command line:).*?(?=\r)" | 
% {$_.Matches} | 
% {$_.Value}; 
    "BaseSizePath" = Select-String -InputObject $_ -Pattern "(?<=Base    Size  Path).*?(?=\r)" | 
% {$_.Matches} | 
% {$_.Value}; 
     "Verified" = Select-String -InputObject $_ -Pattern "(?<= Verified: ).*?(?=\r)" | % {$_.Matches} | 
% {$_.Value}; 
    "Publisher" = Select-String -InputObject $_ -Pattern "(?<= Publisher: ).*?(?=\r)" | % {$_.Matches} | 
% {$_.Value}; 
    "Description" = Select-String -InputObject $_ -Pattern "(?<= Description: ).*?(?=\r)" | % {$_.Matches} | 
% {$_.Value}; 
    "Product" = Select-String -InputObject $_ -Pattern "(?<= Product: ).*?(?=\r)" | % {$_.Matches} | 
% {$_.Value}; 
    "Version" = Select-String -InputObject $_ -Pattern "(?<= Version: ).*?(?=\r)" | % {$_.Matches} | 
% {$_.Value}; 
    "File_version" = Select-String -InputObject $_ -Pattern "(?<= File version: ).*?(?=\r)" | % {$_.Matches} | 
% {$_.Value}; 
    "Create_time" = Select-String -InputObject $_ -Pattern "(?<= Create time: ).*?(?=\r)" | % {$_.Matches} | 
% {$_.Value}; 
    })} | 
Select-Object -Property pid,Command_line,BaseSizePath,Verified,Publisher,Description,Product,Version,File_version,Create_time | 
Export-Csv -Path C:\Users\Rummaan\Downloads\ListDlls\listdlls.csv -NoTypeInformation 

何が来るのかアウトはサブテキストなしで入力してください: [ここに画像の説明を入力してください] [2]

pt?私は、列がすべてpid、command_line、base、size、path、verified、publisher、description、product、version、file_version、create_timeのような同じレベルにあるプレーンな列の平坦化されたCSVが必要です。

ありがとうございました!

+1

入れないでください。あなたの質問を、データの短い例で更新し、次に出力をどのように見せたいかを入力してください。 –

答えて

0

は、このスクリプトを試してみてください:写真へのリンクを

#Create template for structure of cut 
[email protected]" 
{Row*:"------------------------------------------------------------------------------" 
{Prog:lsass.exe} pid: {Pid:960} 
Command line: {CommandLine:C:\WINDOWS\system32\lsass.exe} 
Base Size Path 
{BaseEXE:0x00000000d2c30000} {SizeEXE:0x11000} {PathEXE:C:\WINDOWS\system32\lsass.exe} 
Verified: {VerifiedEXE:Microsoft Windows Publisher} 
Publisher: {PublisherEXE:Microsoft Corporation} 
Description: {DescriptionEXE:Local Security Authority Process} 
Product: {ProductEXE:Microsoft® Windows® Operating System} 
Version: {VersionEXE:10.0.15063.483} 
File version: {FileVersionEXE:6.2.15063.483} 
Create time: {CreateTimeEXE:Thu Jan 09 08:26:10 2048} 
{BaseDLL:0x000000005c830000} {SizeDll:0x1db000} {PathDll:C:\WINDOWS\SYSTEM32\ntdll.dll} 
Verified: {VerifiedDLL:Microsoft Windows} 
Publisher: {PublisherDLL:Microsoft Corporation} 
Description: {DescriptionDLL:NT Layer DLL} 
Product: {ProductDLL:Microsoft® Windows® Operating System} 
Version: {VersionDLL:10.0.15063.608} 
File version: {FileVersionDLL:6.2.15063.608} 
Create time: {CreateTimeDLL:Wed May 11 01:39:23 2039}} 
{Row*:"------------------------------------------------------------------------------" 
{Prog:lsass.exe} pid: {Pid:960} 
Command line: {CommandLine:C:\WINDOWS\system32\lsass.exe} 
Base Size Path 
{BaseEXE:0x00000000d2c30000} {SizeEXE:0x11000} {PathEXE:C:\WINDOWS\system32\lsass.exe} 
Verified: {VerifiedEXE:Microsoft Windows Publisher} 
Publisher: {PublisherEXE:Microsoft Corporation} 
Description: {DescriptionEXE:Local Security Authority Process} 
Product: {ProductEXE:Microsoft® Windows® Operating System} 
Version: {VersionEXE:10.0.15063.483} 
File version: {FileVersionEXE:6.2.15063.483} 
Create time: {CreateTimeEXE:Thu Jan 09 08:26:10 2048} 
{BaseDLL:0x000000005c830000} {SizeDll:0x1db000} {PathDll:C:\WINDOWS\SYSTEM32\ntdll.dll} 
Verified: {VerifiedDLL:Microsoft Windows} 
Publisher: {PublisherDLL:Microsoft Corporation} 
Description: {DescriptionDLL:NT Layer DLL} 
Product: {ProductDLL:Microsoft® Windows® Operating System} 
Version: {VersionDLL:10.0.15063.608} 
File version: {FileVersionDLL:6.2.15063.608} 
Create time: {CreateTimeDLL:Wed May 11 01:39:23 2039}} 
"@ 


#explode data 
$AllRow=gc "C:\temp\test.txt" | ConvertFrom-String -TemplateContent $template 

#get all properties of object 'Row' 
$AllProperties=($AllRow.Row | gm | where MemberType -eq "NoteProperty").Name 

#Build properties for select 
$props = @() 
foreach ($field in $AllProperties) { 
    $props += @{n="$field";e=([Scriptblock]::Create("`$_.Row.$field"))} 
} 

#Select all properties and export to CSV 
$AllRow | select $props | export-csv "c:\temp\resul.csv" -notype 
+0

gmで固まっているようです:gm:Get-Memberコマンドレットのオブジェクトを指定する必要があります。 C:\ Users \ Rummaan \ Downloads \ ListDlls \ listdllsScript1.ps1:50 char:31 + $ AllProperties =($ AllRow.Row | gm |ここでMemberType -eq "NoteProperty ... + ~~ + CategoryInfo :CloseError:(:) [Get-Member]、InvalidOperationException + FullyQualifiedErrorId:NoObjectInGetMember、Microsoft.PowerShell.Commands.GetMemberCommand – potap75

関連する問題