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 - Text manipulation question

Reply
 
Old 08-25-2008   #1 (permalink)


Vista Ultimate x32
 
 

Text manipulation question

I did a script that outputs a remote client's network connected printers (according to their dmain SID via registry) to a text file.

The text output is in the format eg:

HKEY_USERS\S-1-5-21-xxxxxxxxxx-3770063950-2320700579-61605\Printers\Connections\,,ServerName,QueueName

I'd like to mainpulate that output to:

\\ServerName\QueueName

Any tips on how to do this?

My System SpecsSystem Spec
Old 08-26-2008   #2 (permalink)
tojo2000


 
 

Re: Text manipulation question

On Aug 25, 8:17*pm, aukiman <gu...@xxxxxx-email.com> wrote:
Quote:

> I did a script that outputs a remote client's network connected printers
> (according to their dmain SID via registry) to a text file.
>
> The text output is in the format eg:
>
> HKEY_USERS\S-1-5-21-xxxxxxxxxx-3770063950-2320700579-61605\Printers\Connect ions\,,ServerName,QueueName
>
> I'd like to mainpulate that output to:
>
> '\\ServerName\QueueName' (file://\\ServerName\QueueName)
>
> Any tips on how to do this?
>
> --
> aukiman
>
> '[image:http://i85.photobucket.com/albums/k6...onmansig-n...]'
> (http://www.radioaukiman.com/forums)
Here's one way to do it:

[regex]$pattern = ',,([^,]+),([^,]+)$'
$server = $groups[1].Value
$queue = $groups[2].Value
echo "\\$server\$queue (file://\\$server\$queue)"


I don't know how familiar you are with regular expressions, but
basically that's

,, -- two commas
( -- start grouping
[^,]+ -- one or more characters that are NOT commas
) -- finish grouping

etc...

My System SpecsSystem Spec
Old 08-26-2008   #3 (permalink)
Kiron


 
 

Re: Text manipulation question

$str -replace '.+,,(.+),(.+)','\\$1\$2 (file://\\$1\$2)'

--
Kiron
My System SpecsSystem Spec
Old 08-26-2008   #4 (permalink)
tojo2000


 
 

Re: Text manipulation question

On Aug 25, 10:37*pm, tojo2000 <tojo2...@xxxxxx> wrote:
Quote:

> On Aug 25, 8:17*pm, aukiman <gu...@xxxxxx-email.com> wrote:
>
>
>
Quote:

> > I did a script that outputs a remote client's network connected printers
> > (according to their dmain SID via registry) to a text file.
>
Quote:

> > The text output is in the format eg:
>
Quote:

> > HKEY_USERS\S-1-5-21-xxxxxxxxxx-3770063950-2320700579-61605\Printers\Connect ions\,,ServerName,QueueName
>
Quote:

> > I'd like to mainpulate that output to:
>
Quote:

> > '\\ServerName\QueueName' (file://\\ServerName\QueueName)
>
Quote:

> > Any tips on how to do this?
>
Quote:

> > --
> > aukiman
>>
> Here's one way to do it:
>
> [regex]$pattern = ',,([^,]+),([^,]+)$'
> $server = $groups[1].Value
> $queue = $groups[2].Value
> echo "\\$server\$queue (file://\\$server\$queue)"
>
> I don't know how familiar you are with regular expressions, but
> basically that's
>
> ,, * * *-- two commas
> ( * * * -- start grouping
> [^,]+ *-- one or more characters that are NOT commas
> ) * * * -- finish grouping
>
> etc...
Okay, somehow I forgot to copy a couple of lines:

PS C:\> $path = 'HKEY_USERS\S-1-5-21-
xxxxxxxxxx-3770063950-2320700579-61605\Printers\Connect ions
\,,ServerName,QueueName'
PS C:\> [regex]$pattern = ',,([^,]+),([^,]+)$'
PS C:\> $groups = $pattern.Match($path).Groups
PS C:\> $server = $groups[1].Value
PS C:\> $queue = $groups[2].Value
PS C:\> echo "\\$server\$queue (file://\\$server\$queue)"
\\ServerName\QueueName (file://\\ServerName\QueueName)


My System SpecsSystem Spec
Old 08-26-2008   #5 (permalink)


Vista Ultimate x32
 
 

Re: Text manipulation question

brilliant ! thanks for the help guys, first time I've used expressions. Definitely not the last
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Text file manipulation PowerShell
Re: Question concerning copying from the text body Live Mail
Re: Question concerning copying from the text body Live Mail
Windows programming and image manipulation in Powershell question PowerShell


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