# |Version=1.0.0.1|

# * DELL PROPRIETARY INFORMATION
# *
# * This software is confidential.  Dell Inc., or one of its subsidiaries, has
# * supplied this software to you under the terms of a license agreement,
# * nondisclosure agreement or both.  You may not copy, disclose, or use this 
# * software except in accordance with those terms.
# * 
# * Copyright 2017-2018 Dell Inc.  All Rights Reserved.
# *
# * DELL INC. MAKES NO REPRESENTATIONS OR WARRANTIES
# * ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS
# * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. DELL SHALL
# * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
# * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
# * THIS SOFTWARE OR ITS DERIVATIVES.



##### Defining Error Action Preference #####
#Abstract: Setting the value to continue, ensures script execution does not terminate if there is a failure with a certain command. A value set to Stop will halt script execution upon failure.
$OS=(Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\WNT").OS
$ErrorActionPreference = "Continue"
$HWPlatform = (Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\WNT).HWPlatform
function Get-TimeStamp {
    
    return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
    
}


try{

        if ($OS -eq 'WES7P' -and ($HWPlatform -eq 51 -or $HWPlatform -eq 500 -or $HWPlatform -eq 61 -or $HWPlatform -eq 69 -or $HWPlatform -eq 70)){
            #iex "msiexec.exe /x 'C:\Temp\Win7\vs64\Intel Bluetooth.msi' /qn /norestart"
            Start-Process "C:\Temp\Win7\vs64\Setup.exe" "/qn /x /norestart" -Wait

            Write-Output "$(Get-TimeStamp)Intel Bluetooth driver Uninstalled succesfully" | Out-file C:\Intel_Bluetooth.txt -Force -append
        }

        elseif ($OS -eq 'WES7' -and ($HWPlatform -eq 51 -or $HWPlatform -eq 60 -or $HWPlatform -eq 503 -or $HWPlatform -eq 61 -or $HWPlatform -eq 69 -or $HWPlatform -eq 70)){ 
            #iex "msiexec.exe /x 'C:\Temp\Win7\vs32\Intel Bluetooth.msi' /qn /norestart"
            Start-Process "C:\Temp\Win7\vs32\Setup.exe" "/qn /x /norestart" -Wait
            Write-Output "$(Get-TimeStamp)Intel Bluetooth driver Uninstalled succesfully" | Out-file C:\Intel_Bluetooth.txt -Force -append
        }

        elseif ($OS -eq 'WIE10' -and ($HWPlatform -eq 500 -or $HWPlatform -eq 69 -or $HWPlatform -eq 70)){ 
            #iex "msiexec.exe /x 'C:\Temp\Win10\Intel Bluetooth.msi' /qn /norestart"
           # Start-Process "C:\Temp\Win7\vs64\Setup.exe" "/qn /x /norestart" -Wait
             Start-Process "C:\Temp\Win10\Setup.exe" "/qn /x /norestart" -Wait
            Write-Output "$(Get-TimeStamp)Intel Bluetooth driver Uninstalled succesfully" | Out-file C:\Intel_Bluetooth.txt -Force -append
        }

        sleep 5
        Remove-Item 'HKLM:\SOFTWARE\WNT\Packages\IntelBluetoothDriver' -Force
        Write-Output "$(Get-TimeStamp) Intel Bluetooth uninstalled updated in WNT registry to view in WDM packages section of Dell thin client information" | Out-file C:\Intel_Bluetooth.txt -Force -append

        else{
            Write-Output "$(Get-TimeStamp) Supported OS or platform not found" | Out-file C:\Intel_Bluetooth.txt -Force -append
        }
        Exit 0
    }
Catch{
        Exit 1
     }
    


 