Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Path für getconten-path aus Array und Access denied

$
0
0

Hallo!

Ich will aus einem Verzeichnis alle Dateien rekursiv erfassen, diese in ein Array packen um diese dann über get-content + select-string und measure-object bewerten zu lassen.

Daszu habe ich folgendes Script:

$Pfade=Get-ChildItem -path C:\inetpub\logs\LogFiles\ -Recurse | Foreach-Object { $_.FullName }
$Counter=0

foreach( $File in $Pfade) {
   $Counter= Get-Content -Path "'"$File"'" | Select-String "Suchstring" | Measure-Object
   $Counter=$Counter+$Counter
   Write-Host $File

}


Leider bekommen wir bei der Ausführung die Fehlermeldung

Get-Content : A positional parameter cannot be found that accepts argument 'C:\inetpub\logs\LogFiles\Webseitexy''.
At C:\Scripts\Statistik\Zugriffe.ps1:5 char:14+    $Counter= Get-Content -Path "'"$File"'" | Select-String "Suchstring" | Me ...+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidArgument: (:) [Get-Content], ParameterBindingException+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Führen wir die Anweisung

Get-Content "C:\inetpub\logs\LogFiles\Webseitexy\W3SVC123\u_ex141211.log" | Select-String "Suchstring" | Measure-Object

aus. Bekommen wir unsere Daten die wir haben wollen. Im Array sind auch die Verzeichnisse ordnungsgemäßt enthalten. Was machen wir falsch?

VG niesel


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>