Public/Get-PCInfo.ps1
Function Get-PCInfo { <# .SYNOPSIS This Function Gets a helpful set of properties for the specific AD computer object provided .NOTES Name: Get-PCInfo Author: Luke Hagar Version: 1.0 DateCreated: 5/12/2021 .EXAMPLE Get-PCInfo -ComputerName "Computer1" #> [CmdletBinding()] param ( [Parameter( Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0 )] [Alias('dnsHostName')] [string]$ComputerName = $env:COMPUTERNAME ) BEGIN {} PROCESS { # Instantiate Variables $Permission = $null $PSRemoting = $null $Permission = $null $RDP = $null $ComputerObject = Get-ADComputer $ComputerName -Properties OperatingSystemVersion, Description, Enabled, CanonicalName # Test Enabled if (Test-Connection $ComputerName -Count 1 -Quiet) { # Test PSRemoting if (Test-PSRemoting -computername $ComputerName) { $PSRemoting = "Open" } else { $PSRemoting = "Closed" } # Test RDP if (Test-NetConnection -CommonTCPPort RDP -ComputerName $ComputerName) { $RDP = "Open" } else { $RDP = "Closed" } if (Test-Path "\\$ComputerName\c$" -ErrorAction SilentlyContinue) { $Permission = $true } else { $Permission = $false } [PSCustomObject]@{ ComputerName = $ComputerName.ToString().ToUpper() Enabled = $ComputerObject.Enabled Online = "Online" RDP = $RDP Permission = $Permission PSRemoting = $PSRemoting Description = $ComputerObject.Description CanonicalName = $ComputerObject.CanonicalName OperatingSystemVersion = $ComputerObject.OperatingSystemVersion } } else { [PSCustomObject]@{ ComputerName = $ComputerName.ToString().ToUpper() Enabled = $ComputerObject.Enabled Online = "Offline" RDP = "Offline" PSRemoting = "Offline" Description = $ComputerObject.Description CanonicalName = $ComputerObject.CanonicalName OperatingSystemVersion = $ComputerObject.OperatingSystemVersion } } } END { } } |