【问题标题】:PowerShell Convertto-HTML add data to columnPowerShell Convertto-HTML 将数据添加到列
【发布时间】:2013-04-18 06:04:44
【问题描述】:

我有这个脚本

$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

有什么办法吗?

【问题讨论】:

    标签: html powershell scripting powershell-2.0


    【解决方案1】:

    如果您可以创建一个 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"
    

    【讨论】:

    • 我会试试看 :) 没想到!
    猜你喜欢
    • 1970-01-01
    • 2015-05-25
    • 2018-11-14
    • 2017-02-18
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多