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

Stumped by variable substitution

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-14-2007   #1 (permalink)
K Kong
Guest


 

Stumped by variable substitution

What did I do wrong here? Why does the "\microsoft[1].txt" gets ignored?

PS C:\>
$CookieFile=$env:UserProfile.ToString()+"\"+$Env:username.ToString()+"\microsoft[1].txt"
PS C:\> $CookieFile
C:\Documents and Settings\kingkong\kingkong\microsoft[1].txt
PS C:\> get-content $CookieFile
Get-Content : Cannot find path 'C:\Documents and Settings\kingkong\kingkong'
because it does not exist.
At line:1 char:12
+ get-content <<<< $CookieFile
PS C:\>

Thanks in advance.

My System SpecsSystem Spec
Old 05-14-2007   #2 (permalink)
Shafik
Guest


 

Re: Stumped by variable substitution

On May 14, 9:21 am, K Kong <K...@discussions.microsoft.com> wrote:
> What did I do wrong here? Why does the "\microsoft[1].txt" gets ignored?
>
> PS C:\>
> $CookieFile=$env:UserProfile.ToString()+"\"+$Env:username.ToString()+"\microsoft[1].txt"
> PS C:\> $CookieFile
> C:\Documents and Settings\kingkong\kingkong\microsoft[1].txt
> PS C:\> get-content $CookieFile
> Get-Content : Cannot find path 'C:\Documents and Settings\kingkong\kingkong'
> because it does not exist.
> At line:1 char:12
> + get-content <<<< $CookieFile
> PS C:\>
>
> Thanks in advance.


try that:
$env:UserProfile.ToString()+"\"+$Env:username.ToString()+"\" +
$microsoft[1].txt

My System SpecsSystem Spec
Old 05-14-2007   #3 (permalink)
K Kong
Guest


 

Re: Stumped by variable substitution

Why? "\microsoft[1].txt" is a string literal.

Anyway, what you suggested produced an error as $microsoft is a null array.

"Shafik" wrote:

> try that:
> $env:UserProfile.ToString()+"\"+$Env:username.ToString()+"\" +
> $microsoft[1].txt


My System SpecsSystem Spec
Old 05-14-2007   #4 (permalink)
Newbie


Join Date: May 2007
 
Rep Power: 11
jsnover is on a distinguished road
  jsnover is offline

> PS C:\> get-content $CookieFile
The []s are getting you in trouble as they look like a wildcard. Try:
PS C:\> get-content -LiteralPath $CookieFile

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at: Windows PowerShell
Visit the Windows PowerShell ScriptCenter at: Scripting with Windows PowerShell
My System SpecsSystem Spec
Old 05-14-2007   #5 (permalink)
Marco Shaw
Guest


 

Re: Stumped by variable substitution

K Kong wrote:
> What did I do wrong here? Why does the "\microsoft[1].txt" gets ignored?
>
> PS C:\>
> $CookieFile=$env:UserProfile.ToString()+"\"+$Env:username.ToString()+"\microsoft[1].txt"
> PS C:\> $CookieFile
> C:\Documents and Settings\kingkong\kingkong\microsoft[1].txt
> PS C:\> get-content $CookieFile
> Get-Content : Cannot find path 'C:\Documents and Settings\kingkong\kingkong'
> because it does not exist.
> At line:1 char:12
> + get-content <<<< $CookieFile
> PS C:\>
>
> Thanks in advance.


Seems Keith Hill mentions an issue with "[" and "]" in this thread
"Scripting / Logging Gripe Summary" from May 12th. (I did not read it
in detail though.)

Marco
My System SpecsSystem Spec
Old 05-14-2007   #6 (permalink)
K Kong
Guest


 

Re: Stumped by variable substitution

You are right! Thanks.

"Marco Shaw" wrote:
>
> Seems Keith Hill mentions an issue with "[" and "]" in this thread
> "Scripting / Logging Gripe Summary" from May 12th. (I did not read it
> in detail though.)
>
> Marco
>

My System SpecsSystem Spec
Old 05-14-2007   #7 (permalink)
Keith Hill
Guest


 

Re: Stumped by variable substitution

"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:%23XXCohilHHA.3704@TK2MSFTNGP02.phx.gbl...
>K Kong wrote:
>> What did I do wrong here? Why does the "\microsoft[1].txt" gets ignored?
>>
>> PS C:\>
>> $CookieFile=$env:UserProfile.ToString()+"\"+$Env:username.ToString()+"\microsoft[1].txt"
>> PS C:\> $CookieFile
>> C:\Documents and Settings\kingkong\kingkong\microsoft[1].txt
>> PS C:\> get-content $CookieFile
>> Get-Content : Cannot find path 'C:\Documents and
>> Settings\kingkong\kingkong' because it does not exist.
>> At line:1 char:12
>> + get-content <<<< $CookieFile
>> PS C:\>
>>
>> Thanks in advance.

>
> Seems Keith Hill mentions an issue with "[" and "]" in this thread
> "Scripting / Logging Gripe Summary" from May 12th. (I did not read it in
> detail though.)


Yeah the square braces can be a PITA if you don't want their wildcarding
behavior. In this case it should be enough to specify the last part of path
like so:

.... + 'microsoft[1].txt'

BTW to get the path to your Cookies folder I would use:

PS> [Environment]::GetFolderPath([Environment+SpecialFolder]::Cookies)

--
Keith

My System SpecsSystem Spec
Old 05-14-2007   #8 (permalink)
christhorsen@gmail.com
Guest


 

Re: Stumped by variable substitution

I ran into this last night (while backup up MP3's)

If you use the -literalPath argument (rather than -Path), it doesn't
try to interpret the wildcards:

get-content -literalPath $CookieFile


See "help -detailed get-content:"

My System SpecsSystem Spec
Old 05-16-2007   #9 (permalink)
K Kong
Guest


 

Re: Stumped by variable substitution

Right. Should have thought of this earlier. BTW, do you know of the syntax
of the contents of the cookie files? I Googled but can't seem to find any
information. I suppose this is specific and proprietary to IE. I can guess
on the key/value pairs. But I can't decipher the expiry date. Is there an
API to read the cookies?

Thanks.

"Keith Hill" wrote:

> BTW to get the path to your Cookies folder I would use:
>
> PS> [Environment]::GetFolderPath([Environment+SpecialFolder]::Cookies)
>
> --
> Keith
>
>

My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command & variable substitution Chris PowerShell 5 01-09-2008 07:45 AM
Stumped Andy/Bandi Vista file management 6 06-17-2007 12:00 PM
Stumped Andy/Bandi Vista General 19 06-16-2007 08:51 PM
HELP!! Totally stumped!! ChrisW Vista General 6 04-08-2007 05:13 PM
How can I ensure that a variable is a built-in powershell variable? Sung M Kim PowerShell 7 09-22-2006 06:28 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 51