-
-
Save santisq/4afe32328ee5da7e4b3f80dd9b373c9d to your computer and use it in GitHub Desktop.
| using System; | |
| using System.Collections; | |
| using System.Linq; | |
| using System.Management.Automation; | |
| using System.Reflection; | |
| using System.Text; | |
| using Microsoft.PowerShell.Commands; | |
| using PowerShell ps = PowerShell.Create().AddCommand("Get-ComputerInfo"); | |
| ComputerInfo info = ps.Invoke<ComputerInfo>()[0]; | |
| PropertyInfo[] props = typeof(ComputerInfo).GetProperties(); | |
| int max = props.Max(e => e.Name.Length); | |
| foreach (PropertyInfo prop in props) | |
| { | |
| Console.WriteLine( | |
| $"\e[92m{prop.Name.PadRight(max)} :\e[0m {prop.GetValue(info)}"); | |
| } |
| <Project Sdk="Microsoft.NET.Sdk"> | |
| <PropertyGroup> | |
| <OutputType>Exe</OutputType> | |
| <TargetFramework>net9</TargetFramework> | |
| <Nullable>enable</Nullable> | |
| <LangVersion>latest</LangVersion> | |
| <NoWarn>MSB3277</NoWarn> | |
| </PropertyGroup> | |
| <ItemGroup> | |
| <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.2" /> | |
| <Reference Include="Commands.Management"> | |
| <HintPath>C:\Program Files\PowerShell\7\Microsoft.PowerShell.Commands.Management.dll</HintPath> | |
| </Reference> | |
| <Reference Include="ServiceProcess.ServiceController"> | |
| <HintPath>C:\Program Files\PowerShell\7\System.ServiceProcess.ServiceController.dll</HintPath> | |
| </Reference> | |
| <Reference Include="System.Management"> | |
| <HintPath>C:\Program Files\PowerShell\7\System.Management.dll</HintPath> | |
| </Reference> | |
| </ItemGroup> | |
| </Project> |
santisq
commented
Oct 3, 2025
That's curious - I tried your exact code, except that I used v7.5.3 (both the SDK and the standalone PS 7 installation), and it doesn't work for me (Microsoft Windows 11 Pro (ARM 64-bit Processor; Version 24H2, OS Build: 26100.6584)).
That's curious - I tried your exact code, except that I used v7.5.3 (both the SDK and the standalone PS 7 installation), and it doesn't work for me (Microsoft Windows 11 Pro (ARM 64-bit Processor; Version 24H2, OS Build: 26100.6584)).
@mklement0 indeed, 7.5.3 doesn't work for me either
Thanks for confirming; mysterious.
I've summarized the findings so far in a footnote to https://stackoverflow.com/a/79778070/45375 (which now links to this Gist).
If you come across further information, please leave a comment there.
Thanks for confirming; mysterious.
I've summarized the findings so far in a footnote to https://stackoverflow.com/a/79778070/45375 (which now links to this Gist).
If you come across further information, please leave a comment there.
@mklement0 If he doesn't know then we're surely out of luck 😅
Thanks; I appreciate the follow-up.