+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, Powershell script to list printers with WPK in Coding and Web Development; Hi There I've been trying to get this powershell script to work it should produce a windows with a list ...
  1. #1
    fawkers's Avatar
    Join Date
    Jun 2007
    Location
    Southend
    Posts
    190
    Blog Entries
    2
    Thank Post
    32
    Thanked 21 Times in 20 Posts
    Rep Power
    27

    Powershell script to list printers with WPK

    Hi There

    I've been trying to get this powershell script to work it should produce a windows with a list of printers, It's using the powershell plus kit from the MSDN site (also in the win 7 resource kit).

    Code:
    $DetectedErrorState="unknown","other","No Error","Low Paper","No Paper",`
    "Low Toner","No Toner","Door OPen","Jammed","Offline","Service Requested",`
    "output Bin Full"
    
    $PrinterStatus="Other","Unknown","Idle","Printing","Warming Up","Stopped Printing","Offiline"
    
    #function test{
    #    $class = "win32_printer"
    #    $printers = Get-WmiObject -Class $Class -ComputerName "<COMPUTERNAME>" -Credential <DOMAIN>\<USERNAME>
    #    foreach($p in $printers){
    #        output $p.Name, $DetectedErrorState[$p.DetectedErrorState], $PrinterStatus[$p.PrinterStatus]
    #    }
    #}
    
    
    New-ListView -Width 350 -Height 350 -DataBinding @{
        ItemsSource = New-Binding -IsAsync -UpdateSourceTrigger PropertyChanged -Path Output
    } -View {
        New-GridView -AllowsColumnReorder -Columns {
            New-GridViewColumn "Name" 
            }
    } -DataContext {
        Get-PowerShellDataSource -Script {
            #Get-Process | ForEach-Object { $_ ; Start-Sleep -Milliseconds 25 }
            Get-WmiObject -Class $Class -ComputerName "<COMPUTERNAME" -Credential <DOMAIN>\<USERNAME> |`
            ForEach-Object {
                $_.Name
            }
        }
    } -On_Loaded {
        Register-PowerShellCommand -Run -In "0:0:15" -ScriptBlock {
            $window.Content.DataContext.Script = $window.Content.DataContext.Script
        }
    } -asjob
    If you look in the -DataContext section the commented out line will work, but the four lines below it don't. Can anyone see whats going wrong?

    Thanks

    .Adam

  2. IDG Tech News

  3. #2
    fawkers's Avatar
    Join Date
    Jun 2007
    Location
    Southend
    Posts
    190
    Blog Entries
    2
    Thank Post
    32
    Thanked 21 Times in 20 Posts
    Rep Power
    27
    Hello Everyone

    Got this from technet

    Code:
    New-ListView -Width 350 -Height 350 -DataBinding @{
        ItemsSource = New-Binding -IsAsync -UpdateSourceTrigger PropertyChanged -Path Output
    } -View {
        New-GridView -AllowsColumnReorder -Columns {
            New-GridViewColumn "Name" 
            New-GridViewColumn "PrinterStatus"
            }
    } -DataContext {
        Get-PowerShellDataSource -Script {
     $list = @()
     $PrinterStatus="Other","Unknown","Idle","Printing","Warming Up","Stopped Printing","Offiline"
     
    
     Get-WmiObject -Class Win32_Printer | 
     ForEach-Object {
     $list += New-Object Object | Add-Member NoteProperty Name $_.name -passthru | Add-member NoteProperty PrinterStatus $PrinterStatus[$_.PrinterStatus-1] -passthru
     }
     foreach ($item in $list)
     { 
     $item
     }
    
    
        }
    } -On_Loaded {
        Register-PowerShellCommand -Run -In "0:0:15" -ScriptBlock {
            $window.Content.DataContext.Script = $window.Content.DataContext.Script
        }
    } -asjob
    which works however if you cange the -script block to

    Code:
        Get-PowerShellDataSource -Script {
     $list = @()
     $PrinterStatus="Other","Unknown","Idle","Printing","Warming Up","Stopped Printing","Offiline"
     
     $password = (Read-Host -AsSecureString)
     $user = New-Object Management.Automation.PSCredential ("olympus\ap.admin", $password)
     
     Get-WmiObject -Class Win32_Printer -computername "shsg-d02-prt01" -Credential $User | 
     ForEach-Object {
     $list += New-Object Object | Add-Member NoteProperty Name $_.name -passthru | Add-member NoteProperty PrinterStatus $PrinterStatus[$_.PrinterStatus-1] -passthru
     }
     foreach ($item in $list)
     { 
     $item
     }
    
    
        }
    to allow for a remote computer it doesn't work any more... if anyone has any ideas...


    Thanks

    .Adam

SHARE:
+ Post New Thread

Similar Threads

  1. Printers disappearing after login script
    By gshaw in forum Windows
    Replies: 11
    Last Post: 10th June 2009, 06:47 PM
  2. Get list of printers [Server 2000]
    By somabc in forum Windows Server 2000/2003
    Replies: 2
    Last Post: 26th January 2009, 02:40 PM
  3. Replies: 0
    Last Post: 24th January 2008, 03:58 PM
  4. Printers logon script error messages
    By indie in forum Windows
    Replies: 1
    Last Post: 14th September 2007, 11:34 AM
  5. Replies: 7
    Last Post: 27th November 2005, 11:41 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •