Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Get-SystemInfo { #Create Function
- param( #Create Paramater
- [string[]]$ComputerName = 'localhost'#Create an Array of Strings ALL named $ComputerName: ie $ComputerName = @("ComputerName","ComputerName")
- )
- begin{ #Start giant script block, I'm confused by begin an end, why is this needed? If it is all in the function, isn't that enough?
- $comps = @() #Create new empty array to be used at a later time
- }
- process{ #This represents another script block?
- ForEach ($computer in $ComputerName){ #ForEach loop For every $computer which we JUST created in this ForEach loop: $ComputerName run the switch below.
- $AdminPasswordStatus = Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName $computer | Select-Object -ExpandProperty AdminPasswordStatus #Create variable = to this value
- switch ($AdminPasswordStatus) #Switch, this one is pretty simple.
- {
- 1 {$AdminPasswordStatus = "Disabled"}
- 2 {$AdminPasswordStatus = "Enabled"}
- 3 {$AdminPasswordStatus = "Not Available"}
- 4 {$AdminPasswordStatus = "Unknown"}
- default {"Possible Error"}
- }
- $OS = Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $computer #Create variable = to this value
- $BIOS = Get-CimInstance -ClassName Win32_BIOS -ComputerName $computer #Create variable = to this value
- #Everything below this point is new to me but I'm going to try to follow the logic.
- $obj = [pscustomObject]@{ #Create a custom object, This is neat I did not know this.
- ComputerName = $computer
- AdminPasswordStatus = $AdminPasswordStatus
- OSVersion = $OS.Version #Get-CimInstance -Classname Win32_Operatingsystem.property which is Version
- OSPatch = $OS.ServicePackMajorVersion #Get-CimInstance -Classname Win32_Operatingsystem.property which is ServicePackMajorVersion
- Bios = $BIOS.SerialNumber #Get-CimInstance -Classname Win32_BIOS.property which is SerialNumber
- }
- #end of the ForEach loop, we now store this $obj in $comps
- $comps += $obj #This one is confusing. This means I have more than one $comps so you will need to make an $obj for each $comps?
- }
- }
- end{#End giant script block, I'm confused by begin an end, why is this needed? If it is all in the function, isn't that enough?
- Write-host ("`$comps contains " + ($comps.Count) + " Objects") #Output how many computers you are running this script on.
- $comps | Format-Table #Change output to Format-Table
- }
- }
- Get-SystemInfo #Call Function
Advertisement
Add Comment
Please, Sign In to add comment