Powershell Export-CSV -Append mit Fehler

Nobody2311

Ensign
Registriert
Jan. 2008
Beiträge
224
Hallo

Mein Code:
Code:
$item.FullName,$sizeOfFolder | Export-Csv $csvPath -NoTypeInformation -Append

Die Fehlermeldung:
Code:
Export-Csv : Es wurde kein Parameter gefunden, der dem Parameternamen "Append" entspricht.
Bei C:\Users\[Benutzer]\Desktop\Collect_FolderSize_Job.ps1:32 Zeichen:99
+           $item.FullName,$sizeOfFolder | Export-Csv $csvPath -NoTypeInformation -NoClobber -Append <<<< 
    + CategoryInfo          : InvalidArgument: (:) [Export-Csv], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand

Irgendseine Idee?

Gruss
Nobody
 
Danke für den Hinweis, aber doch bitte gleich den Fehler mir mitteilen.

Gruss
Nobody
 
Es wurde kein Parameter gefunden, der dem Parameternamen "Append" entspricht.

der fehler steht doch im log ?

schlüssel dein $cvspath auf und vergleich mit der syntax

beispiel:

The third command uses a pipeline operator (|) to send the script file information in the ScriptFiles variable to the Export-CSV cmdlet. The command uses the Path parameter to specify the output file and the Append parameter to add the new script data to the end of the output file, instead of replacing the existing file contents.

Windows PowerShell

PS C:\> $scriptFiles | export-csv –append –path \\Archive01\Scripts\Scripts.csv
 
Zuletzt bearbeitet:
Export-Csv [[-Path] <String> ] [[-Delimiter] <Char> ] -InputObject <PSObject> [-Append] [-Encoding <String> ] [-Force] [-LiteralPath <String> ] [-NoClobber] [-NoTypeInformation]

Jetzt bin ich verwirrt.

-Append gibts doch??
Ergänzung ()

Egal wo das -append steht, es wird nicht akzeptiert.

Code:
$Array | Export-Csv -append -path $csvPath
 
poste mal den ganzen code von : Collect_FolderSize_Job.ps1
 
Code:
function Select-Folder($message='Select a folder', $path = 0) { 
    $object = New-Object -comObject Shell.Application  
     
    $folder = $object.BrowseForFolder(0, $message, 0, $path) 
    if ($folder -ne $null) { 
        return $folder.self.Path
    } 
} 

function totalSizeFormated{
    $GroesseGB = "{0:N2}" -f ($Groesse/1GB)
    $GroesseMB = "{0:N2}" -f ($Groesse/1MB)
    echo "$GroesseGB GB"
    echo "$GroesseMB MB"
}

function sizeOfFoldercontent($folderToMeasure) {
    return (Get-ChildItem $folderToMeasure.FullName -Recurse | Measure-Object -Property length -Sum).Sum
}#| Export-Csv $csvPath

function sizeOfFolder($directoriesToMeasure) {
    $sizeOfFolder = 0
    $Array = @()
    foreach ($item in $directoriesToMeasure){
          $sizeOfFolder =((Get-ChildItem $item.FullName -Recurse | Measure-Object -Property length -Sum).Sum/1GB)
          $sizeOfFolderInText =("{0:N2}" -f ((Get-ChildItem $item.FullName -Recurse | Measure-Object -Property length -Sum).Sum/1GB))+" GB"
          # if the item is a directory, then process it.
          #echo "$item " (sizeOfFoldercontent $item)

          if ($item.Attributes -eq "Directory"){
                echo "Groesse von $item : "($sizeOfFolderInText)
                $Array += ("$item,$sizeOfFolderInText")
          }
          
    }
    $Array | Export-Csv -path $csvPath -NoTypeInformation
    
}


function sizeOfEachFolderRecursive($directoriesToMeasure) {
    #echo $directoriesToMeasure
    $sizeOfFolder = 0
    foreach ($item in $directoriesToMeasure){
        
          # if the item is a directory, then process it.
          echo "Foreach"
          echo sizeOfFoldercontent $item

          if ($item.Attributes -eq "Directory"){
                echo "IF reached"
                $childs=Get-ChildItem $item.FullName -Recurse | where {$_.Attributes -eq "Directory"}
                $sizeOfFolder = $sizeOfFolder + (sizeOfFoldercontent($item))
          }
    }
    #$sizeOfFolder | Export-Csv -Append $csvPath 
}

echo "Start"

chcp 1252

$csvPath = "C:\temp\export.csv"
$pathAsString = Select-Folder
# $pathAsString = Select-Folder

$directory = Get-Item $pathAsString
$tableOfContent = Get-ChildItem $directory.FullName -Recurse | where {$_.Attributes -eq "Directory"}
sizeOfFolder (Get-ChildItem $directory.FullName | where {$_.Attributes -eq "Directory"})


$Groesse = (Get-ChildItem $directory.FullName -Recurse | Measure-Object -Property length -Sum).Sum

echo "Total size of $pathAsString"
totalSizeFormated

echo "End"
 
Code:
$Array | Select-Object ToString | Export-Csv -force -path $csvPath -NoTypeInformation

Schreibt mir nur die "Length" in die CSV.

Wie kann ich den Wert im Array rausschreiben?

PS:
Die Version hab ich nun aktualisiert.
 
Zurück
Oben