Created
March 29, 2016 18:28
-
-
Save anonymous/654a2264e0969dad9035c7e31402eeb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Will retrieve the logged on user, and last boot up time for a machine, or list of machines. | |
function GetComputerInfoWork { | |
Param ( | |
[string]$computername | |
) | |
$loggedonuser = Get-WmiObject -computer $computername -class win32_computersystem -ErrorAction Stop | |
$lastboot = Get-WmiObject -computer $computername -class Win32_OperatingSystem -ErrorAction Stop | |
$obj = New-Object -TypeName PSObject | |
$obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $computername | |
$obj | Add-Member -MemberType NoteProperty -Name LoggedOnUser -Value ($loggedonuser.Username) | |
$obj | Add-Member -MemberType NoteProperty -Name LastBoot -Value ($lastboot.ConvertToDateTime($lastboot.LastBootUpTime)) | |
Write-Output $obj | |
} | |
function ErrorHandling { | |
Param ( | |
[string]$pc | |
) | |
$obj2 = New-Object -TypeName PSObject | |
$obj2 | Add-Member -MemberType NoteProperty -Name Unreachable -Value $pc | |
Write-Output $obj2 | |
} | |
function Get-PCInfo { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)] | |
[string[]]$computername | |
) | |
BEGIN {$errorPC = @()} | |
PROCESS { | |
foreach ($computer in $computername) { | |
Try { | |
GetComputerInfoWork -computername $computer -ea Stop | |
} Catch { | |
$errorPC += ,$computer | |
} | |
} | |
} | |
END {foreach ($pc in $errorPC) { | |
ErrorHandling $pc | |
} | |
} | |
} | |
#New-Alias gpc Get-PCInfo | |
#Export-ModuleMember -function Get-PCInfo | |
#Export-ModuleMember -alias gpc | |
Get-PCInfo WWTX41JPRW1,NOTONLINE,WWTXBKVWW32,NOTONLINE2,WWTXBKVWW64,NOTONLINE3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment