从 PowerShell 调用的 SubInACL 输出的双倍间距 [英] Double spacing of output from SubInACL called from PowerShell

查看:44
本文介绍了从 PowerShell 调用的 SubInACL 输出的双倍间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我使用此处的字符串构建命令:
[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 w n e r >

我以前没见过这个.就好像输出是在某个 16 位字符集中,PowerShell ISE 期望\将其解释为 8 位.
这不会给我带来问题.然而,任何见解都将不胜感激,因为它会很好理解,甚至更好地纠正.

解决方案

我试图找到一些信息来解释,但到目前为止找不到.

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

将输出编码更改为 Unicode

#设置输出编码为unicode[控制台]::OutputEncoding = [Text.Encoding]::Unicode$func_filePath = "G:\test\func.txt"#使用subinacl[字符串]$SubInACLCommand = @"subinacl.exe/file "$func_filePath"/setowner="hostname\Administrators""@调用表达式 $SubInACLCommand#将输出编码恢复为默认值[控制台]::OutputEncoding = [Text.Encoding]::Default

PS:我知道 OP 已经删除了他的帐户......

I am using a PowerShell script to delete data.
Where I do not have access I am using SubInACL.exe to take\set ownership
Note: I then call it again to grant access
Note II: I am aware of TakeOwn.exe and use it elsewhere in the script

I build the command using a here-string:
[string]$SubInACLCommand = @"
subinacl.exe /file "$func_filePath" /setowner="Hostname\Administrators"
"@

Then call it using Invoke-Expression:
Invoke-Expression $SubInACLCommand

The output is returned double-spaced:
\ \ 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...

I have not seen this before. It is as if the output is in some 16-bit character set, where PowerShell ISE is expecting\interpreting it as 8-bit.
This is not causing me a problem as such. However any insight would be appreciated as it would be nice to understand and even better to correct.

解决方案

I tried to find some information to explain but could not, so far.

As advised by @PetSerAl you can change the output encoding to Unicode with [Console]::OutputEncoding=[Text.Encoding]::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 : I know OP has deleted his account ...

这篇关于从 PowerShell 调用的 SubInACL 输出的双倍间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