Score:0

Installing O365 via powershell inside an ISO

us flag

I created an Office 365 installer where it does the local installation and dynamically changes the SourcePath, and I need to run it from an ISO file (I normally use USB's, but in VM's I use ISO)

Running locally in any directory or USB it works perfectly, but from an ISO it doesn't, the error appears:

Set-Content : Access to path 'C:\Users\Administrator\AppData\Local\Temp\tmpoffice\configuration.xml' was denied. No E:\SMS\PKG\CM10017B\InstallOffice_OfflineMode.ps1:24 character:164
+ ... fficeMgmtCOM="TRUE" SourcePath="'+$PS1dirEOL) | Set-Content $tempconf
+ ~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo : NotSpecified: (:) [Set-Content], UnauthorizedAccessException
     + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetContentCommand

How do I get this to work also within an ISO? I know an ISO is read-only, but I thought it was strange that he would try to modify something that is not in the ISO but in a temporary directory and he still can't.

$PS1dir = Get-Location

#Paths of the configuration
$tempdir = "$env:TEMP\tmpoffice"
$conf = "$($PS1dir)\configuration.xml"
$tempconf = "$env:TEMP\tmpoffice\configuration.xml"

#Current path with reformated end of XML line
$PS1dirEOL = "$($PS1dir)`" `AllowCdnFallback=`"TRUE`">"

#Copy configuration file for temp folder and set variable for same
Copy-Item $conf -Destination (New-Item -Path $tempdir -Type Directory -Force) -Recurse -Force

#Replace old line with the current folder
(Get-Content $tempconf) -replace '<Add OfficeClientEdition=.*', ('<Add OfficeClientEdition="64" Channel="Current" OfficeMgmtCOM="TRUE" SourcePath="'+$PS1dirEOL) | Set-Content $tempconf

#Running O365 installation from new configuration file
Start-Process cmd.exe -ArgumentList "/c start /MIN $($PS1dir)\setup.exe /configure $tempconf" -Wait

Remove-Item -Path $tempdir -Force -Recurse
in flag
Is Defender active? Lately I find more often Defender preventing access to files and directories that should be no problem. And it doesn't always show a notification.
AegisShimon avatar
us flag
Yes, it is enabled, but it is bizarre to have to disable defender to copy a file to a temporary folder, considering that doing this without being from an ISO this problem does not happen. The command that is failing seems to be Set-Content, but when I analyzed more, it doesn't even copy the file to the temporary folder, which is very strange.
Score:0
in flag

The problem is, that the file is read only. All files on .iso images get the readonly attribute and tha attribute is kept when you copy the file. You need to remove it before you can edit the file.

Set-ItemProperty $tempconf -Name IsReadOnly -Value $false

But this is not the only issue. After removing the ReadOnly attribute, you'll run into the next error, telling you that it can't write into the file because it is being used by another process (because Get-Content is still active). You'll need to use a temporary variable.

$conf = (Get-Content $tempconf) -replace '<Add OfficeClientEdition=.*', ('<Add OfficeClientEdition="64" Channel="Current" OfficeMgmtCOM="TRUE" SourcePath="'+$PS1dirEOL)
$conf | Set-Content $tempconf
AegisShimon avatar
us flag
Perfect, this really solved my problem, THANK YOU SO MUCH!, I took the opportunity and changed the name of the variables to be more within the best practices, and now I can do the installation using a SourcePath in an offline SCCM ISO (because before it was not possible, since SCCM changes the Office SMS PKG path all the time during installation)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.