![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 |
| | #2 (permalink) |
| 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 > |
| | #3 (permalink) |
| 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 >> |
| | #4 (permalink) |
| 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 > >> > > > |
| |
| |
![]() |
| 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 |