I've been trying to find an answer to this peculiar question but haven't had any luck. For work, I've been creating a tiny little script that would help my colleagues and I with the repetitive tasks of preconfiguring new laptops for our clients.
I'm aware that what I'm going to ask is probably not the most efficient method, but I am curious regardless!
I'm at the point in my little script where I want it to write the lines for a temporary second script, run it and then remove it afterwards. However, I fail to have this work correctly. I'm assuming this is because of special characters but I could be wrong.
The method I'm trying to use is to have it echo the actual commands to a file. In the end, I'm hoping to have it create a working .PS1 script, execute it and then delete it.
The commands I want it to write to a file:
$OfficeUninstallStrings = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where {$_.DisplayName -like "*Microsoft Office 365*"} | Select UninstallString).UninstallString
ForEach ($UninstallString in $OfficeUninstallStrings) {
$UninstallEXE = ($UninstallString -split '"')[1]
$UninstallArg = ($UninstallString -split '"')[2] + " DisplayLevel=False"
Start-Process -FilePath $UninstallEXE -ArgumentList $UninstallArg -Wait
}
Would anyone be able to help me figure out what I'm overlooking?
Thank you!