Guest Guest Posted February 10, 2021 Posted February 10, 2021 I'm currently writing a PowerShell script to allow us to configure our BIOS' via SCCM. I've got our remediation script sorted, however, I'm having an issue with the discovery script. I'm pulling in a CSV with a list of settings and values and using a foreach loop to check the status of each, then if the result is False I'm setting a global variable to False and outside of the loop if the variable is empty setting it to True. However, for some reason even if all settings came back true the global variable is being set to false. If anyone could give my script a once over I'd be really grateful DiscoveryNew.ps1
sister_annex Posted February 10, 2021 Posted February 10, 2021 I'm currently writing a PowerShell script to allow us to configure our BIOS' via SCCM. I've got our remediation script sorted, however, I'm having an issue with the discovery script. I'm pulling in a CSV with a list of settings and values and using a foreach loop to check the status of each, then if the result is False I'm setting a global variable to False and outside of the loop if the variable is empty setting it to True. However, for some reason even if all settings came back true the global variable is being set to false. If anyone could give my script a once over I'd be really grateful [ATTACH]60797[/ATTACH] I can't test this but, I believe that Functions should be declared outside of the foreach $ConfigRootPath = "\\server\source\BIOS Config" $DeviceModel = Get-CimInstance -ClassName Win32_ComputerSystem | select -ExpandProperty Model $ConfigFile = Import-CSV "$ConfigRootPath\$DeviceModel.csv" $FinalResult = "" Function Get-BIOSSetting { param( [parameter(Mandatory=$true, HelpMessage="Setting")] [ValidateNotNullOrEmpty()] [string]$Setting ) $BIOS = Get-WmiObject -class hp_biossetting -Namespace "root\hp\instrumentedbios" $BIOSSetting = $BIOS | Where-Object {$_.Name -eq $Setting} | Format-Table Name, Value $a = $BIOSSetting | Out-String $b = $a -replace '\s+',' ' $result = $b.Contains("*$($ConfigItem.Value)") Write-Output $result } foreach ($ConfigItem in $ConfigFile) { $obj = Get-BIOSSetting -Setting $ConfigItem.Setting $Result1 = $Obj if ($Obj -contains "False") {$FinalResult = "False"} Write-Output $Obj } if ($obj -contains "") {$FinalResult = "True"} echo $FinalResult
Guest Guest Posted February 10, 2021 Posted February 10, 2021 That still comes back as False despite all settings returning True
sister_annex Posted February 10, 2021 Posted February 10, 2021 $BIOS = Get-WmiObject -class hp_biossetting -Namespace "root\hp\instrumentedbios" May be worth checking this line. Calling that calls the local machine, if you're calling a remote computer you will need to specify a -computername option I am guessing as this is an SCCM script that it is running locally on each machine though?
sister_annex Posted February 10, 2021 Posted February 10, 2021 if ($obj -contains "") {$FinalResult = "True"} This line... I think the $obj should be $Obj you have two variables with very similar names Again difficult to test but if you run the script through the PowershellISE on a machine you want to check you should be able to add breakpoints in the code and step through to find out what's happening
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now