我有这个脚本。它扫描文件夹位置并将文件夹名称映射到从 CSV 文件中提取的文件夹所有者的名称,然后从 AD 获取用户电子邮件地址并将其作为可点击mailto:
链接添加到新列中。然后,这将在 HTML 页面上的表格中全部输出。
经历了几次迭代,现在进入了最后阶段。
我现在的问题是如何将文件夹名称拉入 mailto 正文 HTML。
Import-Module ActiveDirectory
function Encode($str) {
return ( $str -replace ' ', '%20' -replace '\n', '%0A%0D' )
}
function name($filename, $folderowners, $directory, $output){
$subject = Encode("Folder Access Request")
$body = Encode("Please can I have access to the following folder $directory")
$server = hostname
$date = Get-Date -format "dd-MMM-yyyy HH:mm"
$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 + "body{ font-family:Calibri; font-size:11pt;}"
$a = $a + "</style>"
$c = " <br></br> Content"
$c = $c +"<p>More Content</p>"
$x = ""
$b = Import-Csv $folderowners
$mappings = @{}
$b | % { $mappings.Add($_.FolderName, $_.Owner) }
Get-ChildItem $directory | where {$_.PSIsContainer -eq $True} | select Name, Path, @{n="Owner";e={$mappings[$_.Name]}}, @{n="Email";e={"mailto:"+((Get-ADUser $mappings[$_.Name] -Properties mail).mail)}} | sort -property Name |
ConvertTo-Html -head $a -PostContent $c | % {
$body = Encode("Please can I have access to the following folder " + $_.Name)
$_ -replace '(mailto:)([^<]*)',
"<a href=`"`$1`$2?subject=$subject&body=$body`">`$2</a>"
} | Out-File $output
}
name "gdrive" "\\server\departmentfolders$\location\gdrive.csv" "x:" "\\server\departmentfolders$\location\gdrive.html"
这现在出来了,在电子邮件的正文中它显示了路径,但不包括文件夹名称,只是路径位置 \server\departmentfolders$ 几乎只需要文件夹名称......