cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SGNJ
Paper Tape
Posts: 3
Registered: ‎01-28-2019
Location: US
Views: 528
Message 1 of 5

ThinkBiosCConfig.hta injecting leading space into file name.

I'm using WMI calls to extract the model name from the machine, then matching that model name to the config files extracted manually with the ThinkBiosConfig tool. This matching is working with the exception that a leading space is being added to the file variable by the ThinkBiosConfig.hta tool. When I "Write-Host $configfilename" immediately before calling the hta, the filename prints to screen correctly.

 

Will someone relieve me of this turbulent space?

 

Code:

 

$fullmodel = (Get-WmiObject -Class CIM_System | Select-Object -Property SystemSKUNumber | Findstr -i Lenovo)
$model = $fullmodel.split('_')[2]
$sku = $fullmodel.split()[1]
#Write-Host "$fullmodel"
#Write-Host "$model"
#Write-Host "$sku"

$configfileline = (dir | findstr $sku)
$configfilename = $configfileline.split()[23]
#Write-Host $configfileline
#Write-Host $configfilename

#Add a check for the existence of the correct config file.

E:\BIOSTool\ThinkBiosConfig.hta '"log=<path_to_log_directory>"' '"pass=<key>"' '"file='$configfilename'"'
PAUSE

 

Log line:

fileLocation= M710sConfig.ini

Lenovo Employee dmcdermott
Lenovo Employee
Posts: 140
Registered: ‎06-02-2015
Location: US
Views: 481
Message 2 of 5

Re: ThinkBiosCConfig.hta injecting leading space into file name.

Hi SGNJ,

 

I should be able to help. Just so I follow what you are experiencing- You get the name from powershell properly but the text file exported from ThinkBiosConfig has a leading space in the name? I'm going to try to recreate your issue in the meantime.

 

Thanks!

 

Edit - I'm confused by this line: 

$configfilename = $configfileline.split()[23]

Can you provide the directory name so I can understand what you are trying to take from it?

SGNJ
Paper Tape
Posts: 3
Registered: ‎01-28-2019
Location: US
Views: 463
Message 3 of 5

Re: ThinkBiosCConfig.hta injecting leading space into file name.

See full code below with identifying info removed:

 

 

$fullmodel = (Get-WmiObject -Class CIM_System | Select-Object -Property SystemSKUNumber | Findstr -i Lenovo)

#Pull the model from the output of the above command, splitting out the third underscore delimited field.
$model = $fullmodel.split('_')[2]

#Pulls the SKU as the second space delimited (default delimiter) field. $sku = $fullmodel.split()[1] #Test lines to check variables. #Write-Host "$fullmodel" #Write-Host "$model" #Write-Host "$sku" #Pulls the whole line from the Dir listing. $configfileline = (dir | findstr $sku)
#Splits the model name from the output as the 24th space delimited field. $configfilename = $configfileline.split()[23] #More test lines. #Write-Host $configfileline #This final test prints the name correctly to the screen. #Write-Host $configfilename E:\BIOSTool\ThinkBiosConfig.hta '"log=\\sharename\directory\BIOSTool\LogFolder"' '"pass=16characterStrin"' '"file='$configfilename'"' #Pause is here so I can see the output before closing the window. PAUSE

 

The config files are manually collected, and stored in the same directory from which the script runs. They do not have leading spaces in the actual file names. The leading space seems to come from the way ThinkBiosConfig.hta interprets the file name argument. It is interpreted correctly when I write it to the screen as a test from within the script, but when it shows up in the log file, there is a space, where other arguments do not have spaces. I should have included that for comparison.

 

 

-------------1/28/2019 11:08:49 AM--------------

log=\\sharename\directory\BIOSTool\logs
pass=16characterStrin
fileLocation= M710sConfig.ini

 

Finished gathering settings.
Could not file the specified file.

 

 

Note only the file location entry has space after the equals sign.


Thanks for your assistance!

Highlighted
Lenovo Employee dmcdermott
Lenovo Employee
Posts: 140
Registered: ‎06-02-2015
Location: US
Views: 440
Message 4 of 5

Re: ThinkBiosCConfig.hta injecting leading space into file name.

I was able to recreate your problem and this should solve your issue- change 

E:\BIOSTool\ThinkBiosConfig.hta '"log=\\sharename\directory\BIOSTool\LogFolder"' '"pass=16characterStrin"' '"file='$configfilename'"'

to (pay special attention to the ` characters and the bookend " , these escape the quotes)

Start-Process E:\BIOSTool\ThinkBiosConfig.hta -ArgumentList "`"log=\\sharename\directory\BIOSTool\LogFolder`" `"pass=16characterStrin`" `"file=$configfilename`""

Passing arguments to powershell is difficult once quotes are involved. I'll make sure an example like this is added to the documention. 

 

 

Also, more of a suggestion than necessary but you change the following lines to get the model easier than spliting for the 24th field

#Pulls the whole line from the Dir listing.
$configfileline = (dir | findstr $sku)

#Splits the model name from the output as the 24th space delimited field.
$configfilename = $configfileline.split()[23]

to

$configfilename = dir | ? { $_.Name -eq ($sku + "Config.ini") } | Select -ExpandProperty Name

 

 

Let me know if you have any other issues or need some more help!

SGNJ
Paper Tape
Posts: 3
Registered: ‎01-28-2019
Location: US
Views: 432
Message 5 of 5

Re: ThinkBiosCConfig.hta injecting leading space into file name.

Many thanks! That absolutely did the trick.

Check out current deals!


Shop current deals

Top Kudoed Authors