I have an older Adaptec RAID Controller card (6805/6805Q) that controls a number of RAID1 arrays. This card has no issues with a Windows system running in the older MBR mode, but for the newer UEFI mode while the card can can work, Windows has issues starting the card (error code 10, this device could not start, or be started).
The solution to this was to go into Device Manager, go to the entry for the RAID card (under storage controllers) and proceed to disable and then enable the card. Once that was done, Windows would see the drives no problem.
For a while I would need to do this manually, but I found a program, Devmanview, that allow me to set up a batch file that could do this disabling and enabling via command line arguments. I put a shortcut to the batchfile in my Startup folder and that saved me having to do this every time manually, but I want to improve things a bit, which is where PowerShell comes into play as I don't want the batch file running if Windows started the device correctly already (such as from me logging out of the machine and back in).
Looking around the Internet I have seen others hunt down devices two ways:
A. Via known Instance ID's using the WMI Object, or
B. Getting that through Get-PnpDevice with a where and -Like setup (which is what I'm trying to use).
I have added some debugging to this code to try and see what I'm getting and even added VS Code and an inspection library that upon hovering over a variable should show me the contents, but neither the added debugging or variable check gets me anything. The script itself gets only so far before complaining about a line not having the error status property I'm looking for.
Process Flow: A. Find the RAID Card B. Check Error Status C. If 10 (could not start), run Devmanview batch file to resrt the device. D. Done.
The code without debugging:
Add-Type -AssemblyName PresentationCore,PresentationFramework //Needed for mesage boxes.
#Possible way to check device
$RAIDDEV = Get-PnpDevice | Where {$_.FriendlyName -Like 'Adeptec RAID 6805/6805Q'}
The Firendly Name comes from Device manager.
Above line should find the device and I was hoping for this to allow me to access device properties directly including the error status.
#Since we have the deive from above, add its Instance ID here and use
#that for further checks if needed.
$RDEVIID=NULL #Set empty.
$RDEVIID=$RAIDDEV.InstanceId
I was trying to store the Instance ID in case I needed to use another method to get where I want to go. VS Code is complaining that $RDEVIID is never used, obvioulsy wrong as it should pick up the Instance ID and I did have an if statement checking if the variable was still NULL. Hovering gets me no information. This was part of my debugging attempts.
if ($RAIDDEV.ConfigManagerErrorcode = 10)
{
#Run Devmanview to restart the device
Start-Process -FilePath="C:\Devmanview\Restart Adaptec RAID 6805.bat" //Should get the batch
//file to run.
[System.Windows.MessageBox]::Show('RAID Device Restarted.')
}
else
{
[System.Windows.MessageBox]::Show('RAID Device is working properly this time.')
}
The If line above is the one PowerShell is choking on. Devices have this property and I have seen this error code when I was doing manual restart of the device. This may be a part of WMI-Object, unknown.
I am aware PowerShell has the ability to do diabling and enabling of devices, so that may replace the batch file at a later point, but I'd need to get to the point where the batch file section comes into play.
The IF debug line to check on an instance ID was getting the same variable unused by VS Code, not sure why, as I checked the code and the names are spelled correctly. As far as I know I'm not hitting on reserved words other than what is expectedd (like NULL).
Here is the code with debugging installed:
`Add-Type -AssemblyName PresentationCore,PresentationFramework
#Possible way to check device
$RAIDDEV = Get-PnpDevice | Where {$_.FriendlyName -Like 'Adeptec RAID 6805/6805Q'}
#Since we have the deive from above, add its Instance ID here and use
#that for further checks.
$RDEVIID=NULL #Set empty.
$RDEVIID=$RAIDDEV.InstanceId
if ($RDEVIID = NULL)
{
[System.Windows.MessageBox]::Show('Instance ID not picked up.')
}
else
{
[System.Windows.MessageBox]::Show('Instance ID is picked up.')
if ($RAIDDEV.ConfigManagerErrorcode = 10)
{
#Run Devmanview to restart the device
Start-Process -FilePath="C:\Devmanview\Restart Adaptec RAID 6805.bat"
[System.Windows.MessageBox]::Show('RAID Device Restarted.')
}
else
{
[System.Windows.MessageBox]::Show('RAID Device is working properly this time.')
}
}`