Last active
October 5, 2025 19:19
-
-
Save santisq/4afe32328ee5da7e4b3f80dd9b373c9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)}"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> |
Author
Thanks; I appreciate the follow-up.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mklement0 If he doesn't know then we're surely out of luck 😅