• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Newbie : powershell file creation ...

S

sko002

#1
hi,
I just installed powershell on my pc (which has the required configuration)
but i can not even make simple task like file creation such as :

PS W:\> "hello !" | Out-File c:\test.txt

It returns this error below :

Out-File : Unknown error "-1".
At line:1 char:21
+ "hello !" | Out-File <<<< c:\test.txt

I have searched for such topic on the web but nothing...
Someone can help please ? Thanks.
 

My Computer

K

Klaus H. Probst

#2
sko002 wrote:

> hi,
> I just installed powershell on my pc (which has the required configuration)
> but i can not even make simple task like file creation such as :
>
> PS W:\> "hello !" | Out-File c:\test.txt
Well really, this is no different than plain cmd.exe:

WPS> "Hello" > c:\test.txt

Simple, no? =)

Also:

WPS> get-help set-content

--
Klaus H. Probst
http://www.simulplex.net/
 

My Computer

J
#3
On Oct 10, 1:07 pm, sko002 <sko...@xxxxxx> wrote:

> hi,
> I just installed powershell on my pc (which has the required configuration)
> but i can not even make simple task like file creation such as :
>
> PS W:\> "hello !" | Out-File c:\test.txt
>
> It returns this error below :
>
> Out-File : Unknown error "-1".
> At line:1 char:21
> + "hello !" | Out-File <<<< c:\test.txt
>
> I have searched for such topic on the web but nothing...
> Someone can help please ? Thanks.
There isn't anything wrong with what you are trying to do. Is it
possible you don't have the proper permissions to write to C:\? Try
creating the file with redirection, and see if you get the same
result:

"hello !" > c:\test.txt

Jeff
 

My Computer

S

sko002

#4
Hi Klaus,
Sorry I may be unclear in my problem description.
I wanted to use powershell for some tasks that cmd.exe can not do or do it
easier at least !

My problem is that powershell returns an error when I execute simple command
like : "hello !" | Out-File c:\test.txt ...

do you see what i mean ?!



"Klaus H. Probst" wrote:

> sko002 wrote:

> > hi,
> > I just installed powershell on my pc (which has the required configuration)
> > but i can not even make simple task like file creation such as :
> >
> > PS W:\> "hello !" | Out-File c:\test.txt
>
> Well really, this is no different than plain cmd.exe:
>
> WPS> "Hello" > c:\test.txt
>
> Simple, no? =)
>
> Also:
>
> WPS> get-help set-content
>
> --
> Klaus H. Probst
> http://www.simulplex.net/
>
 

My Computer

K

Kiron

#5
Could you check the version installed, both outputs should be 1.0.0.0:

(Get-Command Out-File).dll -replace '^.+((\d+\.){3}\d+).+$', '$1'
"$((Get-Host).version)"

--
Kiron
 

My Computer

S

sko002

#6
Hi Jeff,

I have admin permissions on my PC ...

Same error with redirection :
PS C:\> "hello !" > c:\test.txt
Unknown error "-1".
At line:1 char:12
+ "hello !" > <<<< c:\test.txt


"Jeff" wrote:

> On Oct 10, 1:07 pm, sko002 <sko...@xxxxxx> wrote:

> > hi,
> > I just installed powershell on my pc (which has the required configuration)
> > but i can not even make simple task like file creation such as :
> >
> > PS W:\> "hello !" | Out-File c:\test.txt
> >
> > It returns this error below :
> >
> > Out-File : Unknown error "-1".
> > At line:1 char:21
> > + "hello !" | Out-File <<<< c:\test.txt
> >
> > I have searched for such topic on the web but nothing...
> > Someone can help please ? Thanks.
>
> There isn't anything wrong with what you are trying to do. Is it
> possible you don't have the proper permissions to write to C:\? Try
> creating the file with redirection, and see if you get the same
> result:
>
> "hello !" > c:\test.txt
>
> Jeff
>
>
 

My Computer

S

sko002

#7
Hi Kiron,
Yes same version ! :)

PS W:\> (Get-Command Out-File).dll -replace '^.+((\d+\.){3}\d+).+$', '$1'
1.0.0.0
PS W:\> "$((Get-Host).version)"
1.0.0.0



"Kiron" wrote:

> Could you check the version installed, both outputs should be 1.0.0.0:
>
> (Get-Command Out-File).dll -replace '^.+((\d+\.){3}\d+).+$', '$1'
> "$((Get-Host).version)"
>
> --
> Kiron
>
 

