How does PowerShell handle large data sets?
Say that Get-ChildItem returns millions of items. How does PowerShell hand开发者_如何学Cle this? Can I process the data in batches? Will the command block the console until the data is retrieved?
I'm new to PowerShell so it would be great if someone could explain the basic principles of handling operations that return many items / can take long time to finish.
Powershell cmdlets process data one record at a time. If you pipe the output of get-childitem to a script block or another cmdlet it should execute both in parallel. That is to say, your script block will execute as soon as a record is available, while get-childitem is still retrieving records. Of course, as it is a console app, the console will naturally be blocked until all records are processed, unless you prompt the user for more data during the processing of a record, or the user terminates the command. If you have time/resource intensive processing to do you may want to consider having your cmdlet use a background job (see this msdn article).
精彩评论