Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Redirecting Output of Script

HTVi
TV Discussion Newsgroups

Redirecting Output of Script
David Eisner <deisner[ at ]gmail.com> 10/23/2008 1:48:54 PM
I must be missing something basic. I have a simple script that calls
an external command (subinacl):

$homeMapFile = "C:\VOL\AD\data\ad_user_homes.csv"

$prefix = "M:\"

Import-CSV -path $homeMapFile |

foreach-object {
$homeDir = $prefix + $_.HOME_DIR
& subinacl /file $homeDir /display=owner
}


The script is saved in "set_permissions.ps1" So now I want to redirect
all the output to a log file. I believe this should do what I want:

.\set_permissions.ps1 > output.txt 2>&1

But what happens is this:

1. The output is still displayed to the console.
2. The output is also placed in output.txt, but with a space between
every character, like so:

+ F i l e M : \ H O M E \ O F F I C E \ J O A N Y U A N

/ o w n e r = b u i l t i n \ a d m
i n i s t r a t o r s

Upon further examination, the spaces are actually three null bytes.
So the file really looks like ... 'F', '\0', '\0', '\0', 'i',
'\0', ...

What's going on? Is this some type of encoding issue? I'd be happy
with UTF-8 by default.

Thanks in advance.

-David


Re: Redirecting Output of Script
"Marco Shaw [MVP]" <marco.shaw[ at ]_NO_SPAM_gmail.com> 11/9/2008 6:23:49 PM

[Quoted Text]
> What's going on? Is this some type of encoding issue? I'd be happy
> with UTF-8 by default.
>
> Thanks in advance.

There's a microsoft.public.windows.powershell group that would be more
helpful with PowerShell questions.

The out-file cmdlet has an encoding parameter:

PS>help out-file -full
....
-Encoding <string>
Specifies the type of character encoding used in the file. Valid
values are "Unicode", "UTF7", "UTF8", "UTF32",
"ASCII", "BigEndianUnicode", "Default", and "OEM". "Unicode" is
the default.

"Unicode" is the default.

"Default" uses the encoding of the system's current ANSI code page.
....

Marco


--
*Microsoft MVP - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen