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 - Issue: getting/setting variable content using Get/Set-Content

Reply
 
Old 09-23-2006   #1 (permalink)
=?Utf-8?B?Um9tYW4gS3V6bWlu?=


 
 

Issue: getting/setting variable content using Get/Set-Content

I was playing with getting/setting variable content using Get/Set-Content and
variable provider and found this:

$x = 'Hi'
gc variable:\x
Hi

sc variable:\x -Value 'Hello'
gc variable:\x
Hello

sc variable:\x -Value (gc variable:\x)
gc variable:\x
Get-Content : The member "PSPath" is already present.
At line:1 char:3
+ gc <<<< variable:\x

What happens?

--
Thanks,
Roman

My System SpecsSystem Spec
Old 09-23-2006   #2 (permalink)
Bruce Payette [MSFT]


 
 

Re: Issue: getting/setting variable content using Get/Set-Content

This is a bug. Here's what's happening. When an object is returned from
get-content, we attach a note property called PSPath that records where the
object came from. This allows you to see where you got the object from:

PS (1) > get-date > foo.txt
PS (2) > (get-content foo.txt)[0].PsPath
C:\Temp\foo.txt
PS (3) > (get-content foo.txt)[1]
Saturday, September 23, 2006 2:01:55 AM

However - if the object already has such a property, then an error occurs
since, by default, we don't overwrite existing properties:

PS (25) > $a = 1 | add-member -mem noteproperty PSPath foo -pass
PS (26) > $a
1
PS (27) > get-content variable:\a
Get-Content : The member "PSPath" is already present.
At line:1 char:12
+ get-content <<<< variable:\a

We need to modify get-content to force an overwrite of the PSPath property
if it already exists...

-bruce

--
Bruce Payette [MSFT]
Windows PowerShell Technical Lead
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit the Windows PowerShell Team blog at:
http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:
http://www.microsoft.com/technet/scr.../hubs/msh.mspx


"Roman Kuzmin" <RomanKuzmin@discussions.microsoft.com> wrote in message
news:4EF98086-3A76-47EB-9931-6106181A6255@microsoft.com...
>I was playing with getting/setting variable content using Get/Set-Content
>and
> variable provider and found this:
>
> $x = 'Hi'
> gc variable:\x
> Hi
>
> sc variable:\x -Value 'Hello'
> gc variable:\x
> Hello
>
> sc variable:\x -Value (gc variable:\x)
> gc variable:\x
> Get-Content : The member "PSPath" is already present.
> At line:1 char:3
> + gc <<<< variable:\x
>
> What happens?
>
> --
> Thanks,
> Roman



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
get-content as variable for add PrinterPorts PowerShell
Set-Content not updating file after get-content and forEach-Object PowerShell
Issue with get-content PowerShell
EMC and Microsoft Form New Enterprise Content Management Alliance, Extend Microsoft Office SharePoint Server With Content, Compliance and Archive Solutions Vista News
Weirdness with get-content | replace | set-content - file content is deleted!! 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