84 lines
2.7 KiB
PowerShell
84 lines
2.7 KiB
PowerShell
#Requires -RunAsAdministrator
|
|
<#
|
|
.SYNOPSIS
|
|
Installs prerequisites for SharePoint XLS Converter application
|
|
#>
|
|
|
|
# Enable TLS 1.2 for secure connections
|
|
[Net.ServicePointManager]::SecurityProtocol = [enum]::Parse([Net.SecurityProtocolType], "Tls12")
|
|
|
|
Write-Host "Installing required modules..." -ForegroundColor Cyan
|
|
|
|
# Install Microsoft.Graph modules
|
|
$graphModules = @(
|
|
"Microsoft.Graph.Sites",
|
|
"Microsoft.Graph.Files",
|
|
"Microsoft.Graph.Authentication"
|
|
)
|
|
|
|
foreach ($module in $graphModules) {
|
|
if (-not (Get-Module -ListAvailable -Name $module)) {
|
|
try {
|
|
Install-Module $module -Scope CurrentUser -Force -AllowClobber
|
|
Write-Host "$module module installed successfully" -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Host "Failed to install ${module}: $($_.Exception.Message)" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "$module module is already installed" -ForegroundColor Yellow
|
|
}
|
|
}
|
|
|
|
# Install OpenXML via NuGet package (not module)
|
|
try {
|
|
# Install NuGet package provider if not exists
|
|
if (-not (Get-PackageProvider -Name NuGet)) {
|
|
Install-PackageProvider -Name NuGet -Force
|
|
}
|
|
|
|
# Install OpenXML SDK package
|
|
$openXmlPackage = Install-Package DocumentFormat.OpenXml -Source https://www.nuget.org/api/v2/ -Force -SkipDependencies
|
|
$dllPath = Join-Path $openXmlPackage.PackageSource "lib\net46\DocumentFormat.OpenXml.dll"
|
|
|
|
if (Test-Path $dllPath) {
|
|
Add-Type -Path $dllPath
|
|
Write-Host "DocumentFormat.OpenXml assembly loaded successfully" -ForegroundColor Green
|
|
}
|
|
else {
|
|
throw "OpenXML DLL not found at $dllPath"
|
|
}
|
|
}
|
|
catch {
|
|
Write-Host "Failed to install DocumentFormat.OpenXml: $($_.Exception.Message)" -ForegroundColor Red
|
|
Write-Host "You may need to install the Open XML SDK manually from:"
|
|
Write-Host "https://www.microsoft.com/en-us/download/details.aspx?id=30425" -ForegroundColor Yellow
|
|
}
|
|
|
|
# Check for Excel installation
|
|
try {
|
|
$excelCheck = New-Object -ComObject Excel.Application -ErrorAction Stop
|
|
$excelCheck.Quit()
|
|
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelCheck) | Out-Null
|
|
Write-Host "Microsoft Excel is installed" -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Host @"
|
|
Microsoft Excel not found! The conversion feature requires:
|
|
1. Microsoft Excel 2013 or newer
|
|
2. PowerShell must run in STA mode
|
|
Run the main script like this:
|
|
powershell.exe -STA -File .\MainForm.ps1
|
|
"@ -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host @"
|
|
Installation complete! Run the main application with:
|
|
powershell.exe -STA -File .\MainForm.ps1
|
|
|
|
Note: First run might take longer while modules load
|
|
"@ -ForegroundColor Green
|