While reading through this, please understand I am not asking for someone to fix my scribbling, I am asking for help to ‘understand’ the behavior, so I can stop tripping over myself. The following snippet works as expected.
Example-00:
$pnam0 = $args[0]
$pnam1 = $args[1]
$pnam2 = $args[2]
$pnam3 = $args[3]
$pnam4 = $args[4]
$Drvrs = Get-WindowsDriver -online -all | ? { $_.providername -like $pnam0 -or $_.providername -like $pnam1 -or $_.providername -like $pnam2 -or $_.providername -like $pnam3 -or $_.providername -like $pnam4 } | select-object driver, version, ProviderName, date | sort date -Descending
From a previous thread (below), it was explained a cmdlet
output is a different type of object
, compared to a “string” object
.
Then I further read, from a Google provided “AI Overview” –
" In PowerShell, an argument before variable assignment is treated as a string.
Here’s why:
–PowerShell’s Dynamic Typing:** PowerShell is dynamically typed, meaning the type of a variable is determined at runtime based on the value assigned to it.
–Default String Interpretation:** If you don’t explicitly specify a type, PowerShell interprets unassigned variables as strings."
In regard to the above “AI Overview”, their use of the word ‘assignment’ seem’s to be used for assigning a data-type. My use of the word ;assignment’ (below), is in regard to assigning a value to a variable-name; please correct where needed.
The main confusion begins …
Example-01
$Drvrs = Get-WindowsDriver -online -all | ? { $_.providername -like $args[0] } | select-object driver, version, ProviderName, date | sort date -Descending
$Drvrs
PS> _Script *amd*
Above returns an empty prompt , compared to the following Example-01a:
$pnam0 = $args[0]
$pnam1 = $args[1]
$pnam2 = $args[2]
$pnam3 = $args[3]
$pnam4 = $args[4]
$Drvrs = Get-WindowsDriver -online -all | ? { $_.providername -like $pnam0 } | select-object driver, version, ProviderName, date | sort date -Descending
$Drvrs
PS> _Script *amd*
Driver Version ProviderName Date
------ ------- ------------ ----
oem65.inf 6.0.0.72 AMD 5/31/2023 12:00:00 AM
oem166.inf 6.0.0.42 AMD 5/25/2023 12:00:00 AM
oem71.inf 10.105.6.45 AMD 5/15/2023 12:00:00 AM
oem3.inf 6.0.6.7 AMD 5/4/2023 12:00:00 AM
Example-01a works as expected providing the above results.
I’m obviously not understanding both: a) if $args[0]
is both a string argument and a variable, indicated by the preceding ‘$’, b) why is ? { $_.providername -like $args[0] }
, from example-01 not expanding it, or otherwise seeing its value until after it is re-assigned; as in $pnam0 = $args[0]
?
Please notify if I did not explain clear enough.