Avatar of techdrive
techdrive
Flag for United States of America asked on

powershell saving to file each time rather than memory

I work in a large enterprise and work with a lot of one liners that collection information and exports this out to a .csv. What I notice in powershell but have not been able to find for more solution there is a way to cycle through the command each time and save this in the file. The way I am currently using is as it cycles through it is stored in memory and when it finishes it then exports this into a file. I do not have a lot of RAM and would prefer each time that it runs a command on each user to export this directly into a file. I hope that I am clear.

embed=snippet 8294648]
Get-PublicFolder -Recurse -resultsize:unlimited | foreach {Get-PublicFolderClientPermission $_ }

Open in new window

Powershell

Avatar of undefined
Last Comment
techdrive

8/22/2022 - Mon
footech

From your example it's not clear what you're doing so it would be hard to suggest a modification.  For the command shown you would just add a pipe to Export-CSV at the end, there's no collecting in memory happening.
Get-PublicFolder -Recurse -resultsize:unlimited | foreach {Get-PublicFolderClientPermission $_ } | Export-CSV file.csv -notype

Open in new window

techdrive

ASKER
thanks footech its really that's something not possible with powershell. I wanted to intercede the OS and force the OS to save to the file on each iteration of a value rather than store in memory. Right now the following occurs


Get-PublicFolder -Recurse -resultsize:unlimited | foreach {Get-PublicFolderClientPermission $_

foldername     path
pfo1                pf01\something----------have this value saved or appended directly to file. currently in memory until completed.
pfo2                pf02\something----------have this value saved or appended directly to file. currently in memory until completed
pfo3                pf03\something----------have this value saved or appended directly to file. currently in memory until completed
pfo4                pf04\something----------have this value saved or appended directly to file. currently in memory until completed
pfo5                pf05\something----------have this value saved or appended directly to file. currently in memory until completed

Sorry I was not clear enough let me know if this helps.
footech

With the command you posted, each object will be output to screen as it's retrieved, and it won't be kept in memory.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
techdrive

ASKER
I am aware of this but when you place thisnin a file export-csv or output-file powershell stores the contents of the output in memory. I was trying to intercede and have this to write to a file each iteration.
ASKER CERTIFIED SOLUTION
footech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
techdrive

ASKER
thanks