Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-Info {
- [cmdletbinding()]
- param(
- [parameter(Mandatory)]
- [alias('hostname')]
- [string[]]$ComputerName
- )
- BEGIN{
- Write-Verbose 'Begin'
- }
- PROCESS{
- Write-Verbose 'Process'
- foreach ($Computer in $ComputerName) {
- try{
- Write-Verbose 'Continue or not to Continue'
- $Continue = $true
- $AdminPasswordStatus = Get-WmiObject -EV myerr1 -EA stop -Class Win32_ComputerSystem -ComputerName $ComputerName `
- `
- | Select-Object -ExpandProperty AdminPasswordStatus
- $CS = Get-WmiObject -EV myerr2 -EA stop -Class Win32_ComputerSystem -ComputerName $ComputerName `
- `
- | Select-Object -Property Domain,Model,Manufacturer
- $BS = Get-WmiObject -EV myerr3 -EA stop -Class Win32_Bios -ComputerName $ComputerName `
- `
- | Select-Object -property SerialNumber
- $OS = Get-WmiObject -EV myerr4 -EA stop -Class Win32_OperatingSystem -ComputerName $ComputerName `
- `
- | Select-Object -Property Version,ServicePackMajorVersion
- } catch {
- Write-Verbose 'Catch'
- $Continue = $false
- $Computer = Out-File C:\errorlog.txt
- $myerr1 | Out-File C:\errormessages.txt -Append
- $myerr2 | Out-File C:\errormessages.txt -Append
- $myerr3 | Out-File C:\errormessages.txt -Append
- $myerr4 | Out-File C:\errormessages.txt -Append
- }
- if ($Continue = $true) {
- Write-Verbose 'Pass thru if the if fits'
- switch ($AdminPasswordStatus)
- {
- '1' {$AdminPasswordStatus = "Disabled"}
- '2' {$AdminPasswordStatus = "Enabled"}
- '3' {$AdminPasswordStatus = "NA"}
- '4' {$AdminPasswordStatus = "Unknown"}
- Default {"Sorry"}
- }
- $obj = [pscustomObject] @{
- ComputerName = $ComputerName;
- Domain = $CS.Domain;
- AdminPW = $AdminPasswordStatus
- Model = $cs.Model;
- Manufacturer = $CS.Maanufacturer;
- SerialNumber = $BS.SerialNumber;
- Version = $OS.Version;
- ServicePack = $OS.ServicePackMajorVersion}
- }
- }
- }
- End{
- Write-Verbose 'End'
- $obj
- }
- }
- Get-Info -ComputerName localhost, noton -Verbose
Advertisement
Add Comment
Please, Sign In to add comment