Reading specific .ini key change

Welcome Forums General PowerShell Q&A Reading specific .ini key change

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 weeks ago.

  • Author
    Posts
  • #174787

    Participant
    Topics: 6
    Replies: 8
    Points: 88
    Rank: Member

    Hello, I'm having a hard time understanding how to read an .ini file change prior to my If/ Elseif/Else.
    Previously, I read the value that changed from the Registry – no problem. (shown below)
    Now the software no longer writes the default source there. Instead the vendor decided to include it in an .ini file.
    Can someone please show me what I need to add in order to pick up the Key value?

    One of the lines in Section "Defaults" is DefaultSource32. This can only be set as one item, but there are many options. I'm only running my IF statement when this changes from Software Import to Fujitsu fi-7160 or Fujitsu fi-7260.

    .ini file
    [Defaults]
    DefaultSource32=Software Import

    Here's my previous script.

    Start-Process -FilePath "C:\Program Files (x86)\Kofax\Capture\ImgCtls\Bin\ScannerConfigUtil.exe" -Wait
    
    $src_dir1 = "C:\Program Files (x86)\Kofax Set Default Scanner\Fujitsu 7160"
    $src_dir2 = "C:\Program Files (x86)\Kofax Set Default Scanner\Fujitsu 7260"
    $dst_dir1 = "C:\ProgramData\Kofax\Vrs"
    $dst_dir2 = "C:\Program Files (x86)\Kofax\Capture\ImgCtls\bin\Profiles"
    
    #This no longer applies#
    $value = Get-ItemPropertyValue "HKLM:\SOFTWARE\WOW6432Node\Kofax\Condor\1.0\*" -Name 'Default Source'
    ########
    if ($value -like 'Fujitsu fi-7160*'){
    Copy-Item "$src_dir1\*.cps" -Destination "$dst_dir2" -WhatIf
    Copy-Item "$src_dir1\*" -Exclude "*.cps" -Destination "$dst_dir1" -WhatIf
    }
    elseif($value -like 'Fujitsu fi-7260*'){
    Copy-Item "$src_dir2\*.cps" -Destination "$dst_dir2" -WhatIf
    Copy-Item "$src_dir2\*" -Exclude "*.cps" -Destination "$dst_dir1" -WhatIf
    }
    Else
    {
    $wshell = New-Object -ComObject Wscript.Shell
    $Output = $wshell.Popup("Selection was not a correct model. Please re-open utility and choose Fujitsu 7160 or 7260")
    

    Thank you!

  • #174802

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,438
    Helping Hand
    Rank: Community Hero

    You can use below link to get some help. It has a function to convert from ini.

    Managing INI Files with PowerShell

  • #174823

    Participant
    Topics: 6
    Replies: 8
    Points: 88
    Rank: Member

    Thanks, kvprasoon.

    I did some digging around and ultimately tested this. It works and returns exactly what I need.

    $DefaultSource32 = Get-Content -Path C:\ProgramData\Kofax\Vrs\kofax200.ini | Where-Object { $_ -match 'DefaultSource32' }
    $DefaultSource32.Split('=')[1]
    
    Thanks again!

You must be logged in to reply to this topic.