通过Powershell从SharePoint下载文件



我正试图通过PowerShell从SharePoint网站下载文件。此脚本的目标是获取SharePoint文件并将其应用于Outlook以获得员工签名。我们已经创建了我们想要的员工签名,我们只需要将这些.htm文件部署到员工设备上。我正在通过Office 365 Endpoint Manager(不再是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:UsernameAppDataLocalMicrosoftOutlook"
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 = 'MicrosoftSignatures' 
$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:'SoftwareMicrosoftOffice16.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:'SoftwareMicrosoftOffice16.0OutlookSetup' -ErrorAction SilentlyContinue))   
{  
Remove-ItemProperty -Path HKCU:'SoftwareMicrosoftOffice16.0OutlookSetup' -Name 'First-Run' -Force  
}  
If (!(Get-ItemProperty -Name 'External-Signature' -Path HKCU:'SoftwareMicrosoftOffice16.0CommonMailSettings' -ErrorAction SilentlyContinue))   
{  
New-ItemProperty -Path HKCU:'SoftwareMicrosoftOffice16.0CommonMailSettings' -Name 'Ext-Signature' -Value $ExternalSignatureName -PropertyType 'String' -Force  
}  
If (!(Get-ItemProperty -Name 'Replies-Forwards-Signature' -Path HKCU:'SoftwareMicrosoftOffice16.0CommonMailSettings' -ErrorAction SilentlyContinue))   
{  
New-ItemProperty -Path HKCU:'SoftwareMicrosoftOffice16.0CommonMailSettings' -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:APPDATAMicrosoftWindowsRecent" -File | Sort-Object LastWriteTime -Descending | Remove-Item
Get-ChildItem -Path "$env:APPDATAMicrosoftWindowsRecentAutomaticDestinations" -File | Sort-Object LastWriteTime -Descending | Remove-Item
}

我想我不久前遇到了这个问题。我认为你的脚本很好,你只需要确保你的blob存储中有一个有效的令牌。

最新更新