My Computer

S

sko002

#9
damn ! Still the same !!! : (

PS W:\> powershell -noProfile {"hello !" | Out-File c:\test.txt}
Out-File : Unknown error "-1".
At line:1 char:21
+ "hello !" | Out-File <<<< c:\test.txt



"Kiron" wrote:

> Try this:
>
> powershell -noProfile {"hello !" | Out-File c:\test.txt}
>
> --
> Kiron
>
 

My Computer

K

Kiron

#10
It is very odd sko002. I've never heard of 'unknown error "-1"'. You have the right version and you tried executing from a PowerShell session without user Profile... but the error persists. I can't think of any other suggestion than to either wait, there are very knowledgeable members on this group that can help; or unisntall PowerShell, download the version for your platform again and reinstall it.

Sorry I couldn't help more.

--
Kiron
 

My Computer

S

sko002

#11
No problem Kiron ! Thanks anyway for your help !
I will try re-installing powershell as you adviced. :)



"Kiron" wrote:

> It is very odd sko002. I've never heard of 'unknown error "-1"'. You have
> the right version and you tried executing from a PowerShell session
> without user Profile... but the error persists. I can't think of any other
> suggestion than to either wait, there are very knowledgeable members on
> this group that can help; or unisntall PowerShell, download the version
> for your platform again and reinstall it.
>
> Sorry I couldn't help more.
>
> --
> Kiron
>
 

My Computer

B

Brandon Shell [MVP]

#12
Did a re-install fix it?

What OS? SP Level?

Can you try "Hello" | c:\temp\test.txt -force

"sko002" <sko002@xxxxxx> wrote in message
news:2DC468AA-826A-48A2-929D-D745CEDDFAE0@xxxxxx

> No problem Kiron ! Thanks anyway for your help !
> I will try re-installing powershell as you adviced. :)
>
>
>
> "Kiron" wrote:
>

>> It is very odd sko002. I've never heard of 'unknown error "-1"'. You have
>> the right version and you tried executing from a PowerShell session
>> without user Profile... but the error persists. I can't think of any
>> other
>> suggestion than to either wait, there are very knowledgeable members on
>> this group that can help; or unisntall PowerShell, download the version
>> for your platform again and reinstall it.
>>
>> Sorry I couldn't help more.
>>
>> --
>> Kiron
>>
 

My Computer

R
#13
"sko002" <sko002@xxxxxx> wrote in message
news:064BB776-F5E4-45E0-99D7-7B26B422B338@xxxxxx

> hi,
> I just installed powershell on my pc (which has the required
> configuration)
> but i can not even make simple task like file creation such as :
>
> PS W:\> "hello !" | Out-File c:\test.txt
>
> It returns this error below :
>
> Out-File : Unknown error "-1".
> At line:1 char:21
> + "hello !" | Out-File <<<< c:\test.txt
>
> I have searched for such topic on the web but nothing...
> Someone can help please ? Thanks.
>
>

If I run your test script I get:::

Out-File : Access to the path 'C:\test.txt' is denied.
At line:1 char:20
+ "Hello!" | out-file <<<< c:\test.txt
but if I change the output file to C:\dos\test.txt then no problem. Looks
like a permission thing related to Vista.

Ray
 

My Computer

S

sko002

#14
The re-install did not worked unfortunately ...

OS: XP pro version 2002
SP : SP2

Here what i got with your command :
PS C:\> "Hello" | Out-File c:\temp\test.txt -force
Out-File : Unknown error "-1".
At line:1 char:19
+ "Hello" | Out-File <<<< c:\temp\test.txt -force

Seems like I am the first to get such problem ! great ! ;)


"Brandon Shell [MVP]" wrote:

> Did a re-install fix it?
>
> What OS? SP Level?
>
> Can you try "Hello" | c:\temp\test.txt -force
>
> "sko002" <sko002@xxxxxx> wrote in message
> news:2DC468AA-826A-48A2-929D-D745CEDDFAE0@xxxxxx

> > No problem Kiron ! Thanks anyway for your help !
> > I will try re-installing powershell as you adviced. :)
> >
> >
> >
> > "Kiron" wrote:
> >

