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 - Stumped by variable substitution

Reply
 
Old 05-14-2007   #1 (permalink)
K Kong


 
 

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


 
 

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


 
 

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)


 
 

> 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


 
 

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


 
 

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


 
 

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


 
 

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


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Command substitution PowerShell
How to perform variable substitution in powershell? PowerShell
Command & variable substitution PowerShell
Stumped Vista General
How can I ensure that a variable is a built-in powershell variable? 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