将输出文件的名称更改为servername

时间:2014-06-22 11:40:16

标签: powershell

我想使用运行它的服务器名称动态输出文件,而不是指定要使用的名称。因为我想使用多实例方法在多个服务器上运行代码。

$OutFile = "C:\Users\munjanga\Documents\AoN Project\Execute\Output.csv"
$Header = "FolderPath,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Del $OutFile
Add-Content -Value $Header -Path $OutFile 

$RootPath = "C:\Users\munjanga\Documents\Operations Orchestration"

$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}

foreach ($Folder in $Folders){
    $ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access  }
    Foreach ($ACL in $ACLs){
        $OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference  + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
        Add-Content -Value $OutInfo -Path $OutFile
    }
}

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您需要根据服务器名称更改$ OutFile。您可以使用Environment class的MachineName属性:

$OutFile = "C:\Users\munjanga\Documents\AoN Project\Execute\$([Environment]::MachineName).csv"