Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-Info {
- [cmdletbinding()]
- param([parameter(
- Mandatory=$True,
- ValueFromPipeline=$true,
- ValueFromPipelineByPropertyName=$true
- )]
- [alias('hostname')]
- [string[]]$ComputerName
- )
- BEGIN{
- $everything = @()
- }
- PROCESS{
- foreach ($Computer in $ComputerName) {
- #only scan WMI if the computer responds to ping
- Write-Verbose "Pinging $computer"
- if(test-connection -ComputerName $computer -Count 1 -Quiet){
- Write-Verbose "$Computer responded to ping"
- try
- {
- $CS = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer -ErrorAction Stop
- $BS = Get-WmiObject -Class Win32_Bios -ComputerName $Computer -ErrorAction Stop
- $OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -ErrorAction Stop
- }
- catch
- {
- "$(get-date) - $computer failed the wmi call!" | out-file c:\errorlog.txt -Append
- $error[0].Exception.Message | out-file c:\errorlog.txt -Append
- }
- Write-Verbose "Switchy switches!"
- switch ($CS.AdminPasswordStatus)
- {
- '0' {$AdminPasswordStatus = "Not set" }
- '1' {$AdminPasswordStatus = "Disabled"}
- '2' {$AdminPasswordStatus = "Enabled"}
- '3' {$AdminPasswordStatus = "N/A"}
- '4' {$AdminPasswordStatus = "Unknown"}
- Default {$AdminPasswordStatus = "FAIL!"}
- }
- switch -Wildcard ($OS.Version)
- {
- '6.1.7600' {$OS.Version = "7"}
- '6.1.7601' {$OS.Version = "7 SP1"}
- '*9200*' {$OS.Version = "8/2012"}
- '*9600*' {$OS.Version = "8.1/2012R2"}
- Default {$OS.Version = "OLD!"}
- }
- #create new object for current computer
- $thiscomputerobj = [pscustomobject][ordered]@{
- ComputerName = $Computer.toupper();
- Domain = $CS.Domain;
- AdminPW = $AdminPasswordStatus;
- Model = $CS.Model;
- Manufacturer = $CS.Manufacturer;
- SerialNumber = $BS.SerialNumber;
- Version = $OS.Version;
- #ServicePack = $OS.ServicePackMajorVersion
- }
- #add the current computer to the summary object
- $everything += $thiscomputerobj
- }#end test-connection if
- }#end foreach
- }#end Process
- End{
- Write-Verbose 'End'
- $everything
- }
- }#end function
- Get-Info
Advertisement
Add Comment
Please, Sign In to add comment