Link to home
Start Free TrialLog in
Avatar of Mark Damen
Mark DamenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell Script - Why no Output?

I have downloaded the below Powershell script from Microsoft - BUT, running it results in no output, not even the error that is included within the script.

 
function LoggedOnUser {
#Requires -Version 2.0            
[CmdletBinding()]            
 Param             
   (                       
    [Parameter(Mandatory=$true,
               Position=0,                          
               ValueFromPipeline=$true,            
               ValueFromPipelineByPropertyName=$true)]            
    [String[]]$ComputerName
   )#End Param

Begin            
{            
 Write-Host "`n Checking Users . . . "
 $i = 0            
}#Begin          
Process            
{
    $ComputerName | Foreach-object {
    $Computer = $_
    try
        {
            $processinfo = @(Get-WmiObject -class win32_process -ComputerName $Computer -EA "Stop")
                if ($processinfo)
                {    
                    $processinfo | Foreach-Object {$_.GetOwner().User} | 
                    Where-Object {$_ -ne "NETWORK SERVICE" -and $_ -ne "LOCAL SERVICE" -and $_ -ne "SYSTEM"} |
                    Sort-Object -Unique |
                    ForEach-Object { New-Object psobject -Property @{Computer=$Computer;LoggedOn=$_} } | 
                    Select-Object Computer,LoggedOn
                }#If
        }
    catch
        {
            "Cannot find any processes running on $computer" | Out-Host
        }
     }#Forech-object(ComputerName)       
            
}#Process
End
{

}#End

}#LoggedOnUser

Open in new window


I'm running it like this:

 .\Get-LoggedOnUsername.ps1 -ComputerName martin-pc

Many Thanks
Mark
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark Damen

ASKER

Excellent, many thanks for the prompt reply that worked.

2 more quick questions if I may, I will accept your first reply as the answer and award points.

How would I pipe a computer list into this function?
How would I supply a text file computer list into this function?

Many Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Amazingly quick response, answer provided worked first time!