I have the following code in Powershell
$filePath = "C:\my\programming\Powershell\output.test.txt" try { $wStream = new-object IO.FileStream $filePath, [System.IO.FileMode]::Append, [IO.FileAccess]::Write, [IO.FileShare]::Read $sWriter = New-Object System.IO.StreamWriter $wStream $sWriter.writeLine("test") }
I keep getting the error:
It is not possible to convert the argument "1" with the value: "[IO.FileMode] :: Append", for "FileStream" to enter "System.IO.FileMode": "It is not possible to convert the value" [IO.FileMode] :: Add "to print "System.IO.FileMode" because the enumeration is invalid. Specify one of the following enumeration values ββand try again. Possible enumeration values ββare "CreateNew, Create, Open, OpenOrCreate, Truncate, Add."
I tried the equivalent in C #,
FileStream fStream = null; StreamWriter stWriter = null; try { fStream = new FileStream(@"C:\my\programming\Powershell\output.txt", FileMode.Append, FileAccess.Write, FileShare.Read); stWriter = new StreamWriter(fStream); stWriter.WriteLine("hahha"); }
it works great!
What happened to my powershell script? BTW I work on powershell
Major Minor Build Revision ----- ----- ----- -------- 3 2 0 2237
source share