Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:15:56+00:00 2026-06-14T19:15:56+00:00

The script works fine and will toggle through the printers on the servers and

  • 0

The script works fine and will toggle through the printers on the servers and determine if the printers are shared (TRUE). But the problem arises if the last printer on the server happens to not be shared, it then changes the shared to (False). which skews the results in the spreadsheet stating that the server is not a print server although it is. I need to some how create a loop stating that if we find one shared printer on a server, stop the search and place the server in the spread sheet flagged as a print server.

I would like to put in something like
$Printers = gwmi Win32_Printer -computername $StrComputer
if ($printers.shared -eq "True){# then stop searching that machine
and place it in the speadsheet as a print server}

Here is my code :

foreach ($StrComputer in $colComputers){
            $Printers = gwmi Win32_Printer -computername $StrComputer
            $GenItems1 = gwmi Win32_OperatingSystem -Comp $StrComputer

    # Populate Printer Sheet with information
        foreach ($objItem in $GenItems1){
            $Sheet1.Cells.Item($intRow, 1) = $StrComputer
            $Sheet1.Cells.Item($intRow, 2) = $objItem.Caption
            $Sheet1.Cells.Item($intRow, 3) = $objItem.CSDVersion
            }

        foreach ($objItem in $Printers){
            $Sheet1.Cells.Item($intRow, 4) = $objItem.Shared

            }

        $de = New-Object System.DirectoryServices.DirectoryEntry
        $ds = New-Object System.DirectoryServices.DirectorySearcher
        $ds.SearchRoot = $de
        $ds.Filter = "(&(objectCategory=computer)(objectClass=computer)(samAccountName=$($StrComputer)$))"
        $ds.SearchScope = "SubTree"
        $r = $ds.FindOne()
        $r.Path
        $Sheet1.Cells.Item($intRow, 5) = $r.Path

            $intRow = $intRow + 1}
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:15:57+00:00Added an answer on June 14, 2026 at 7:15 pm

    change this:

    foreach ($objItem in $Printers){
                $Sheet1.Cells.Item($intRow, 4) = $objItem.Shared
                }
    

    with this:

    $isprinterserver = $false
    $printers | % { if ($_.shared -eq $true) { $isprinterserver = $true; break} }
    $Sheet1.Cells.Item($intRow, 4) = $isprinterserver
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This script works fine on single click but on double click it shows both
The script below works fine if 3 and 3.2 are not links but i
The following works fine in Firefox and Chrome, but IE 8 will not call
I have the following script which works fine: $(.txtDate).datepicker( { changeMonth: true, changeYear: true,
The following script works fine: $(#regform).validate().showErrors({username:message}); After I changed the script to the below
Firstly, the bash script works fine when I call it outside of ant. Here
We have a ubuntu test server that this simple script works fine on where
I am using HTTPPost to send values to a server. The script works fine
I have this jQuery script that works fine: $(select).change(function () { var finalPrice =
I'm using this script which works fine for a single lightbox popup window. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.