> >> It is very odd sko002. I've never heard of 'unknown error "-1"'. You have
> >> the right version and you tried executing from a PowerShell session
> >> without user Profile... but the error persists. I can't think of any
> >> other
> >> suggestion than to either wait, there are very knowledgeable members on
> >> this group that can help; or unisntall PowerShell, download the version
> >> for your platform again and reinstall it.
> >>
> >> Sorry I couldn't help more.
> >>
> >> --
> >> Kiron
> >>
>
 

My Computer

B

Brandon Shell [MVP]

#15
I think you do have a odd problem and I would file a bug or support case

what about using set-content
"Hello!" | set-content c:\temp\test.txt


Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

s> The re-install did not worked unfortunately ...
s>
s> OS: XP pro version 2002 SP : SP2
s>
s> Here what i got with your command :
s> PS C:\> "Hello" | Out-File c:\temp\test.txt -force
s> Out-File : Unknown error "-1".
s> At line:1 char:19
s> + "Hello" | Out-File <<<< c:\temp\test.txt -force
s> Seems like I am the first to get such problem ! great ! ;)
s>
s> "Brandon Shell [MVP]" wrote:
s>

>> Did a re-install fix it?
>>
>> What OS? SP Level?
>>
>> Can you try "Hello" | c:\temp\test.txt -force
>>
>> "sko002" <sko002@xxxxxx> wrote in message
>> news:2DC468AA-826A-48A2-929D-D745CEDDFAE0@xxxxxx
>>

>>> No problem Kiron ! Thanks anyway for your help !
>>> I will try re-installing powershell as you adviced. :)
>>> "Kiron" wrote:
>>>
>>>> It is very odd sko002. I've never heard of 'unknown error "-1"'.
>>>> You have
>>>> the right version and you tried executing from a PowerShell session
>>>> without user Profile... but the error persists. I can't think of
>>>> any
>>>> other
>>>> suggestion than to either wait, there are very knowledgeable
>>>> members on
>>>> this group that can help; or unisntall PowerShell, download the
>>>> version
>>>> for your platform again and reinstall it.
>>>> Sorry I couldn't help more.
>>>>
>>>> --
>>>> Kiron
 

My Computer

S

sko002

#16
hi Rats,
I am not under vista but XP pro SP2 ...
and your command with dos directory is not working on my pc !


"Rats" wrote:

>
> "sko002" <sko002@xxxxxx> wrote in message
> news:064BB776-F5E4-45E0-99D7-7B26B422B338@xxxxxx

> > hi,
> > I just installed powershell on my pc (which has the required
> > configuration)
> > but i can not even make simple task like file creation such as :
> >
> > PS W:\> "hello !" | Out-File c:\test.txt
> >
> > It returns this error below :
> >
> > Out-File : Unknown error "-1".
> > At line:1 char:21
> > + "hello !" | Out-File <<<< c:\test.txt
> >
> > I have searched for such topic on the web but nothing...
> > Someone can help please ? Thanks.
> >
> >
>
>
> If I run your test script I get:::
>
> Out-File : Access to the path 'C:\test.txt' is denied.
> At line:1 char:20
> + "Hello!" | out-file <<<< c:\test.txt
> but if I change the output file to C:\dos\test.txt then no problem. Looks
> like a permission thing related to Vista.
>
> Ray
>
>
 

My Computer

S

sko002

#17
What do you mean by file a support case ?!

here is the result for set-content :
PS C:\> "Hello!" | set-content c:\temp\test.txt
Set-Content : Unknown error "-1".
At line:1 char:23
+ "Hello!" | set-content <<<< c:\temp\test.txt



"Brandon Shell [MVP]" wrote:

> I think you do have a odd problem and I would file a bug or support case
>
> what about using set-content
> "Hello!" | set-content c:\temp\test.txt
>
>
> Brandon Shell
> ---------------
> Blog: http://www.bsonposh.com/
> PSH Scripts Project: www.codeplex.com/psobject
>
> s> The re-install did not worked unfortunately ...
> s>
> s> OS: XP pro version 2002 SP : SP2
> s>
> s> Here what i got with your command :
> s> PS C:\> "Hello" | Out-File c:\temp\test.txt -force
> s> Out-File : Unknown error "-1".
> s> At line:1 char:19
> s> + "Hello" | Out-File <<<< c:\temp\test.txt -force
> s> Seems like I am the first to get such problem ! great ! ;)
> s>
> s> "Brandon Shell [MVP]" wrote:
> s>

