4

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.

Andrew M
  • 43
  • 4

1 Answers1

2

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 ...

sodawillow
  • 12,497
  • 4
  • 34
  • 44
  • 1
    [Sorry for slow reply, it took me a while to understand that this instance of my question is on a different site to where I posted it, giving me problems responding]
    PetSerAl's comment was enough for me to fix my script, however I can't mark it as an answer. I have therefore marked sodawillow's as the answer, which is probably more fitting as it shows where to make the initial change (which is earlier than I thought, i.e. it needs to be before the command is issued with Invoke-Expression) and how to set it back (which I had worked out, but is worth making clear).
    Thank you both.
    – Andrew M Nov 16 '15 at 10:39