I have no problems getting output with these in v1:
# 1
$printserver="serverName"
net view "\\$printserver" | select-string "print", "Comment"
# 2
function net-view($printserver){
net view "\\$printserver" | select-string "print", "Comment"
}
net-view serverName
BTW, the WMI call be optimized to:
PS > get-wmiobject win32_printer -filter "servername is not null" | select
sharename, servername
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar:
http://tinyurl.com/PSToolbar
R> On Oct 1, 10:44 am, Jason <Ja...@xxxxxx> wrote:
R>
>> All,
>>
>> I'm trying to run a function to assist in mapping printers. Running
>> the following command outside of the function works fine:
>>
>> net view \\servername | select-string "print", "comment"
>>
>> This gives me only the printers on that server (the "comment" ensures
>> that I get the table header)
>>
>> However, when I put that line in a function, the pipe to
>> select-string breaks it, and I get null output; no errors. Any
>> suggestions?
>>
>> function add-printer {
>> write-host Current Mapped Printers:
>> get-wmiobject win32_printer | select sharename, servername | where
>> {$_.servername -ne $null}
>> $printserver = Read-Host "Enter the servername without slashes"
>> net view "\\$printserver" | select-string "print", "Comment"
>> $printer = Read-Host "Type in the exact share name"
>> $printerpath = "\\$printserver\$printer"
>> $net = new-object -com Wscript.network
>> $net.addwindowsprinterconnection($printerpath)
>> get-wmiobject win32_printer | select sharename, servername | where
>> {$_.servername -ne $null}
>> }- Hide quoted text -
>>
>> - Show quoted text -
>> R> That is definitely weird.
R> It happens on my CTP2 machine too.
R> Fixing it is easy.
R> net view "\\$printserver" | select-string "print", "Comment" | write-
R> host
R> Explaining it is a different story.
R> It can be reproduced like this
R>
R> function test ($val) {
R> get-wmiobject win32_printer |
R> select sharename, servername |
R> where {$_.servername -ne $null}
R> net view "$val"| select-string "server"
R> }
R>
R> What is totally weird is that this totally locks up PowerShell. I had
R> to kill the instance.
R>
R> function test ($val) {
R> get-wmiobject win32_printer |
R> select sharename, servername |
R> where {$_.servername -ne $null}
R> net view "$val"| select-string "server"|ft -a
R> }
R>