0

我有这个脚本

$a = "<style>"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color:black;}"
$a = $a + "Table{background-color:#ffffff;border-collapse: collapse;}"
$a = $a + "TH{border-width:1px;padding:0px;border-style:solid;border-color:black;}"
$a = $a + "TR{border-width:1px;padding-left:5px;border-style:solid;border-color:black;}"
$a = $a + "TD{border-width:1px;padding-left:5px;border-style:solid;border-color:black;}"
$a = $a + "</style>"


dir -path  "\\server\loctation$"  |where {$_.mode -match "d"} | select-object  name, creationtime, lastwritetime, Owner| ConvertTo-Html -head $a | Out-File "\\server\location\drivelistings.html"

它输出结果很好。

但我想在表的末尾添加一列,其中包含前缀数据。

当前页面输出:

   Name   Creation Time    LateWriteTime   Owner
   Test   2013/04/12       2013/04/12
   Test2  2013/04/12       2013/04/12
   Test3  2013/04/12       2013/04/12

我想使用成员列手动输入所有者。此数据不会更改,文件夹结构也不会更改。

例如:

   Name   Creation Time    LateWriteTime   Owner
   Test   2013/04/12       2013/04/12      user1
   Test2  2013/04/12       2013/04/12      user2
   Test3  2013/04/12       2013/04/12      user3

有什么办法可以做到这一点?

4

1 回答 1

0

如果您可以创建一个 csv 将所有者映射到文件夹名称、完整路径或独特的东西,您可以试试这个:

文件夹用户映射.csv

"FolderName","Owner"
"Test","user1"
"Test2","user2"
"Test3","user3"

脚本

$a = Import-Csv folder-user-mappings.csv
#Convert to hashtable to simplify code and search faster
$mappings = @{}
$a | % { $mappings.Add($_.FolderName, $_.Owner) }

dir -path  "\\server\loctation$" | 
where {$_.mode -match "d"} |
select-object name, creationtime, lastwritetime, @{n="Owner";e={$mappings[$_.Name]}} | 
ConvertTo-Html -head $a | 
Out-File "\\server\location\drivelistings.html"
于 2013-04-24T15:55:43.633 回答