We are trying to update our BIOS within a task sequence and I have a script provided by Lenovo which is working fine in Windows 10 and PowerShell v5. However, it is not working properly in Windows 7 with PowerShell v2. We can't upgrade to v5 on the Windows 7 machines.
The script reads an XML file I have exported from the SCCM and matches the appropriate BIOS package, downloads it and runs it.
So the script looks like:
[xml]$Packages = Get-Content BIOSPackages.xml
# Environment variable call for task sequence only
$tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment
$BIOS = (Get-WmiObject -Namespace root\cimv2 -Class Win32_BIOS).SMBIOSBIOSVersion.Substring(0,4)
$ns = New-Object Xml.XmlNamespaceManager $Packages.NameTable
$ns.AddNamespace("def", "http://schemas.microsoft.com/powershell/2004/04")
$Xpathqry = "/def:Objs/def:Obj//def:MS[contains(.,`"$BIOS`")]"
$Package = ($Packages.SelectNodes($xpathqry,$ns))
$PackageID = $Package.SelectNodes('def:S[contains(@N,"PackageID")]',$ns)
$tsenv.Value('OSDDownloadDownloadPackages') = $PackageID.InnerXML
and it fails on:
$PackageID = $Package.SelectNodes('def:S[contains(@N,"PackageID")]',$ns)
I have tried to fudge with it for a day and I am just hitting a wall.
What I get is the following error:
Method invocation failed because [System.Xml.XPathNodeList] doesn't contain a method named 'SelectNodes'. At C:\_SMSTaskSequence\Packages\NC1002CB\Get-BIOSPackages.ps1:17 char:38 + $PackageID = $Package.SelectNodes <<<< ('def:S[contains(@N,"PackageID")]',$ns) + CategoryInfo : InvalidOperation: (SelectNodes:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound