【问题标题】:Download file from SharePoint through Powershell通过 Powershell 从 SharePoint 下载文件
【发布时间】:2020-12-01 10:09:51
【问题描述】:

我正在尝试通过 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: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

}

【问题讨论】:

    标签: powershell sharepoint intune


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-09-22
      • 1970-01-01
      • 1970-01-01
      • 2015-05-10
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 2022-08-05
      • 2022-01-02
      相关资源
      最近更新 更多