t32 GetDeviceInformation(string DeviceID, ref IntPtr DevInfoSet, ref SP_DEVINFO_DATA DevInfo)
        {
            DevInfoSet = SetupDiCreateDeviceInfoList(IntPtr.Zero, IntPtr.Zero);
            if (DevInfoSet == IntPtr.Zero)
            {
                return (UInt32)Marshal.GetLastWin32Error();
            }

            DevInfo.Size = (UInt32)Marshal.SizeOf(DevInfo);

            if(0 == SetupDiOpenDeviceInfo(DevInfoSet, DeviceID, IntPtr.Zero, 0, ref DevInfo))
            {
                SetupDiDestroyDeviceInfoList(DevInfoSet);
                return ERROR_CLASS_MISMATCH;
            }
            return 0;
        }

        public static void ReleaseDeviceInfoSet(IntPtr DevInfoSet)
        {
            SetupDiDestroyDeviceInfoList(DevInfoSet);
        }

        public static UInt32 EnableDevice(string DeviceID, bool Enable, bool IsGlobal)
        {
            UInt32 ResultCode = 0;
            IntPtr DevInfoSet = IntPtr.Zero;
            SP_DEVINFO_DATA DevInfo = new SP_DEVINFO_DATA();

            ResultCode = GetDeviceInformation(DeviceID, ref DevInfoSet, ref DevInfo);

            if (0 == ResultCode)
            {
                SP_PROPCHANGE_PARAMS Params = new SP_PROPCHANGE_PARAMS();
                Params.ClassInstallHeader.Size = Marshal.SizeOf(typeof(SP_CLASSINSTALL_HEADER));
                Params.ClassInstallHeader.InstallFunction = (int)DIF_PROPERTYCHANGE;
                Params.StateChange = Enable ? DICS_ENABLE : DICS_DISABLE;
                Params.Scope = IsGlobal ? DICS_FLAG_GLOBAL : DICS_FLAG_CONFIGSPECIFIC;
                Params.Profile = 0;

                IntPtr ChangeParams = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SP_PROPCHANGE_PARAMS)));
                Marshal.StructureToPtr(Params, ChangeParams, true);
                IntPtr ptrDevInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SP_DEVINFO_DATA)));
                Marshal.StructureToPtr(DevInfo, ptrDevInfo, true);

                if (1 != SetupDiSetClassInstallParams(DevI# Copyright  2008, Microsoft Corporation. All rights reserved.


#TS_HardwareDevice
PARAM($DeviceID, $Action)

Import-LocalizedData -BindingVariable localizationString -FileName CL_LocalizationData

. .\DB_DeviceErrorLibrary.ps1

$RootCauseAdded = $false
Write-DiagProgress -activity $localizationString.Troubleshoot_DeviceDisabled

$ProblemDevice = Get-WmiObject -Class Win32_PnPEntity | Where-Object -FilterScript {$_.DeviceID -eq $DeviceID}

if(($ProblemDevice -ne $Null) -and ($ProblemDevice.ConfigManagerErrorCode -ne $Null))
{
    [string]$DeviceName = $ProblemDevice.Name
    [string]$ErrorCode = $ProblemDevice.ConfigManagerErrorCode

    if ([String]::IsNullOrEmpty($DeviceName))
    {
        $DeviceName = $localizationString.UnknownDevice
    }

    if($HashDisabled.Contains($ErrorCode) -eq $True)
    {
        Update-DiagRootCause -id RC_DeviceDisabled -iid $DeviceID -Detected $true -p @{'DeviceName'= $DeviceName; 'DeviceID'= $DeviceID; 'ErrorCode'= $ErrorCode}
        $ProblemDevice | Select-Object -Property @{Name=$localizationString.DeviceName; Expression={$_.Name}}, @{Name=$localizationString.PnPDeviceID; Expression={$_.PNPDeviceID}}, @{Name=$localizationString.ConfigManagerErrorCode; Expression={$_.ConfigManagerErrorCode}} | ConvertTo-XML | Update-DiagReport -ID DeviceDisabled -Name $localizationString.Report_Name_ProblemDevice -Verbosity Informational -rid RC_DeviceDisabled -riid $DeviceID
        $RootCauseAdded = $True
    }
    else
    {
        if ($Action -eq "Verify")
        {
            Update-DiagRootCause -id RC_DeviceDisabled -iid $DeviceID -Detected $false -p @{'DeviceName'= $DeviceName; 'DeviceID'= $DeviceID; 'ErrorCode'= $ErrorCode}
        }
    }
}

return $RootCauseAdded