> >> Did a re-install fix it?
> >>
> >> What OS? SP Level?
> >>
> >> Can you try "Hello" | c:\temp\test.txt -force
> >>
> >> "sko002" <sko002@xxxxxx> wrote in message
> >> news:2DC468AA-826A-48A2-929D-D745CEDDFAE0@xxxxxx
> >>
> >>> No problem Kiron ! Thanks anyway for your help !
> >>> I will try re-installing powershell as you adviced. :)
> >>> "Kiron" wrote:
> >>>
> >>>> It is very odd sko002. I've never heard of 'unknown error "-1"'.
> >>>> You have
> >>>> the right version and you tried executing from a PowerShell session
> >>>> without user Profile... but the error persists. I can't think of
> >>>> any
> >>>> other
> >>>> suggestion than to either wait, there are very knowledgeable
> >>>> members on
> >>>> this group that can help; or unisntall PowerShell, download the
> >>>> version
> >>>> for your platform again and reinstall it.
> >>>> Sorry I couldn't help more.
> >>>>
> >>>> --
> >>>> Kiron
>
>
>
 

My Computer

K

Kiron

#18
Hi sko002, just in case, check the versions of the .Net Framework installed on your system:

ls HKLM:\SOFTWARE\Microsoft\.NETFramework\policy | ? {$_.name -match 'v'}

--
Kiron
 

My Computer

B

Brandon Shell [MVP]

#19
AFAIK you have two options here
1) Pay $295 (I think) for a support case and hope its a bug.
2) File a bug on connect

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

s> What do you mean by file a support case ?!
s>
s> here is the result for set-content :
s> PS C:\> "Hello!" | set-content c:\temp\test.txt
s> Set-Content : Unknown error "-1".
s> At line:1 char:23
s> + "Hello!" | set-content <<<< c:\temp\test.txt
s> "Brandon Shell [MVP]" wrote:
s>

>> I think you do have a odd problem and I would file a bug or support
>> case
>>
>> what about using set-content
>> "Hello!" | set-content c:\temp\test.txt
>> Brandon Shell
>> ---------------
>> Blog: http://www.bsonposh.com/
>> PSH Scripts Project: www.codeplex.com/psobject
>> s> The re-install did not worked unfortunately ...
>> s>
>> s> OS: XP pro version 2002 SP : SP2
>> s>
>> s> Here what i got with your command :
>> s> PS C:\> "Hello" | Out-File c:\temp\test.txt -force
>> s> Out-File : Unknown error "-1".
>> s> At line:1 char:19
>> s> + "Hello" | Out-File <<<< c:\temp\test.txt -force
>> s> Seems like I am the first to get such problem ! great ! ;)
>> s>
>> s> "Brandon Shell [MVP]" wrote:
>> s>

>>>> Did a re-install fix it?
>>>>
>>>> What OS? SP Level?
>>>>
>>>> Can you try "Hello" | c:\temp\test.txt -force
>>>>
>>>> "sko002" <sko002@xxxxxx> wrote in message
>>>> news:2DC468AA-826A-48A2-929D-D745CEDDFAE0@xxxxxx
>>>>
>>>>> No problem Kiron ! Thanks anyway for your help !
>>>>> I will try re-installing powershell as you adviced. :)
>>>>> "Kiron" wrote:
>>>>>> It is very odd sko002. I've never heard of 'unknown error "-1"'.
>>>>>> You have
>>>>>> the right version and you tried executing from a PowerShell
>>>>>> session
>>>>>> without user Profile... but the error persists. I can't think of
>>>>>> any
>>>>>> other
>>>>>> suggestion than to either wait, there are very knowledgeable
>>>>>> members on
>>>>>> this group that can help; or unisntall PowerShell, download the
>>>>>> version
>>>>>> for your platform again and reinstall it.
>>>>>> Sorry I couldn't help more.
>>>>>> --
>>>>>> Kiron
 

My Computer

S

sko002

#20
Yes, here it is...

PS C:\> ls HKLM:\SOFTWARE\Microsoft\.NETFramework\policy | ? {$_.name -match
'v'}

Hive:
Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy

SKC VC Name Property
--- -- ---- --------
0 1 v1.1 {4322}
0 1 v2.0 {50727}



"Kiron" wrote:

> Hi sko002, just in case, check the versions of the .Net Framework
> installed on your system:
>
> ls HKLM:\SOFTWARE\Microsoft\.NETFramework\policy | ? {$_.name -match 'v'}
>
> --
> Kiron
>
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)