问题描述
我正在使用 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[控制台]::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 输出的双倍间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!