Hi Wilson,
Add a condition statement before calling 'Statwith' method on the
$devicename.
$devicename = $driver.Devicename
if (!$devicename) { continue }
if ($devicename.Startswith("Smart Array"))
Tao Ma
"Wilson" <Wilson@xxxxxx> 写入消息新闻:2AF91A85-AF3F-4523-AE91-3E22F172DE3D@xxxxxx
> Hi
>
> I wrote a PS script which gets registry informations about specific
> drivers.
> Here is the code:
> ----------------------------------------------------------------
> $computer = "nodename1","nodename2"
> foreach($nodename in $computer){
> $PnP = Get-WMIObject Win32_PnPSignedDriver -computer $nodename
> write-host " "
> write-host " "
> write-host "Objects in node $nodename"
> write-host "********************************************"
> Foreach ($driver in $PnP){
> $devicename = $driver.Devicename
> if($devicename.Startswith("Smart Array")){
> write-host $devicename
> $driver.DriverVersion
> write-host "------------------------------"
>
> }
> }
> }
> --------------------------------------------------------------
>
> I get all informations i want but there is still a error which i don't
> know
> how to fix:
>
> Objects in node nodename1
> ********************************************
> Smart Array 5x and 6x Notification Driver
> 6.4.0.32
> -------------------------------------
> Smart Array 5300 Controller
> 5.80.0.32
> -------------------------------------
> You cannot call a method on a null-valued expression.
> At line:9 char:34
> + if($devicename.Startswith <<<< ("Smart Array")){
>
>
> Objects in node nodename2
> ********************************************
> Smart Array 5x and 6x Notification Driver
> 6.4.0.32
> -------------------------------------
> Smart Array 5300 Controller
> 5.80.0.32
> -------------------------------------
> You cannot call a method on a null-valued expression.
> At line:9 char:34
> + if($devicename.Startswith <<<< ("Smart Array")){
>
> It looks like $devicename is empty at the end and the script wants still
> make a loop...
> Hope someone can help me getting this error away :-)
>
> greetings
>
> PS: Sorry for my english ;-)