0
votes

I am trying to download a file from a SharePoint site through PowerShell. The objective of this script is to take the SharePoint file and apply it to Outlook for employee signatures. We already have created the employee signatures that we want, we just need to deploy those .htm files to the employee devices. I am running this script through Office 365 Endpoint Manager (no longer Intune) to deploy to my end users. The Script will create the .htm files locally on a machine, however when opening the .htm file it takes me to the site url, not providing me with the actual email signature - almost like the command is only copying and not actually downloading. Any thoughts on how to add onto this script to download the respective file from the SharePoint site, where the email signatures are stored? Or is there another, easier option that I am not thinking about that could work better? Still a little new to some SharePoint functions and getting Powershell to communicate with Sharepoint, so please bear with me. Thank you for your help.

Used this code to help build the script: https://github.com/marcusburst/scripts/blob/master/Powershell/Exchange/AutomaticOutlookSignature.ps1

Made adjustments to help fit my needs.

# 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

}
1

1 Answers

0
votes

I think i ran into this issue a while back. I think your script it fine, you just have to make sure there's a valid token in your blob storage.