Kelly Garcia
asked on
Powershell Code
Hi All,
I am trying to understand the code below. The foreach - what exactly is it looping through???
Regards,
K
I am trying to understand the code below. The foreach - what exactly is it looping through???
$data = Get-WmiObject -Class Win32_OperatingSystem | ForEach {
New-Object PSObject -Property @{
Computername = $env:computername
OS = $_.Caption
Version = $_.Version
SystemDirectory = $_.systemdirectory
Serialnumber = $_.serialnumber
InstalledOn = ($_.ConvertToDateTime($_.InstallDate))
LastReboot = ($_.ConvertToDateTime($_.LastBootUpTime))
}
Regards,
K
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The important part is that you do not read it like this
($data = Get-WMIObject ...) | foreach { ... }
but$data = ( Get-WMIObject ...) | foreach { ... } )
i.e. the expression including pipeline is executed, and the result assigned to the var.
Open in new window