Export to CSV with no Info

Hi all,

Some one can explain to me why the CSV is exported but with no data?

CODE 1 (Working)

CODE 2 (Not Working)

I made two codes to do the same, but the number 1 search for “PST´s” on the registry, number 2 on the Outlook Client.

######## CODE 1 ######### $user = $env:USERNAME # THIS GET MAPPED PST´s $GetPST = Get-item HKCU:softwareMicrosoftOffice16.0OutlookSearchCatalog | select -expandProperty property | where {$_ -match '.pst$'} #THIS Remove the "\?UNC" fromthe registry key $WritePST = $GetPST.Replace("\?UNC","\") $WritePST #THIS GET THE PATH OF THE PST, AND GET THE SIZE OF EACH $teste = Foreach ($file in $WritePST) {('{0:F3} GB' -f ((Get-Item $file).length/1GB))} #YOUR CODE $i = 0 $data = @(foreach ($pst in $writePST) { [PSCustomObject]@{ name = $user path = $WritePST[$i] } $i++ }) $data | Export-Csv "C:Usersruben.reisDownloadspsts testeoutput.csv" -NoTypeInformation -append ######## CODE 2 ######### $user = $env:USERNAME $date = Get-Date $Serverdata = "C:UsersUSERDownloadspsts testeoutput.csv" $AgentFolder = "$env:APPDATAPSTAgent" $AgentLog = "$AgentFolderPstagentlog.txt" $FolderTest = Test-Path $AgentFolder If ($FolderTest -eq $True) {} Else {New-Item -ItemType Directory -Name "PSTAgent" -Path $env:APPDATA} # THIS GET MAPPED PST´s FROM OUTLOOK $PSTFiles=$null $ol=New-Object -ComObject Outlook.Application $ns=$ol.GetNamespace('MAPI') $store=$ns.Session.Stores|Where-Object{$_.FilePath -match "pst$"} $store | Foreach-Object{ $pst=$_.FilePath If($PSTFiles -ne $null){ $PSTFiles+="|$pst" } If($PSTFiles -eq $null){ $PSTFiles=$pst } } $PSTFiles=$PSTFiles.split("|") return $PSTFiles #EXPORT TO CSV $i = 0 $data = @(foreach ($pst in $PSTFiles) { [PSCustomObject]@{ name = $User path = $PSTFiles[$i] } $i++ }) $data | Export-Csv $Serverdata -NoTypeInformation -append 

submitted by /u/rubenfrreis
[link] [comments]

Leave a Reply