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

create dir, stuff some logs in a new file in that dir

Closed Thread
 
Thread Tools Display Modes
Old 09-11-2006   #1 (permalink)
=?Utf-8?B?R2lsIE5vdmFr?=
Guest


 

create dir, stuff some logs in a new file in that dir


Why doesn't the following work, and what would?

I try putting the following in a script file and running it:
###
$a="sometext"
$subdir="logdir"
new-item -Name $subdir -Type directory
Write-Output -InputObject $a > $subdir\blah.txt
###

PS C:\> C:\createNewFileWithText.ps1


Directory: Microsoft.PowerShell.Core\FileSystem::C:\


Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 9/11/2006 4:56 PM logdir
Access to the path 'C:\logdir' is denied.
At C:\createNewFileWithText.ps1:4 char:31
+ Write-Output -InputObject $a > <<<< $subdir\blah.txt

Old 09-11-2006   #2 (permalink)
=?Utf-8?B?ZHJlZXNjaGtpbmQ=?=
Guest


 

RE: create dir, stuff some logs in a new file in that dir

"Gil Novak" wrote:

>
> Why doesn't the following work,


I guess, it has to do with the way the parser works.
Obvioulsy, your syntax is not supported.

> and what would?


My first thought was:

Write-Output -InputObject $a > "$subdir\blah.txt"

But this gave me different error message.
The problem here is, that the variable $subdir is not expanded before
writing to the file. This looks like a bug for me.
For now, you can just put everything in brackets and force the variable to
be expanded before writing to the file:

Write-Output -InputObject $a > ("$subdir\blah.txt")

--
greetings
dreeschkind

> I try putting the following in a script file and running it:
> ###
> $a="sometext"
> $subdir="logdir"
> new-item -Name $subdir -Type directory
> Write-Output -InputObject $a > $subdir\blah.txt
> ###
>
> PS C:\> C:\createNewFileWithText.ps1
>
>
> Directory: Microsoft.PowerShell.Core\FileSystem::C:\
>
>
> Mode LastWriteTime Length Name
> ---- ------------- ------ ----
> d---- 9/11/2006 4:56 PM logdir
> Access to the path 'C:\logdir' is denied.
> At C:\createNewFileWithText.ps1:4 char:31
> + Write-Output -InputObject $a > <<<< $subdir\blah.txt
>

Old 09-11-2006   #3 (permalink)
Lee Holmes [MSFT]
Guest


 

Re: create dir, stuff some logs in a new file in that dir

This works in current builds.

--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"dreeschkind" <dreeschkind@discussions.microsoft.com> wrote in message
news:5CA46B0A-2943-42BA-A089-E09BB95861AD@microsoft.com...
> "Gil Novak" wrote:
>
>>
>> Why doesn't the following work,

>
> I guess, it has to do with the way the parser works.
> Obvioulsy, your syntax is not supported.
>
>> and what would?

>
> My first thought was:
>
> Write-Output -InputObject $a > "$subdir\blah.txt"
>
> But this gave me different error message.
> The problem here is, that the variable $subdir is not expanded before
> writing to the file. This looks like a bug for me.
> For now, you can just put everything in brackets and force the variable to
> be expanded before writing to the file:
>
> Write-Output -InputObject $a > ("$subdir\blah.txt")
>
> --
> greetings
> dreeschkind
>
>> I try putting the following in a script file and running it:
>> ###
>> $a="sometext"
>> $subdir="logdir"
>> new-item -Name $subdir -Type directory
>> Write-Output -InputObject $a > $subdir\blah.txt
>> ###
>>
>> PS C:\> C:\createNewFileWithText.ps1
>>
>>
>> Directory: Microsoft.PowerShell.Core\FileSystem::C:\
>>
>>
>> Mode LastWriteTime Length Name
>> ---- ------------- ------ ----
>> d---- 9/11/2006 4:56 PM logdir
>> Access to the path 'C:\logdir' is denied.
>> At C:\createNewFileWithText.ps1:4 char:31
>> + Write-Output -InputObject $a > <<<< $subdir\blah.txt
>>



Old 09-12-2006   #4 (permalink)
=?Utf-8?B?R2lsIE5vdmFr?=
Guest


 

Re: create dir, stuff some logs in a new file in that dir

Those workarounds didn't work for me. I think the bug is in parsing the "\"
in the path I'm redirecting to. This, however, did work:

$a="sometext"
$subdir="logdir"
new-item -Name $subdir -Type directory
$outpath="$subdir\blah.txt"
Write-Output -InputObject $a > $outpath


"Lee Holmes [MSFT]" wrote:

> This works in current builds.
>
> --
> Lee Holmes [MSFT]
> Windows PowerShell Development
> Microsoft Corporation
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "dreeschkind" <dreeschkind@discussions.microsoft.com> wrote in message
> news:5CA46B0A-2943-42BA-A089-E09BB95861AD@microsoft.com...
> > "Gil Novak" wrote:
> >
> >>
> >> Why doesn't the following work,

> >
> > I guess, it has to do with the way the parser works.
> > Obvioulsy, your syntax is not supported.
> >
> >> and what would?

> >
> > My first thought was:
> >
> > Write-Output -InputObject $a > "$subdir\blah.txt"
> >
> > But this gave me different error message.
> > The problem here is, that the variable $subdir is not expanded before
> > writing to the file. This looks like a bug for me.
> > For now, you can just put everything in brackets and force the variable to
> > be expanded before writing to the file:
> >
> > Write-Output -InputObject $a > ("$subdir\blah.txt")
> >
> > --
> > greetings
> > dreeschkind
> >
> >> I try putting the following in a script file and running it:
> >> ###
> >> $a="sometext"
> >> $subdir="logdir"
> >> new-item -Name $subdir -Type directory
> >> Write-Output -InputObject $a > $subdir\blah.txt
> >> ###
> >>
> >> PS C:\> C:\createNewFileWithText.ps1
> >>
> >>
> >> Directory: Microsoft.PowerShell.Core\FileSystem::C:\
> >>
> >>
> >> Mode LastWriteTime Length Name
> >> ---- ------------- ------ ----
> >> d---- 9/11/2006 4:56 PM logdir
> >> Access to the path 'C:\logdir' is denied.
> >> At C:\createNewFileWithText.ps1:4 char:31
> >> + Write-Output -InputObject $a > <<<< $subdir\blah.txt
> >>

>
>
>

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create New folder, move file, delete file. Explorer Freeze erod49 General Discussion 10 05-20-2008 05:38 AM
Create new file Daniel Vista General 2 04-08-2008 02:19 PM
How to create file on c:\ Stoyan Malchev Vista security 2 11-16-2007 10:16 AM
subject windows Vista Event Logs access through WMI ( Applications and Services Logs) beeess Vista networking & sharing 0 04-17-2007 01:02 PM
windows Vista Event Logs access through WMI ( Applications and Services Logs) beeess Vista General 0 04-17-2007 01:00 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