![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
| | #8 (permalink) |
| | 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 Specs![]() |
| | #9 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||