Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Issue with get-content

Closed Thread
 
Thread Tools Display Modes
Old 05-25-2007   #1 (permalink)
mdifranco
Guest


 

Issue with get-content

When I use get-content with the binary flag like

$bytes=get-content $path -encoding byte

Some of the JPEGS I am trying to open cause PowerShell to start eating memory
I am opening a 1.5MB image and in the Task Manager it shows PowerShell going
from about 10,000k to almost 1.5GB memory usage. I have seen this with
multiple JPEGS. It can take a minute or 2 to open one of these files in
binary mode, while opening them without the binary flag, they open up in 2
seconds.

Any one have any ideas? I am writing scripts to upload 1.5 Million docs
into a SharePoint site and this everything appears to be working except for
this.

Thanks
Old 05-25-2007   #2 (permalink)
Keith Hill [MVP]
Guest


 

Re: Issue with get-content


"mdifranco" <mdifranco@discussions.microsoft.com> wrote in message
news:BB7DA2A3-DEC0-45DF-B580-447D6215E7D7@microsoft.com...
> When I use get-content with the binary flag like
>
> $bytes=get-content $path -encoding byte
>
> Some of the JPEGS I am trying to open cause PowerShell to start eating
> memory
> I am opening a 1.5MB image and in the Task Manager it shows PowerShell
> going
> from about 10,000k to almost 1.5GB memory usage. I have seen this with
> multiple JPEGS. It can take a minute or 2 to open one of these files in
> binary mode, while opening them without the binary flag, they open up in 2
> seconds.
>
> Any one have any ideas? I am writing scripts to upload 1.5 Million docs
> into a SharePoint site and this everything appears to be working except
> for
> this.


I think it is safe to say that this an area that needs some serious
optimization. For now I would just bypass get-content and use this .NET
method. It is quite fast:

$bytes = [System.IO.File]::ReadAllBytes('C:\Users\Keith\Pictures\Foo.JPG')

--
Keith

Old 05-29-2007   #3 (permalink)
mdifranco
Guest


 

Re: Issue with get-content

"Keith Hill [MVP]" wrote:

>
> "mdifranco" <mdifranco@discussions.microsoft.com> wrote in message
> news:BB7DA2A3-DEC0-45DF-B580-447D6215E7D7@microsoft.com...
> > When I use get-content with the binary flag like
> >
> > $bytes=get-content $path -encoding byte
> >
> > Some of the JPEGS I am trying to open cause PowerShell to start eating
> > memory
> > I am opening a 1.5MB image and in the Task Manager it shows PowerShell
> > going
> > from about 10,000k to almost 1.5GB memory usage. I have seen this with
> > multiple JPEGS. It can take a minute or 2 to open one of these files in
> > binary mode, while opening them without the binary flag, they open up in 2
> > seconds.
> >
> > Any one have any ideas? I am writing scripts to upload 1.5 Million docs
> > into a SharePoint site and this everything appears to be working except
> > for
> > this.

>
> I think it is safe to say that this an area that needs some serious
> optimization. For now I would just bypass get-content and use this .NET
> method. It is quite fast:
>
> $bytes = [System.IO.File]::ReadAllBytes('C:\Users\Keith\Pictures\Foo.JPG')
>
> --
> Keith
>


Thanks Keith,
I ended up using the .Net classes all ready.

$fs = new-object System.IO.FileStream($path,[System.IO.FileMode]::Open,
[System.IO.FileAccess]::Read)
$fs.open
$br = new-object System.IO.BinaryReader($fs)
$bytes=[byte[]] $br.ReadBytes($fs.Length)

Looks like you code is a little simpler.
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set-Content not updating file after get-content and forEach-Object Tolli PowerShell 1 06-14-2007 09:01 PM
EMC and Microsoft Form New Enterprise Content Management Alliance, Extend Microsoft Office SharePoint Server With Content, Compliance and Archive Solutions z3r010 Vista News 0 10-03-2006 08:04 AM
Issue: getting/setting variable content using Get/Set-Content =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 1 09-23-2006 04:09 AM
Weirdness with get-content | replace | set-content - file content is deleted!! Andrew Watt [MVP] PowerShell 4 05-23-2006 05:59 PM








Vistax64.com 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 2005-2008

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 47 48 49 50