Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Printer migration

Reply
 
Old 08-11-2009   #1 (permalink)
Reno


 
 

Printer migration

I have about 100 printers installed on two separate print servers.
I've got a new print server and the tech here installed all the
printers on the new server but the names are not identical. Rats!!!
Anyway, as an example, \\server1\29F HP4600 would be \
\server03\29F.
I'm trying to come up with a script to read each users installed
printers, install the same printer but on the new server and then
remove the old printer. I've gotten help with the installing and
removing printers but I could use some help with matching the names
up.

Here's what I've got so far:

$printers = gwmi -query "select * from win32_printer where network =
'true'"|select-object sharename
$newprinters = gwmi win32_printer -computer server03 |select-object
sharename
foreach ($printer in $printers){
foreach ($newprinter in $newprinters){
if ($printer -match $newprinter){
write-host "match! $newprinter"
}
}
}

The script runs without generating errors but currently I only get one
match with 8 random printers installed. The old/new names are similar
enough so that if I enter each into a variable and then run $tst1 -
match $tst2, I always get True. I've got an error somewhere and I
can't find it.

Does anyone see anything wrong with the above or have a better idea on
how to do this? I'm pretty new to pshell.


THANKS FOR YOUR HELP!



My System SpecsSystem Spec
Old 08-11-2009   #2 (permalink)
Oisin (x0n) Grehan [MVP]


 
 

Re: Printer migration

On Aug 11, 6:38*pm, Reno <johnfri...@xxxxxx> wrote:
Quote:

> I have about 100 printers installed on two separate print servers.
> I've got a new print server and the tech here installed all the
> printers on the new server but the names are not identical. Rats!!!
> Anyway, as an example, *\\server1\29F HP4600 *would be \
> \server03\29F.
> * *I'm trying to come up with a script to read each users installed
> printers, install the same printer but on the new server and then
> remove the old printer. *I've gotten help with the installing and
> removing printers but I could use some help with matching the names
> up.
>
> Here's what I've got so far:
>
> $printers = gwmi -query "select * from win32_printer where network =
> 'true'"|select-object sharename
> $newprinters = gwmi win32_printer -computer server03 |select-object
> sharename
> foreach ($printer in $printers){
> *foreach ($newprinter in $newprinters){
> * if ($printer -match $newprinter){
> * *write-host "match! $newprinter"
> * }
> *}
>
> }
>
> The script runs without generating errors but currently I only get one
> match with 8 random printers installed. *The old/new names are similar
> enough so that if I enter each into a variable and then run $tst1 -
> match $tst2, I always get True. *I've got *an error somewhere and I
> can't find it.
>
> Does anyone see anything wrong with the above or have a better idea on
> how to do this? *I'm pretty new to pshell.
>
> THANKS FOR YOUR HELP!
I think you really mean:

if ($printer -like $newprinter) {

}

-match uses a special pattern matching syntax called "regular
expressions" or "regex." The operator -like does DOS-like wildcards
with *, e.g. "29F HP FOO" -like "29F*" will be true.

-Oisin
My System SpecsSystem Spec
Old 08-12-2009   #3 (permalink)
Alex K. Angelopoulos


 
 

Re: Printer migration

Are both the old and new print queues currently available?

I'm trying to figure out what you specifically want to do from your script,
and don't see it; I think when you encountered some problems you cut back to
simply trying a WMI match and displaying output for simple debugging, which
is smart, but leaves me wondering what you really want to do. That's
important because if I understand your problem correctly, you may have a
_very_ simple solution to the problem - even with about 100 printers
installed.

If I understand you correctly, you know the old share names and the new
share names for each printer share, and the PowerShell problem you're trying
to resolve is this: When enumerating share paths to installed printers using
WMI, how do you uniquely and correctly match the old share path currently in
use to a new share path?

You don't want to use -match since it does regex matching. Furthermore, if
you _know_ which share will map to what, it's probably a bad idea to
use -like matching; it is faster and easier to simply take a listing of old
and new shares and set up a hash. Here's how you do it, based on my
assumptions about what you know and what you're doing.

(1) Save the old shares and the new shares in a simple two-column CSV file
with headers - I'm using OldShare and NewShare as the headers here, and
assume you're saving it as c:\tmp\ptrmap.csv. It should look like the lines
below. Note that I assume you DO know every single old share and every
single new share.
OldShare,NewShare
\\server1\29F HP4600,\\server03\29F
\\oldsrv1\comptr2,\\newsrv\cp2

(2) Create an empty hashtable for the old-new printer mappings, and then
import the ptrmap.csv file using import-csv. The import-csv cmdlet will
import the file data as a set of objects with OldShare and NewShare
properties; here's how it would work:

$map = @{} #creates a hashtable
import-csv C:\tmp\ptrmap.csv | %{$map[$_.OldShare] = $_.NewShare}

Now, if you do this:
$map["\\server1\29f hp4600"]
you get an _exact_ return of the new value
\\server03\29F

You can then do this on individual systems:

$qry = "select * from win32_printer where network = 'true'"
$NetPrinters = gwmi -query $qry
foreach($NetPrinter in $NetPrinters)
{
if $map.ContainsKey($NetPrinter.ShareName)
{
$old = $NetPrinter.Sharename
$new = $map[$old]
"$old needs to be changed to $new"
}
}



"Reno" <johnfrieze@xxxxxx> wrote in message
news:c39e2390-20af-4ca9-9deb-b474523bbabc@xxxxxx
Quote:

> I have about 100 printers installed on two separate print servers.
> I've got a new print server and the tech here installed all the
> printers on the new server but the names are not identical. Rats!!!
> Anyway, as an example, \\server1\29F HP4600 would be \
> \server03\29F.
> I'm trying to come up with a script to read each users installed
> printers, install the same printer but on the new server and then
> remove the old printer. I've gotten help with the installing and
> removing printers but I could use some help with matching the names
> up.
>
> Here's what I've got so far:
>
> $printers = gwmi -query "select * from win32_printer where network =
> 'true'"|select-object sharename
> $newprinters = gwmi win32_printer -computer server03 |select-object
> sharename
> foreach ($printer in $printers){
> foreach ($newprinter in $newprinters){
> if ($printer -match $newprinter){
> write-host "match! $newprinter"
> }
> }
> }
>
> The script runs without generating errors but currently I only get one
> match with 8 random printers installed. The old/new names are similar
> enough so that if I enter each into a variable and then run $tst1 -
> match $tst2, I always get True. I've got an error somewhere and I
> can't find it.
>
> Does anyone see anything wrong with the above or have a better idea on
> how to do this? I'm pretty new to pshell.
>
>
> THANKS FOR YOUR HELP!
>
>
My System SpecsSystem Spec
Old 08-12-2009   #4 (permalink)
Reno


 
 

Re: Printer migration

Thanks for replying guys. I tried the using -like and didn't get
better results but using the hash table based on a csv with the old/
new printer names worked great.
I appreciate your help!

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
P2V and V2V migration Virtual Server
Migration of WLM from one PC to another Live Mail
Printer Migration Vista print fax & scan
RE: LINUX: First Wave - OS Migration, Second Wave - Program Migration Vista General
Re: LINUX: First Wave - OS Migration, Second Wave - Program Migration Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46