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 - How check local Queues in a If

Reply
 
Old 02-14-2008   #1 (permalink)
Gregor


 
 

How check local Queues in a If

Hello

I have problems with check local queues. I have a db with queues.

1. Check local system of. Is queue exist. when not create this part don't
function.

Where is the error? Do you have a idea?

Thanks for you help

Thanks
Gregor

#SQL Connection aufbauen
$conn = new-object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "server=hsb592as;database=PrintMgmt;integrated
security=true"
$cmd = new-object System.Data.SqlClient.SqlCommand("spCreateQueue", $conn)
$cmd.CommandType = [System.Data.CommandType]'StoredProcedure'
$cmd.Parameters.Add("@PrintServerName",$env:COMPUTERNAME)
$cmd.Connection = $conn
$adapter = new-object System.Data.SqlClient.SqlDataAdapter
$adapter.SelectCommand = $cmd
$ds = new-object System.Data.DataSet
$adapter.Fill($ds)
$conn.close()

#DataTable erstellen
$dt = new-object "System.Data.DataTable" "dtData"
$dt = $ds.Tables[0]
$dt | FOREACH-OBJECT {

$PrintSRV = $_.PrintServer
$PrintSRVShort = $_.PrintServerShort
$QueueTemplate = $_.QueueTemplate
$QueueName = $_.Printername+'_'+$_.QueueName
$PrinterName = $_.PrinterName
$PrinterPortDomain = '.bkw-fmb.ch'
$PrinterPort = $_.PrinterName+'.bkw-fmb.ch'
$UNCName = '\\'+$_.PrintServer+'\'+$_.QueueName
$Url = 'http://'+$_.PrintServer+'/'+$_.QueueName
$Location = $_.Location
#$Description = 'Kommentar Feld'
$FilterPPort = "Name = '$PrinterPort'"
$FilterQueue = "Name = '$_.QueueName'"
$RegFile = $_.QueueRegFile

#Add PrinterPort
$colItemPrinterPort = get-WmiObject -class
"Win32_TCPIPPrinterPort" -namespace "root\CIMV2" -computername
$env:COMPUTERNAME -Filter $FilterPPort | foreach {$_.name}
If ($colItemPrinterPort -eq $PrinterPort)
{
write-Host = "Port exist" $PrinterPort
}
else
{
#Create PrinterPort
cmd /c start /wait Cscript c:\Windows\System32\Prnport.vbs -a -s
$env:COMPUTERNAME -r $PrinterPort -h $PrinterPort -me -y public -o raw -n
9100
write-Host = "Port created" $PrinterPort
}

1. >>>>>>>>>>>>>>>>>>>

$colItemQueue = get-WmiObject -class "Win32_Printer" -namespace
"root\CIMV2" -computername $env:COMPUTERNAME -Filter $FilterQueue |
foreach {$_.name}

if ($colItemQueue -eq $QueueName)
{
Write-Host = "Queue "$QueueName" exist"
}
else
{
Write-Host = "Queue "$QueueName" create"
....
}
Quote:
Quote:
Quote:

>>>>>>>>>>>>>>>>>>>>>>>>

My System SpecsSystem Spec
Old 02-14-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: How check local Queues in a If

Quote:

> #Create PrinterPort
> cmd /c start /wait Cscript c:\Windows\System32\Prnport.vbs -a -s
> $env:COMPUTERNAME -r $PrinterPort -h $PrinterPort -me -y public -o raw
> -n 9100
> write-Host = "Port created" $PrinterPort
If I follow, I would try doing this:
cmd /c start /wait "Cscript c:\Windows\System32\Prnport.vbs -a -s
$env:COMPUTERNAME -r $PrinterPort -h $PrinterPort -me -y public -o raw
-n 9100"

The variables you are declaring are likely not being passed to the
VBScript script.

Also, it is not:
write-host = "something"
but instead
write-host "something"

Marco


--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 02-14-2008   #3 (permalink)
Gregor


 
 

Re: How check local Queues in a If

Hello Marco

My problem is:

$colItemQueue = get-WmiObject -class "Win32_Printer" -namespace
"root\CIMV2" -computername $env:COMPUTERNAME -Filter $FilterQueue |
foreach {$_.name}

if ($colItemQueue -eq $QueueName)
{
Write-Host = "Queue "$QueueName" exist"
}
else
{
Write-Host = "Queue "$QueueName" create"
....
}

"Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:ehcpwjwbIHA.4712@xxxxxx
Quote:

>
Quote:

>> #Create PrinterPort
>> cmd /c start /wait Cscript c:\Windows\System32\Prnport.vbs -a -s
>> $env:COMPUTERNAME -r $PrinterPort -h $PrinterPort -me -y public -o raw -n
>> 9100
>> write-Host = "Port created" $PrinterPort
>
> If I follow, I would try doing this:
> cmd /c start /wait "Cscript c:\Windows\System32\Prnport.vbs -a -s
> $env:COMPUTERNAME -r $PrinterPort -h $PrinterPort -me -y public -o raw -n
> 9100"
>
> The variables you are declaring are likely not being passed to the
> VBScript script.
>
> Also, it is not:
> write-host = "something"
> but instead
> write-host "something"
>
> Marco
>
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 02-14-2008   #4 (permalink)
Shay Levi


 
 

Re: How check local Queues in a If



1. for local computers -computername parameter is not needed
2. "root\CIMV2" is the default WMI namespace, you can remove it
3. You can't do Write-Host = "something", and there are also double quotes
errors.

Try this:

$colItemQueue = get-WmiObject -class "Win32_Printer" -namespace -Filter $FilterQueue
| where {$_.name -eq $QueueName}

if ($colItemQueue){
Write-Host "Queue $QueueName exist"
}
else
{
Write-Host "Queue $QueueName create"
....
}



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hello Marco
>
> My problem is:
>
> $colItemQueue = get-WmiObject -class "Win32_Printer" -namespace
> "root\CIMV2" -computername $env:COMPUTERNAME -Filter $FilterQueue |
> foreach {$_.name}
>
> if ($colItemQueue -eq $QueueName)
> {
> Write-Host = "Queue "$QueueName" exist"
> }
> else
> {
> Write-Host = "Queue "$QueueName" create"
> ...
> }
> "Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
> news:ehcpwjwbIHA.4712@xxxxxx
>
Quote:
Quote:

>>> #Create PrinterPort
>>> cmd /c start /wait Cscript c:\Windows\System32\Prnport.vbs -a -s
>>> $env:COMPUTERNAME -r $PrinterPort -h $PrinterPort -me -y public -o
>>> raw -n
>>> 9100
>>> write-Host = "Port created" $PrinterPort
>> If I follow, I would try doing this:
>> cmd /c start /wait "Cscript c:\Windows\System32\Prnport.vbs -a -s
>> $env:COMPUTERNAME -r $PrinterPort -h $PrinterPort -me -y public -o
>> raw -n
>> 9100"
>> The variables you are declaring are likely not being passed to the
>> VBScript script.
>>
>> Also, it is not:
>> write-host = "something"
>> but instead
>> write-host "something"
>> Marco
>>
>> --
>> Microsoft MVP - Windows PowerShell
>> http://www.microsoft.com/mvp
>> PowerGadgets MVP
>> http://www.powergadgets.com/mvp
>> Blog:
>> http://marcoshaw.blogspot.com


My System SpecsSystem Spec
Old 02-14-2008   #5 (permalink)
Marco Shaw [MVP]


 
 

Re: How check local Queues in a If

Gregor wrote:
Quote:

> Hello Marco
>
> My problem is:
>
> $colItemQueue = get-WmiObject -class "Win32_Printer" -namespace
> "root\CIMV2" -computername $env:COMPUTERNAME -Filter $FilterQueue |
> foreach {$_.name}
>
> if ($colItemQueue -eq $QueueName)
> {
> Write-Host = "Queue "$QueueName" exist"
> }
> else
> {
> Write-Host = "Queue "$QueueName" create"
> ...
> }
I think I follow now, try doing this instead:

$colItemQueue = get-WmiObject -class "Win32_Printer" -namespace
"root\CIMV2" -computername $env:COMPUTERNAME -Filter $FilterQueue

if ($colItemQueue -ne $null)
{
Write-Host = "Queue "$QueueName" exist"
}
else
{
Write-Host = "Queue "$QueueName" create"
....
}
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Getting print queues PowerShell
Add local machine users to local admin group via GPO .NET General
error 0x80040707 dll functioncall crashed BRADDPRT. check local po Vista General
Creating msmq queues, triggers and rules PowerShell
Newbie: Nagios with nrpe_nt, check for diskspace; check services,returncode 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