0

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.')
 }
 }`
David Makogon
71k22 gold badges145 silver badges204 bronze badges
asked Dec 4, 2023 at 1:39
5
  • 2
    In PowerShell, = is only for assignment. For equality comparison you want -eq, eg.: $RAIDDEV.ConfigManagerErrorcode -eq 10 Commented Dec 4, 2023 at 13:18
  • 1
    Similarly, do not use = to separate a parameter name from its value: use a space, e.g. -FilePath "C:\Devmanview\Restart Adaptec RAID 6805.bat" (a less common alternative is :) Commented Dec 4, 2023 at 15:08
  • Additionally, use $null to represent a null value in PowerShell. In a statement such as $RDEVIID=NULL, NULL is interpreted as a command name. To test a value for $null, place $null on the LHS, to avoid potential side effects from PowerShell's array-filtering behavior with an array-valued LHS: if ($null -eq $RDEVIID). You also do not need to initialize $RDEVIID with $null, because by default $RAIDDEV.InstanceId implicitly evaluates to $null if $RDEVIID is either itself $null or doesn't have an .InstanceId property. Commented Dec 4, 2023 at 15:52
  • To extend other comments, you might want to review some beginner guides to Powershell just to learn some syntax differences from the other languages you’ve been using. The "pipeline" and "output stream" for example take a bit of getting used to at first, as does equality comparison to $null (which is not commutative in all scenarios), and not using round brackets for function calls, which is another one that crops up regularly from people new to Powershell. You’ve not tripped over them in your question, but fore-warned is fore-armed :-). Commented Dec 4, 2023 at 21:14
  • Please read How to Ask and how to create a minimal reproducible example. I removed a lot of unneeded text, as this question is already enormous - and the backstory doesn’t help - it just makes your question hard to read/understand. Commented Dec 10, 2023 at 4:56

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.