PoshCode Archive  Artifact [eaa26b2c71]

Artifact eaa26b2c719bf198eecd4110e4cb4e9d6c1d4dc8a4fec1a0341eac0be7b28b11:

  • File Get-CInfo.ps1 — part of check-in [6f0359ab62] at 2018-06-10 13:33:12 on branch trunk — This function allows you to search AD for computers by computer name. Once you find the computer you want it displays info about that computer to you. The info is: Name, IP, OS, exc… (user: D-Money size: 3542)

# encoding: ascii
# api: powershell
# title: Get-CInfo
# description: This function allows you to search AD for computers by computer name. Once you find the computer you want it displays info about that computer to you. The info is: Name, IP, OS, exc…
# version: 0.1
# type: function
# author: D-Money
# license: CC0
# function: Get-CInfo
# x-poshcode-id: 3932
# x-archived: 2013-02-12T14:20:53
# x-published: 2013-02-03T00:01:00
#
# DO FIRST:
# 1. Copy to your Powershell profile.
# 2. Make sure you also get AD imported.(Import-module -name activedirectory)
# How to Use:
# 1. type: Get-CInfo (type in pc name). ##no need for ()##
# -if the name cant be found, a wild card AD search is automatically preformed to help you find the correct pc name.
#
function Get-CInfo {
    param($Comp)

  Function PC-Name{
param ($compname)
$ADS = Get-ADComputer -Filter {name -eq $compname} -Properties * | Select-Object -Property name
If($ads -eq $null) {$false}
ELSE{$True}
                }

$ping = PC-Name $COMP

if ($ping -eq $true) {
Write-Host -ForegroundColor Green ("Computer Info For: $COMP")


$a= @{Expression={$_.Name};Label="Comp. Name";width=25},
    @{Expression={$_.ipv4address};Label="IP Address";width=25},
    @{Expression={$_.operatingsystem};Label="Operating System";width=25},
    @{Expression={$_.Created};Label="Created";width=25},
    @{Expression={$_.lastlogondate};Label="Last Logon";width=25},
    @{Expression={$_.logoncount};Label="# of Logins";width=25}

Get-ADComputer -f {name -eq $comp} -Properties * |
select-object -property name,ipv4address,operatingsystem,created,lastlogondate,logoncount |
format-table -Wrap -AutoSize $A
                        }

ELSEIF ($ping -eq $false) {
                            do { Write-Host -ForegroundColor yellow "No Match Found, Below Is An AD Search, Try Again (CTRL-C to Exit):"
                                $SEARCH = "*$COMP*"
                                Get-ADComputer -Filter {name -like $SEARCH} | Select-Object -property name,enabled | Format-Table -AutoSize
                                $comp = (read-host "What is the Computer Name? (EX. demersm-l7567)").ToLower()
                                function Ping-Server {
                                                     Param([string]$srv)
                                                     $pingresult = Get-WmiObject Win32_PingStatus -Filter  "Address='$srv'"
                                                     if($pingresult.StatusCode -eq 0) {$true} else {$false}
                                                     }
                              
                                $PING2 = PC-Name $COMP
                              }
                            While ($PING2 -eq $false)
                            }
If($ping2 -eq $true){
Write-Host -ForegroundColor Green ("Computer Info For: $COMP")


$a= @{Expression={$_.Name};Label="Comp. Name";width=25},
    @{Expression={$_.ipv4address};Label="IP Address";width=25},
    @{Expression={$_.operatingsystem};Label="Operating System";width=25},
    @{Expression={$_.Created};Label="Created";width=25},
    @{Expression={$_.lastlogondate};Label="Last Logon";width=25},
    @{Expression={$_.logoncount};Label="# of Logins";width=25}

Get-ADComputer -f {name -eq $comp} -Properties * |
select-object -property name,ipv4address,operatingsystem,created,lastlogondate,logoncount |
format-table -Wrap -AutoSize $A
                        }
                        }