Reputation: 3
Trying to perform an if/else statement to an existing test lab machine configuration script. Basically I want to search for an exact file path, if it is true proceed with script, if false, stop script and display driver name and version.
I've tried with the continue statement, but powershell doesn't like it
Function Namespace_Check
{ Write-Host "Checking available namepace" -ForegroundColor Green
Get-CimInstance -namespace "root\cimv2" -ClassName __NAMESPACE
$path = "root\cimv2\NV"
Write-Host "Complete" -ForegroundColor Green
if
($path -match '*NV*' ){continue}
else
{Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -like "*nvidia*"}}
}
I would like for when the "if" statement is true, to continue running remaining script and when the "if" statement is false, to stop the script and display the driver name and version to display similar to this:
Product Name : Quadro P2000
Video Driver Version: 391.03
Upvotes: 0
Views: 809
Reputation: 8889
I don't understand your $path
variable, if your purpose is to check If the namespace contains the 'NV' you can do:
if ((Get-CimInstance -namespace "root\cimv2" -ClassName __NAMESPACE).Name -match 'NV')
{
return
}
else {
return (Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -like "*nvidia*"})
}
anyway using your code, you can update it to:
Function Namespace_Check
{ Write-Host "Checking available namepace" -ForegroundColor Green
Get-CimInstance -namespace "root\cimv2" -ClassName __NAMESPACE
$path = "root\cimv2\NV"
Write-Host "Complete" -ForegroundColor Green
if
($path -match '*NV*' ){return}
else
{ return (Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -like "*nvidia*"}})
}
Upvotes: 0