This repository was archived by the owner on Jan 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobject-pscustomobject.ps1
More file actions
53 lines (37 loc) · 1.39 KB
/
object-pscustomobject.ps1
File metadata and controls
53 lines (37 loc) · 1.39 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Clear the content of the textfile (if it exists)
If (Test-Path .\dumpcomputers.txt) {
Clear-Content .\dumpcomputers.txt
}
# Populate the textfile
$hostname = hostname
for ($i=0;$i -lt 5; $i++) { Add-Content .\dumpcomputers.txt $hostname }
$computers = Get-Content .\dumpcomputers.txt
# Instantiate the array for the objects
$output = @();
# Loop through all $computers in $hostname file
foreach($entry in $computers) {
# Let's create a complex object with an array as a property
$psversions = $PSVersionTable
$psversion = @()
foreach ($p in $psversions) {
$psobject = [pscustomobject]@{
PSVersie = $p.PSVersion
WSMANVersie = $p.WSManStackVersion
}
$psversion += $psobject
}
# Collect other info
$info = Get-WmiObject -Class Win32_OperatingSystem -Computername $entry
$bios = Get-WmiObject -Class Win32_Bios -Computername $entry
# create the object for reporting
$object = [pscustomobject]@{
fabrikant = $bios.manufacturer;
serial = $info.serialnumber;
registratienaam = $info.registereduser;
datum = (Get-Date);
company = 'Contoso';
powershell = $psversion;
}
$output += $object
}
$output | Export-Csv dump2.csv