Jump to content

coldf1r3

Members
  • Gesamte Inhalte

    3
  • Registriert seit

  • Letzter Besuch

Beiträge erstellt von coldf1r3

  1. vor 18 Stunden schrieb daabm:

     Warum hoslt Du dreimal den Inhalt von $file? Einmal würde reichen.

    Und warum holst Du den Inhalt der Zieldatei, wenn Anhängen reichen würde? :-)

     

    Bin noch recht unerfahren mit Powershell und es sollte auch relativ schnell gehen, daher habe ich einfach Copy Paste gemacht gehabt.

    Vom Aufbau gefällt es mir auch noch nicht. Kam nur noch nicht zum Optimieren ^^

  2. Hallo Zusammen,

    ich bastel gerade ein Skript was in einer Textdatei aus 3 Zeilen Werte auslesen soll und diese dann in eine Zeile Kommasepariert einfügt.

    Leider bekomme ich immer einen Zugriff verweigert Error, seitdem ich von einer festen Zeile auf nach Nummern suchen geändert habe. Jedoch ist die Abfrage ja vorher.

    Bin noch Anfänger was Powershell angeht. Daher bin ich auch für andere Verbessungsvorschläge gerne offen.

     

    $user = $env:USERPROFILE
    $path = $MyInvocation.MyCommand.Path
    $path = $path.Substring(0, $path.LastIndexOf('\gdtfix'))
    Set-Location -Path $path
    $dest = "..\work\"
    $file= $path+"worklist*.txt"
    Set-Location -Path ..
    $timeout = 10
    Write-Host $path
    $FileSystemWatcher = New-Object System.IO.FileSystemWatcher $path
    Write-Host Press CTRL+C to abort monitoring $path
    while ($true) {
     $result = $FileSystemWatcher.WaitForChanged(‘all’, $timeout)
     if ($result.TimedOut -eq $false)
     {
     Write-Host "test"
    $txt = $file
    (gc $path -Force | % { if($_ -match "0010,2295") {$var1 = $_}})
    $var1 = $var1.Substring(10)
    (gc $path | % { if($_ -match "0010,4000") {$var2 = $_}})
    $var2 = $var2.Substring(10)
    (gc $path | % { if($_ -match "0010,2201") {$var3 = $_}})
    $var3 = $var3.Substring(10)
    (Get-Content -Path $txt)|%{$_ -replace "0010,4000,.+","0010,4000, $var1, $var2, $var3"}| Set-Content -Path $txt
    
    Move-Item -Path $txt -Destination $dest
    }}

     

    Fehlermeldung:

    gc : Der Zugriff auf den Pfad "PFAD" wurde verweigert.
    In PFAD\GDTfix.ps1:18 Zeichen:2
    + (gc $path -Force | % { if($_ -match "0010,2295") {$var1 = $_}})
    +  ~~~~~~~~~~~~~~~
        + CategoryInfo          : PermissionDenied: (PFAD\GDTfix:String) [Get-Content], UnauthorizedAccessException
        + FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand
     
    Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
    In PFAD\GDTfix.ps1:19 Zeichen:1
    + $var1 = $var1.Substring(10)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
     
    gc : Der Zugriff auf den Pfad "PFAD" wurde verweigert.
    In PFAD\GDTfix.ps1:20 Zeichen:2
    + (gc $path | % { if($_ -match "0010,4000") {$var2 = $_}})
    +  ~~~~~~~~
        + CategoryInfo          : PermissionDenied: (PFAD:String) [Get-Content], UnauthorizedAccessException
        + FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand
     
    Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
    In PFAD\GDTfix.ps1:21 Zeichen:1
    + $var2 = $var2.Substring(10)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
     
    gc : Der Zugriff auf den Pfad "PFAD\GDTfix" wurde verweigert.
    In PFAD\GDTfix.ps1:22 Zeichen:2
    + (gc $path | % { if($_ -match "0010,2201") {$var3 = $_}})
    +  ~~~~~~~~
        + CategoryInfo          : PermissionDenied: (PFAD\GDTfix:String) [Get-Content], UnauthorizedAccessException
        + FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand
     
    Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
    In PFAD\GDTfix.ps1:23 Zeichen:1
    + $var3 = $var3.Substring(10)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

     

     

     

     

    Vielen Dank schonmal für die Hilfe

    Mit -Force hatte ich es auch bereits versucht. Dies hatte leider nicht geklappt.

×
×
  • Neu erstellen...