【发布时间】:2020-05-08 19:46:37
【问题描述】:
我正在设置一个查看活动目录并获取用户名称、标题和缩略图照片的 powershell 脚本。
但是,当它试图显示照片时,它会以二进制形式返回而不是对其进行解码?我试图实现以粗体显示的代码的解码部分,但它不起作用。我试图让它在标签中显示图像作为最终产品。
尝试对其进行编码的代码如下:
$item.thumbnailPhoto | Set-Content $PhotoPath -Encoding byte
它通过 if 语句检查用户是否有照片。
主代码:
PROCESS{
Write-Verbose "Getting information from users"
$usersnames= get-aduser -filter * -Properties *
$computer = $env:computername
$AllInfoProperties=@()
foreach($user in $usersnames){
$IDName=$user.SamAccountName
$AllInfoProperties+=Get-ADUser -Identity $IDName -Properties * | Select *
}
$AllUsersFilter= $AllInfoProperties| Sort-Object Department,Enabled | Select DisplayName,EmailAddress,OfficePhone,Department,Title,thumbnailPhoto
#Html5 part
$html= '<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>'
$html+=$title
$html+="</title>
<style type=""text/css"">{margin:0;padding:0}@import url(https://fonts.googleapis.com/css?family=Indie+Flower|Josefin+Sans|Orbitron:500|Yrsa);body{text-align:center;font-family:14px/1.4 'Indie Flower','Josefin Sans',Orbitron,sans-serif;font-family:'Indie Flower',cursive;font-family:'Josefin Sans',sans-serif;font-family:Orbitron,sans-serif}#page-wrap{margin:50px}tr:nth-of-type(odd){background:#eee}th{background:#EF5525;color:#fff;font-family:Orbitron,sans-serif}td,th{padding:6px;border:1px solid #ccc;text-align:center;font-size:large}table{width:90%;border-collapse:collapse;margin-left:auto;margin-right:auto;font-family:Yrsa,serif}</style>
</head>
<body>
<table>
<tr>
<th>Name</th><th>Email</th><th>Phone Number</th><th>Department</th><th>Title</th><th>Photo</th>
</tr>
"
foreach($item in $AllUsersFilter){
if ($item.thumbnailPhoto -ne ""){
$item.thumbnailPhoto | Set-Content -Encoding byte
}
$html+="<tr> <td>$($item.DisplayName)</td> <td>$($item.EmailAddress)</td> <td>$($item.OfficePhone)</td> <td>$($item.Department)</td> <td>$($item.Title)</td> <td>$($item.thumbnailPhoto)</td> </tr></tr>"
}
$html+="
</table>
<br>
</body>
</html>"
【问题讨论】:
-
我们还没有收到您的来信.. 我的回答解决了您的问题吗?如果是这样,请通过单击左侧的✓图标来考虑accepting它。这将帮助其他有类似问题的人更轻松地找到它。
-
刚接触 SO 你可能不知道这一点,但习惯于点击左侧的 ✓ 图标accept the answer that solved your problem。这将帮助其他有类似问题的人更轻松地找到它,并有助于激励人们回答您未来的问题。
标签: windows powershell active-directory windows-server