-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreate.Objects.ps1
More file actions
39 lines (29 loc) · 996 Bytes
/
Create.Objects.ps1
File metadata and controls
39 lines (29 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Create Objects
#region Using Add-Member
$OS = gwmi Win32_OperatingSystem
$ComputerName = $env:COMPUTERNAME
# Create new PS custom object
$Obj = New-Object –Type PSObject
# Add members
$Obj | Add-Member –Name OS –Value $OS.Caption –Type NoteProperty
$Obj | Add-Member –Name ServicePack –Value $OS.CSDVersion –Type NoteProperty
$Obj | Add-Member –Name Version –Value $OS.Version –Type NoteProperty
$Obj | Add-Member –Name ComputerName –Value $ComputerName –Type NoteProperty
$Obj | Add-Member –Name Name –Value OS –Type AliasProperty
# Return PS Object (to pipeline)
$Obj
$Obj | gm
#endregion
#region Using New-Object with Hash table
$Properties = @{
OS = $OS.Caption
ServicePack = $OS.CSDVersion
Version = $OS.Version
ComputerName = $ComputerName
}
$Obj = New-Object –Type PSObject –Property $Properties
# Return PS Object (to pipeline)
$Obj
$Obj | gm
Remove-Variable Obj -Force
#endregion