![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Overwriting Arrays I think I'm missing something simple here. I have the following script to get the name, size, and owner of files in a directory. Each time at $Details += $Detail , every element in $Details gets overwritten with the current $Detail so my output.txt ends up being a table with the last record repeated. $files=Get-ChildItem C:/Scripts $Detail = Select-Object -InputObject "" Name,Size,Owner $Details = @() foreach ($file in $files) { $owner=Get-acl $file.FullName $Detail.Name = $file.FullName $Detail.Size = $file.length $Detail.Owner = $owner.owner $Details += $Detail } $Details | out-file output.txt |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Overwriting Arrays On Dec 28, 7:48 am, DavidLMeiss...@xxxxxx wrote:
Move the line where you create the $Detail object into the loop, and you will see what you expect. Below is a another way to accomplish what you are doing: Get-ChildItem | Select-Object ` @{Name="Name"; Expression={$_.Fullname}}, @{Name="Size"; Expression={$_.Length}}, @{Name="Owner"; Expression={(Get-Acl $_).Owner}} | Out-File output.txt I hope this helps. Jeff | ||||||||||||
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Overwriting existing folder without merging | kccube | Vista General | 0 | 12-13-2007 07:31 AM |
| help overwriting free space | goingnuts | Vista performance & maintenance | 0 | 11-04-2007 11:01 AM |
| Copying and Overwriting of Files | husky86 | Vista General | 2 | 10-20-2007 05:14 PM |
| Overwriting existing files | Jeanne | Vista General | 5 | 09-26-2007 06:44 PM |
| How to avoid overwriting XP | Colin Barnhorst | Vista General | 29 | 09-19-2006 09:45 AM |