Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - stoopid newb question

Reply
 
Old 08-14-2007   #1 (permalink)
tonyr
Guest


 
 

stoopid newb question

ok so I have the following - all on one line.

ls c:\ -rec | where {$_.mode -like "d*"} | foreach
{$di.getfolder($_.fullname).size/1024/1024}

$di = fso
the above line returns the folder size correctly but I can't seem to find a
way to output both the fullname and the size, any help would be appreciated!
tr


My System SpecsSystem Spec
Old 08-14-2007   #2 (permalink)
RichS
Guest


 
 

RE: stoopid newb question

this would work

PS> ls c:\ -rec | where{$_.mode -like "d*"} | foreach{ $size =
$di.getfolder($_.fullname).size/1mb; Write-Host $_.fullname $size }
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"tonyr" wrote:

> ok so I have the following - all on one line.
>
> ls c:\ -rec | where {$_.mode -like "d*"} | foreach
> {$di.getfolder($_.fullname).size/1024/1024}
>
> $di = fso
> the above line returns the folder size correctly but I can't seem to find a
> way to output both the fullname and the size, any help would be appreciated!
> tr
>

My System SpecsSystem Spec
Old 08-14-2007   #3 (permalink)
Hal Rottenberg
Guest


 
 

Re: stoopid newb question

On Aug 14, 10:48 am, tonyr <to...@discussions.microsoft.com> wrote:
> ls c:\ -rec | where {$_.mode -like "d*"} | foreach
> {$di.getfolder($_.fullname).size/1024/1024}
>
> $di = fso


$objFSO = New-Object -com scripting.filesystemobject
$dirs = ls c:\ -rec | where { $_.PSIsContainer } # Another way to get
the directories
$dirs | % { "$($_.fullname) $($objFSO.getfolder($_).size/1024/1024)" }

I imagine there's prettier ways to do this.

My System SpecsSystem Spec
Old 08-14-2007   #4 (permalink)
RichS
Guest


 
 

RE: stoopid newb question

this gives a prettier output

ls c:\ -rec | where{$_.mode -like "d*"} | foreach{ $size =
$di.getfolder($_.fullname).size/1mb; "{0,9} {1,2} " -f $size, $_.fullname }
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"tonyr" wrote:

> ok so I have the following - all on one line.
>
> ls c:\ -rec | where {$_.mode -like "d*"} | foreach
> {$di.getfolder($_.fullname).size/1024/1024}
>
> $di = fso
> the above line returns the folder size correctly but I can't seem to find a
> way to output both the fullname and the size, any help would be appreciated!
> tr
>

My System SpecsSystem Spec
Old 08-14-2007   #5 (permalink)
tonyr
Guest


 
 

RE: stoopid newb question

dangit I tried something very similar not sure why it did not work! thanks
very much

"RichS" wrote:

> this would work
>
> PS> ls c:\ -rec | where{$_.mode -like "d*"} | foreach{ $size =
> $di.getfolder($_.fullname).size/1mb; Write-Host $_.fullname $size }
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "tonyr" wrote:
>
> > ok so I have the following - all on one line.
> >
> > ls c:\ -rec | where {$_.mode -like "d*"} | foreach
> > {$di.getfolder($_.fullname).size/1024/1024}
> >
> > $di = fso
> > the above line returns the folder size correctly but I can't seem to find a
> > way to output both the fullname and the size, any help would be appreciated!
> > tr
> >

My System SpecsSystem Spec
Old 08-14-2007   #6 (permalink)
tonyr
Guest


 
 

Re: stoopid newb question

cool in just these two replys I've learned loads of info! thanks.
tr

"Hal Rottenberg" wrote:

> On Aug 14, 10:48 am, tonyr <to...@discussions.microsoft.com> wrote:
> > ls c:\ -rec | where {$_.mode -like "d*"} | foreach
> > {$di.getfolder($_.fullname).size/1024/1024}
> >
> > $di = fso

>
> $objFSO = New-Object -com scripting.filesystemobject
> $dirs = ls c:\ -rec | where { $_.PSIsContainer } # Another way to get
> the directories
> $dirs | % { "$($_.fullname) $($objFSO.getfolder($_).size/1024/1024)" }
>
> I imagine there's prettier ways to do this.
>
>

My System SpecsSystem Spec
Old 08-14-2007   #7 (permalink)
Hal Rottenberg
Guest


 
 

Re: stoopid newb question

On Aug 14, 11:24 am, RichS <Ri...@discussions.microsoft.com> wrote:
> this gives a prettier output
>
> ls c:\ -rec | where{$_.mode -like "d*"} | foreach{ $size =
> $di.getfolder($_.fullname).size/1mb; "{0,9} {1,2} " -f $size, $_.fullname }


And here's a link about the format operator "-f".

http://www.computerperformance.co.uk..._-f_format.htm

(I'm still trying to grok this one myself.)

My System SpecsSystem Spec
Old 08-14-2007   #8 (permalink)
Keith Hill [MVP]
Guest


 
 

Re: stoopid newb question

"tonyr" <tonyr@discussions.microsoft.com> wrote in message
news:F9E889E6-E7D7-48F1-989D-7FD096B1CF5C@microsoft.com...
> dangit I tried something very similar not sure why it did not work! thanks
> very much
>
> "RichS" wrote:
>
>> this would work
>>
>> PS> ls c:\ -rec | where{$_.mode -like "d*"} | foreach{ $size =
>> $di.getfolder($_.fullname).size/1mb; Write-Host $_.fullname $size }


BTW I would recommend using the PSIsContainer property to filter out
directories e.g.:

gci c:\ -r | ?{$_.PSIsContainer} | %{"{0} {1} MB" -f $_.fullname,
($di.getFolder($_.fullname).size/1MB)}

--
Keith

My System SpecsSystem Spec
Old 08-14-2007   #9 (permalink)
RichS
Guest


 
 

Re: stoopid newb question

There is an awful lot in the format operator. It is well worth getting to
know. Also check out the articles on msdn about using it
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Hal Rottenberg" wrote:

> On Aug 14, 11:24 am, RichS <Ri...@discussions.microsoft.com> wrote:
> > this gives a prettier output
> >
> > ls c:\ -rec | where{$_.mode -like "d*"} | foreach{ $size =
> > $di.getfolder($_.fullname).size/1mb; "{0,9} {1,2} " -f $size, $_.fullname }

>
> And here's a link about the format operator "-f".
>
> http://www.computerperformance.co.uk..._-f_format.htm
>
> (I'm still trying to grok this one myself.)
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Probably a complete newb question Network & Sharing
Help! IR NEWB Gaming
complete newb Network & Sharing
NewB to Vista Mail has question Vista mail
newb question - iteratate a hashtable PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46