首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过Powershell从SharePoint下载文件

通过Powershell从SharePoint下载文件
EN

Stack Overflow用户
提问于 2020-08-12 01:23:07
回答 1查看 894关注 0票数 0

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

做了一些调整以满足我的需求。

代码语言:javascript
运行
复制
# 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

}
EN

回答 1

Stack Overflow用户

发布于 2020-08-16 11:33:07

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63363330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档