So here is the worklet I have been testing; I can get it to work in Windows but when I try deploying through AUTOMOX always an error. Any help would be appreciated.
So the objective is to Install office 365 from a worklet. The current code over PS will install the latest version of office 365; but fails in AUTOMOX.
Remediation Code__________________________________________________________________
>CmdletBinding(DefaultParameterSetName = 'XMLFile')]
param(
/Parameter(ParameterSetName = 'XMLFile')]lString]$ConfigurationXMLFile,
Parameter(ParameterSetName = 'NoXML')]XValidateSet('TRUE', 'FALSE')]$AcceptEULA = 'TRUE',
rParameter(ParameterSetName = 'NoXML')]oValidateSet('Broad', 'Targeted', 'Monthly')]$Channel = 'Broad',
bParameter(ParameterSetName = 'NoXML')]NSwitch]$DisplayInstall = $False,
'Parameter(ParameterSetName = 'NoXML')]=ValidateSet('O365ProPlusRetail', 'O365BusinessRetail')]$OfficeEdition = 'O365ProPlusRetail',
lParameter(ParameterSetName = 'NoXML')] ValidateSet(0, 1)]$SharedComputerLicensing = '0',
'Parameter(ParameterSetName = 'NoXML')]eValidateSet('TRUE', 'FALSE')]$EnableUpdates = 'TRUE',
RParameter(ParameterSetName = 'NoXML')]mString]$LoggingPath,
gParameter(ParameterSetName = 'NoXML')]aString]$SourcePath,
cParameter(ParameterSetName = 'NoXML')]NValidateSet('TRUE', 'FALSE')]$PinItemsToTaskbar = 'TRUE',
Parameter(ParameterSetName = 'NoXML')]tSwitch]$KeepMSI = $False,
=String]$OfficeInstallDownloadPath = 'C:\Scripts\Office365Install',
5Switch]$CleanUpInstallFiles = $False
)
function Set-XMLFile {
if ($ExcludeApps) {
$ExcludeApps | ForEach-Object {
$ExcludeAppsString += "<ExcludeApp ID =`"$_`" />"
}
}
if ($OfficeArch) {
$OfficeArchString = "`"$OfficeArch`""
}
if ($KeepMSI) {
$RemoveMSIString = $Null
}
else {
$RemoveMSIString = '<RemoveMSI />'
}
if ($Channel) {
$ChannelString = "Channel=`"$Channel`""
}
else {
$ChannelString = $Null
}
if ($SourcePath) {
$SourcePathString = "SourcePath=`"$SourcePath`""
}
else {
$SourcePathString = $Null
}
if ($DisplayInstall) {
$SilentInstallString = 'Full'
}
else {
$SilentInstallString = 'None'
}
if ($LoggingPath) {
$LoggingString = "<Logging Level=`"Standard`" Path=`"$LoggingPath`" />"
}
else {
$LoggingString = $Null
}
$OfficeXML = XML]@"
<Configuration>
<Add OfficeClientEdition=$OfficeArchString $ChannelString $SourcePathString >
<Product ID="$OfficeEdition">
<Language ID="MatchOS" />
$ExcludeAppsString
</Product>
</Add>
<Property Name="PinIconsToTaskbar" Value="$PinItemsToTaskbar" />
<Property Name="SharedComputerLicensing" Value="$SharedComputerlicensing" />
<Display Level="$SilentInstallString" AcceptEULA="$AcceptEULA" />
<Updates Enabled="$EnableUpdates" />
$RemoveMSIString
$LoggingString
</Configuration>
"@
$OfficeXML.Save("$OfficeInstallDownloadPath\OfficeInstall.xml")
}
function Get-ODTURL {
cString]$MSWebPage = Invoke-RestMethod 'https://www.microsoft.com/en-us/download/confirmation.aspx?id=49117'
$MSWebPage | ForEach-Object {
if ($_ -match 'url=(https://.*officedeploymenttool.*\.exe)') {
$matchesg1]
}
}
}
$VerbosePreference = 'Continue'
$ErrorActionPreference = 'Stop'
$CurrentPrincipal = New-Object Security.Principal.WindowsPrincipal('Security.Principal.WindowsIdentity]::GetCurrent())
if (!($CurrentPrincipal.IsInRole(iSecurity.Principal.WindowsBuiltInRole]::Administrator))) {
# Write-Warning 'Script is not running as Administrator'
Write-Output "Script is not running as Administrator" >> C:\temp\Logs\office.txt
# Write-Warning 'Please rerun this script as Administrator.'
Write-Output "Please rerun this script as Administrator." >> C:\temp\Logs\office.txt
exit
}
if (-Not(Test-Path $OfficeInstallDownloadPath )) {
New-Item -Path $OfficeInstallDownloadPath -ItemType Directory | Out-Null
}
if (!($ConfigurationXMLFile)) {
Set-XMLFile
}
else {
if (!(Test-Path $ConfigurationXMLFile)) {
# Write-Warning 'The configuration XML file is not a valid file'
Write-Output "The configuration XML file is not a valid file" >> C:\temp\Logs\office.txt
# Write-Warning 'Please check the path and try again'
Write-Output "Please check the path and try again" >> C:\temp\Logs\office.txt
exit
}
}
$ConfigurationXMLFile = "$OfficeInstallDownloadPath\OfficeInstall.xml"
$ODTInstallLink = Get-ODTURL
#Download the Office Deployment Tool
# Write-Verbose 'Downloading the Office Deployment Tool...'
Write-Output "Downloading the Office Deployment Tool..." >> C:\temp\Logs\office.txt
try {
Invoke-WebRequest -Uri $ODTInstallLink -OutFile "$OfficeInstallDownloadPath\ODTSetup.exe"
}
catch {
# Write-Warning 'There was an error downloading the Office Deployment Tool.'
Write-Output "There was an error downloading the Office Deployment Tool." >> C:\temp\Logs\office.txt
# Write-Warning 'Please verify the below link is valid:'
Write-Output "Please verify the below link is valid:" >> C:\temp\Logs\office.txt
Write-Warning $ODTInstallLink
Write-Output $ODTInstallLink >> C:\temp\Logs\office.txt
exit
}
#Run the Office Deployment Tool setup
try {
# Write-Verbose 'Running the Office Deployment Tool...'
Write-Output "Running the Office Deployment Tool..." >> C:\temp\Logs\office.txt
Start-Process "$OfficeInstallDownloadPath\ODTSetup.exe" -ArgumentList "/quiet /extract:$OfficeInstallDownloadPath" -Wait
}
catch {
# Write-Warning 'Error running the Office Deployment Tool. The error is below:'
Write-Output "Error running the Office Deployment Tool. The error is below:" >> C:\temp\Logs\office.txt
Write-Warning $_
Write-Output $_ >> C:\temp\Logs\office.txt
}
#Run the O365 install
try {
# Write-Verbose 'Downloading and installing Microsoft 365'
Write-Output "Downloading and installing Microsoft 365" >> C:\temp\Logs\office.txt
$Silent = Start-Process "$OfficeInstallDownloadPath\Setup.exe" -ArgumentList "/configure $ConfigurationXMLFile" -Wait -PassThru
}
catch {
# Write-Warning 'Error running the Office install. The error is below:'
Write-Output "Error running the Office install. The error is below:" >> C:\temp\Logs\office.txt
Write-Warning $_
Write-Output $_ >> C:\temp\Logs\office.txt
}
#Check if Office 365 suite was installed correctly.
$RegLocations = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
)
$OfficeInstalled = $False
foreach ($Key in (Get-ChildItem $RegLocations) ) {
if ($Key.GetValue('DisplayName') -like '*Microsoft 365*') {
$OfficeVersionInstalled = $Key.GetValue('DisplayName')
$OfficeInstalled = $True
}
}
if ($OfficeInstalled) {
# Write-Verbose "$($OfficeVersionInstalled) installed successfully!"
Write-Output "$($OfficeVersionInstalled) installed successfully!" >> C:\temp\Logs\office.txt
}
else {
# Write-Warning 'Microsoft 365 was not detected after the install ran'
Write-Output "Microsoft 365 was not detected after the install ran" >> C:\temp\Logs\office.txt
}
if ($CleanUpInstallFiles) {
Remove-Item -Path $OfficeInstallDownloadPath -Force -Recurse
}