Mark Damen
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.
I'm running it like this:
.\Get-LoggedOnUsername.ps1 -ComputerName martin-pc
Many Thanks
Mark
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
I'm running it like this:
.\Get-LoggedOnUsername.ps1
Many Thanks
Mark
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Amazingly quick response, answer provided worked first time!
ASKER
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