如何解决通过Powershell从SharePoint下载文件
我正在尝试通过PowerShell从SharePoint网站下载文件。该脚本的目的是获取SharePoint文件并将其应用于Outlook以获取员工签名。我们已经创建了所需的员工签名,我们只需要将这些.htm文件部署到员工设备即可。我正在通过Office 365端点管理器(不再是Intune)运行此脚本,以部署到我的最终用户。脚本将在计算机上本地创建.htm文件,但是打开.htm文件时,它将带我到站点URL,没有为我提供实际的电子邮件签名-几乎就像命令仅在复制而不是在实际下载一样。关于如何添加到此脚本以从存储电子邮件签名的SharePoint网站下载相应文件的任何想法?还是我没有想到的另一个更简单的选择会更好?对于某些SharePoint功能还是新的功能,并且使Powershell与Sharepoint进行通信,所以请耐心等待。谢谢您的帮助。
使用以下代码来帮助构建脚本:https://github.com/marcusburst/scripts/blob/master/Powershell/Exchange/AutomaticOutlookSignature.ps1
进行调整以满足我的需求。
# Checks if outlook profile exists - we only want it to run on people who have a profile so they don't get an annoying profile popup #
$OutlookProfileExists = Test-Path
"C:\Users\$env:Username\AppData\Local\Microsoft\Outlook"
if ($OutlookProfileExists -eq $true) {
Write-Host "User Outlook profile exists.. continuing.." -ForegroundColor Yellow
# Signature Variables #
$ExternalSignatureName = 'External-Signature.htm'
$SigSource = 'https://SharePointSiteURLL'
$RepliesForwardsSignatureName = 'Replies-Forwards-Signature.htm'
$SigSource = 'https://SharePointSiteURL'
# Environment variables #
$AppData = $env:appdata
$SigPath = '\Microsoft\Signatures'
$LocalSignaturePath = $AppData + $SigPath
# Copy file #
If (!(Test-Path -Path $LocalSignaturePath)) {
New-Item -Path $LocalSignaturePath -Type Directory
}
# Check signature path #
if (!(Test-Path -path $LocalSignaturePath)) {
New-Item $LocalSignaturePath -Type Directory
}
# Copy signature templates from domain to local Signature-folder #
Write-Host "Copying Signatures" -ForegroundColor Green
Invoke-WebRequest -URI $Sigsource -Outfile "$LocalSignaturePath\$ExternalSignatureName"
Invoke-WebRequest -URI $SigSource -OutFile "$LocalSignaturePath\$RepliesForwardsSignatureName"
# Set as Default Signature #
If (Test-Path HKCU:'\Software\Microsoft\Office\16.0') {
Write-host "Setting signature for Office 2019"-ForegroundColor Green
Write-host "Setting signature for Office 2019 as available" -ForegroundColor Green
If ((Get-ItemProperty -Name 'First-Run' -Path HKCU:'\Software\Microsoft\Office\16.0\Outlook\Setup' -ErrorAction SilentlyContinue))
{
Remove-ItemProperty -Path HKCU:'\Software\Microsoft\Office\16.0\Outlook\Setup' -Name 'First-Run' -Force
}
If (!(Get-ItemProperty -Name 'External-Signature' -Path HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -ErrorAction SilentlyContinue))
{
New-ItemProperty -Path HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'Ext-Signature' -Value $ExternalSignatureName -PropertyType 'String' -Force
}
If (!(Get-ItemProperty -Name 'Replies-Forwards-Signature' -Path HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -ErrorAction SilentlyContinue))
{
New-ItemProperty -Path HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'Replies-Forwards-Signature' -Value $RepliesForwardsSignatureName -PropertyType 'String' -Force
}
}
# Removes files from recent items in file explorer #
Write-host "Cleaning up recent files list in File Explorer.." -ForegroundColor Yellow
Get-ChildItem -Path "$env:APPDATA\Microsoft\Windows\Recent" -File | Sort-Object LastWriteTime -Descending | Remove-Item
Get-ChildItem -Path "$env:APPDATA\Microsoft\Windows\Recent\AutomaticDestinations" -File | Sort-Object LastWriteTime -Descending | Remove-Item
}
解决方法
我想我前一段时间遇到了这个问题。我认为您的脚本很好,您只需确保Blob存储中有一个有效的令牌即可。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。