Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Test {
- #Allow Verbose
- [cmdletbinding()]
- param(
- #Make computer name parameter mandatory
- [parameter(Mandatory=$True,
- Valuefrompipeline=$True)]
- #allow user to use hostname alias
- [Alias('hostname')]
- [string[]]$computername,
- #log errors
- [switch]$ErrorLog
- )
- BEGIN{
- #If errorlog siwtch is on start
- if ($ErrorLog) {
- #use [cmdletbinding()] to display write-verbose
- Write-Verbose "Error Log On"
- $i = 0
- #Do this loop if Errorlog switch is on
- Do {
- $LogFile = "names-$i.txt"
- $i++
- #Check for path if exist create new file
- } While (Test-Path $LogFile)
- Write-Verbose "LogFile name is $LogFile"
- } else {
- #If Errorlog switch is off
- Write-Verbose "Error Log Off"
- }
- }
- PROCESS{
- Write-Verbose "Connecting to $Computer"
- #log file to $logfile
- if ($ErrorLog) {
- $Computer | Out-File $LogFile -Append
- }
- #set specific output to this variable
- $adminpasswordstatus = Get-WmiObject -class Win32_ComputerSystem | Select-Object -ExpandProperty AdminPasswordStatus
- switch ($adminpasswordstatus)
- {
- 1 {'Disabled'}
- 2 {'Enabled'}
- 3 {'NA'}
- 4 {'Unknown'}
- default {'Try Again'}
- }
- #for each computer grab this information
- foreach ($comps in $computername) {
- $cs = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computername | Select-Object Domain
- $os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computername | Select-Object Version,ServicePackMajorVersion
- $bios = Get-WmiObject -Class Win32_Bios -ComputerName $computername | Select-Object SerialNumber
- $properties = @{'ComputerName' =$computername;
- 'Domain' =$cs.Domain;
- 'AdminPassword'=$AdminPasswordStatus;
- 'OSVersion' =$os.version;
- 'ServicePack' =$os.servicepackmajorversion;
- 'SerialNumber' =$bios.SerialNumber}
- #take objects from hash table and convert to object
- $obj = New-Object -TypeName PSObject -Property $properties
- }
- }
- END{
- #write object named $obj
- Write-Host "$obj"
- }
- }
- test -computername localhost -errorlog -verbose
Advertisement
Add Comment
Please, Sign In to add comment