从PowerShell调用SubInACL的输出的双倍间距

时间:2015-11-10 12:33:52

标签: powershell

我使用PowerShell脚本删除数据 在我无法访问的地方,我使用SubInACL.exe来取消设置所有权 注意:然后我再次调用它来授予访问权限 注意二:我知道TakeOwn.exe并在脚本的其他地方使用它

我使用here-string构建命令:
[string]$SubInACLCommand = @"
subinacl.exe /file "$func_filePath" /setowner="Hostname\Administrators"
"@

然后使用Invoke-Expression调用它:
Invoke-Expression $SubInACLCommand

输出以双倍间距返回:
\ \ H o s t n a m e \ S h a r e n a m e \ F o l d e r n a m e : H o s t n a m e \ A d m i n i s t r a t o r s i s t h e n e w o w n e r ...

我以前没见过这个。就好像输出是一些16位字符集,PowerShell ISE期望将其解释为8位。
这不会导致我这样的问题。然而,任何见解都会受到赞赏,因为理解它们会更好,甚至更好。

1 个答案:

答案 0 :(得分:2)

我试图找到一些信息来解释,但到目前为止还没有。

根据@PetSerAl的建议,您可以使用[Console]::OutputEncoding=[Text.Encoding]::Unicode

将输出编码更改为Unicode
#set output encoding to unicode
[Console]::OutputEncoding = [Text.Encoding]::Unicode

$func_filePath = "G:\test\func.txt"

#use subinacl
[string]$SubInACLCommand = @"
subinacl.exe /file "$func_filePath" /setowner="hostname\Administrators"
"@

Invoke-Expression $SubInACLCommand

#revert output encoding back to default
[Console]::OutputEncoding = [Text.Encoding]::Default
PS:我知道OP已经删除了他的账号......