We have 4 terminals and a lot of printers on them... So... We need that the number and names of printers were equal on each terminals... (the name of printer must be *_*_*... HP_buh_01)
sorry for my bad english, i m from russia :)
#create massiv of terminals, folder for files... and files for errors...
$terminals = ("terminalname1","terminalname2","terminalname3","terminalname4")
New-Item -Path 'c:\printer' -ItemType "directory"
New-Item -Path 'c:\printer\terminalname1+error.txt' -ItemType "file"
New-Item -Path 'c:\printer\terminalname2+error.txt' -ItemType "file"
New-Item -Path 'c:\printer\terminalname3+error.txt' -ItemType "file"
New-Item -Path 'c:\printer\terminalname4+error.txt' -ItemType "file"
#find bad printers, good printers... it's numbers and send it in files
foreach ($terminal in $terminals)
{
$a=0
$printers = get-wmiobject -class Win32_Printer -computer $terminal
foreach ($printer in $printers)
{
if ($printer.name -like "*_*_*")
{$printer.name >> c:\printer\$terminal.txt
$a=$a+1}
elseif (($printer.name -like "*session*") -or ($printer.name -like "*сеансе*") -or ($printer.name -like "*uk*"))
{$printer.name >> c:\printer\$terminal+session.txt}
else {$printer.name >> c:\printer\$terminal+error.txt}
}
"the number of printers on $terminal = $a" >> c:\printer\tnumbers.txt
$a >> c:\printer\n.txt}
#create massivs of printers
$term1 = Get-Content -Path c:\printer\terminalname1.txt
$term2 = Get-Content -Path c:\printer\terminalname2.txt
$term3 = Get-Content -Path c:\printer\terminalname3.txt
$term4 = Get-Content -Path c:\printer\terminalname4.txt
$n = Get-Content -Path c:\printer\n.txt
$errterm1 = Get-Content -Path c:\printer\terminalname1+error.txt
$errterm2 = Get-Content -Path c:\printer\terminalname2+error.txt
$errterm3 = Get-Content -Path c:\printer\terminalname3+error.txt
$errterm4 = Get-Content -Path c:\printer\terminalname4+error.txt
$error = "no printers"
#find the unnecessary printer on terminal
$max = $n[0]
for ($i=1; $i -lt $n.length+1; $i++)
{
if ($max -lt $n[$i])
{$max = $n[$i]}
}
$max
if ($n[0] -eq $max)
{"1"
for ($s=0; $s -le $term1.length;$s++)
{
$k=0
for ($t=0; $t -le $term2.length;$t++)
{
if ($term1[$s] -eq $term2[$t])
{$k=1
break}
}
if ($k -eq 0)
{$error=$term1[$s]
break}
}
}
elseif ($n[1] -eq $max)
{"2"
for ($s=0; $s -le $term2.length;$s++)
{
$k=0
for ($t=0; $t -le $term1.length;$t++)
{
if ($term2[$s] -eq $term1[$t])
{$k=1
break}
}
if ($k -eq 0)
{$error=$term2[$s]
break}
}
}
elseif ($n[2] -eq $max)
{"3"
for ($s=0; $s -le $term3.length;$s++)
{
$k=0
for ($t=0; $t -le $term2.length;$t++)
{
if ($term3[$s] -eq $term2[$t])
{$k=1
break}
}
if ($k -eq 0)
{$error=$term3[$s]
break}
}
}
elseif ($n[3] -eq $max)
{"4"
for ($s=0; $s -le $term4.length;$s++)
{
$k=0
for ($t=0; $t -le $term3.length;$t++)
{
if ($term4[$s] -eq $term3[$t])
{$k=1
break}
}
if ($k -eq 0)
{$error=$term4[$s]
break}
}
}
$error
"bad printers on terminalname1 $errterm1"
"bad printers on terminalname2 $errterm2"
"bad printers on terminalname3 $errterm3"
"bad printers on terminalname4 $errterm4"