MicroScripter
MicroScripter

Reputation: 148

Bring Set-Acl output to file

I have a PowerShell Problem: My Script gives modify permissions to "user2" to a Folder with Get-Acl and Set Acl. When I run Set-Acl, I want the standard output to be piped into the logfile. But when I look, the logfile is just empty.

My Code:

$permisions = Get-Acl D:\home\user1\Folder
$accessrule = New-Object System.Security.AccessControl.FileSystemAccessRule ("domain\user2","Modify","Allow")
$permissions.SetAccessrule($accessrule)
Set-Acl -AclObject $permissions -Path "D:\home\user1\Folder" -Verbose | out-file -FilePath $logfile -Append

I also tried with

Set-Acl -AclObject $permissions -Path "D:\home\user1\Folder" -Verbose >>$logfile

But both isn't working.

Upvotes: 1

Views: 1556

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

Add the -Passthru parameter to the Set-Acl cmdlet.

By default, Set-Acl does not generate any output. However, if you use the Passthru parameter, it generates a security object. The type of the security object depends on the type of the item.

Upvotes: 1

Related Questions