This script runs without the restart option
wmic product where “name like ‘Forti%%’” call uninstall /nointeractive
With the No restart option it would not execute
wmic product where “name like ‘Forti%%’” call uninstall /nointeractive|wmic && shutdown /a
I want to ensure that I can use this script or convert this to a PowerShell script and run this through INTUNE. Unfortunately, I wrote a PowerShell script and that does not work also and it would error out. I heard that it is tough to remove Forticlient, I do not want to run this script and make all computers reboot. Which is why I need something that would be solid and will also remove it successfully.
Get the product with a name like ‘Forti’
$fortiProduct = Get-WmiObject -Query “SELECT * FROM Win32_Product WHERE Name LIKE ‘Forti%’”
Check if the product was found
if ($fortiProduct -ne $null) {
# Uninstall the product
$uninstallResult = $fortiProduct.Uninstall()
# Check the result of the uninstallation
if ($uninstallResult.ReturnValue -eq 0) {
Write-Host "Uninstall successful."
# Shutdown the computer
Stop-Computer -Force
} else {
Write-Host "Uninstall failed with error code $($uninstallResult.ReturnValue)."
}
} else {
Write-Host “No product found with a name like ‘Forti’.”
}
When I run the Powershell script, I get the error code
Uninstall failed with error code 1603.
Before we proceed: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
( !! Sometimes the preformatted text button hides behind the settings gear symbol. )
In a PowerShell console? Really? And there are no errors?
I am actually unsure why you’re using a pipe here. Should the output of the first wmic command be the input of the second one? That’s what a pipe is used for - reading the output of one command and using it as input for another second one.
And the command separator in PowerShell is a semicolon (;) - not a double ampersand (&&).
Regardless of that - If you’re running this in PowerShell you may use internal commands rather than external ones.
BTW: The parameter /a for the external comamnd shutdown cancels an anogoing shutdown.
If you get errors you should share them here copmpletely (formatted as code as well please). Errors are an important language feature telling you what’S wrong and sometimes even tellung how to do it better.
??? I’m prety sure it is manageble to figure out the needed command line to actually uninstall an installed app.
You should not use Get-WmiObject anymore as it is depricated. Use Get-CimInstance instead.
When you compare agains NULL, NULL should be on the left hand side of the comparison.
1603 is an MSI error - not PowerShell - A fatal error occurred during installation.
BTW: When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you potentially wasting their time.