-
Notifications
You must be signed in to change notification settings - Fork 1
/
Intune-DocumentTemplateStorageAccount.ps1
98 lines (68 loc) · 3.96 KB
/
Intune-DocumentTemplateStorageAccount.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<#
.SYNOPSIS
Script will download new Office templates each time it runs.
.DESCRIPTION
Script connects to remote azure storage account, and download new Office templates.
Template are refresh each time script run and putted in dedicated folder.
.NOTES
File Name : Intune-DocumentTemplateStorageAccount.ps1
Author : Michal Machniak
Requires : PowerShell V5.1
.LINK
Github: https://github.com/mimachniak/sysopslife-scripts
Site: https://sysopslife.sys4ops.pl/
Modules links:
#>
#------------------------------------ Input parameters ------------------------------------------------- #
$LogLocation = 'C:\Users\Public\Documents\' # Location of lgs generated by execution of the script
$LogFileName = 'OfficeTemplates.log' # log file name
Start-Transcript -Path $LogLocation$LogFileName #Create log each run script
$storageAccountName = "dofficetemplate.blob.core.windows.net" # Azure Storage Acccount Url
$containerName = "office-template" # Azure storage account blob container with files
$TemplateFolderName = 'Office Templates' # Folder name on desktop when files willbe downloaded
$MyDocumentsPath = [Environment]::GetFolderPath("MyDocuments") # Get default location of Documents
$CustomTemplatesLocation = $MyDocumentsPath+"\"+$TemplateFolderName #Folder for custom templates
if ((Test-Path $CustomTemplatesLocation) -eq $false)
{
New-Item -Path $MyDocumentsPath -Name $TemplateFolderName -ItemType "directory"
}
$CustomWordTemplatesLocation = Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Word\Options" -Name "PersonalTemplates"
$CustomPowerPointTemplatesLocation = Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\PowerPoint\Options" -Name "PersonalTemplates"
if ($CustomWordTemplatesLocation -ne $null)
{
Write-Host "PersonalTemplates reg exist in HKCU:\SOFTWARE\Microsoft\Office\16.0\Word\Options"
}
else {
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Office\16.0\Word\Options -Name "PersonalTemplates" -Value $CustomTemplatesLocation -PropertyType ExpandString -Force # Setup custom temaplate folder for Word
}
if ($CustomPowerPointTemplatesLocation -ne $null)
{
Write-Host "PersonalTemplates reg exist in HKCU:\SOFTWARE\Microsoft\Office\16.0\PowerPoint\Options"
}
else {
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Office\16.0\PowerPoint\Options -Name "PersonalTemplates" -Value $CustomTemplatesLocation -PropertyType ExpandString -Force # Setup custom temaplate folder for PowerPoint
}
if ($CustomPowerPointTemplatesLocation -ne $null)
{
Write-Host "PersonalTemplates reg exist in HKCU:\SOFTWARE\Microsoft\Office\16.0\Excel\Options"
}
else {
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Office\16.0\PowerPoint\Options -Name "PersonalTemplates" -Value $CustomTemplatesLocation -PropertyType ExpandString -Force # Setup custom temaplate folder for PowerPoint
}
write-host "https://$storageAccountName/$containerName/?comp=list" # URL with files
$xml = Invoke-WebRequest -Method Get -Uri "https://$storageAccountName/$containerName/?comp=list" -ContentType "application/xml" -UseBasicParsing # Get All files in Blob Container without SAS token
[xml] $i = $xml.Content -replace "", ""
$ListBlobs = $i.EnumerationResults.Blobs.Blob
foreach ($BlobFile in $ListBlobs)
{
$TemplatesLocation = $CustomTemplatesLocation+"\"+$BlobFile.Name
Write-Host "Location of file [$TemplatesLocation]"
$fileDownloadBlob = try {
Invoke-WebRequest -Uri $BlobFile.Url -OutFile $TemplatesLocation
Write-Host "File downloaded [$($BlobFile.Name)]"
}
catch [System.Net.WebException] {
Write-Warning "Exception was caught: $($_.Exception.Message)"
}
}
Stop-Transcript # End logging