When I rum the script below and it did not update any of my files. What Iam trying accomplish is for the script to go thru multiple ini files.
In the ini files there is a printer name called Name, which ends with either a an odd number or an even number.
***Desired output should be:
Printer=SMB2 Local Name="Windows Printer | AC-10-170" Host="VJJJRT02" Name="AC-10-170" PrinterID="HP LaserJet 4100 Series PCL6" Class="PCL5" Enabled=yes
***
If the printer name ends with an odd value then change the value in the Host='VJJJRT02"
If the printer name ends with an odd value then change the value in the Host='VJJJRT01"
Thanks
Thanks
Function check-even ($num){[bool]!($num%2)}
$printers= @('AC-10-170',
'AC-11-171',
'ac-11-173',
'ac-11-175',
'ac-11-176',
'ac-11-180',
'ac-11-181',
'AC-11-182',
'ac-11-183',
'ac-11-185',
'ac-11-186',
'ac-11-187',
'ef-11-218',
'ef-11-219',
'ef-11-222',
'ef-11-223',
'ef-4-207',
'ef-4-208',
'ef-4-211',
'ef-4-212',
'ef-4-213',
'ef-4-215',
'EF-4-220',
'ef-4-224',
'ef-4-225',
'ef-4-226',
'ef-4-227')
foreach($filein(Get-ChildItem-Path c:\Test\*.ini)){
$newfilename=$file.fullname-replace".ini", ".txt"
foreach($linein(Get-Content$file.fullname)){
foreach($printerin$printers){
# Get the number off the end of the printer name
$printerNum=$printer.Split("-")[2]
if((check-even $printerNum)-eq$true){
#even
$line.Replace('Host="ACFILE01"','Host="VJJJRT02"').Replace('Host="effile01"','Host="VJJJRT02"')
}
else{
#odd
$line.Replace('Host="ACFILE01"','Host="VSHHPRT01"').Replace('Host="ACFILE01"','Host="VSHHPRT01"')
}
}
}
}