Created
April 28, 2022 17:25
-
-
Save rnemeth90/965a158dad354eb0dff88adc108bf2ae to your computer and use it in GitHub Desktop.
Get HostName Extended File Attribute using C# and Powershell
This file contains 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.Diagnostics; | |
string path = @"C:\Path\to\your\file.txt"; | |
ProcessStartInfo processInfo = new ProcessStartInfo(); | |
processInfo.FileName = @"powershell.exe"; | |
processInfo.Arguments = $@"-Command $ErrorActionPreference = 'Stop'; $VerbosePreference = 'Continue'; $ProgressPreference = 'SilentlyContinue'; | |
$fi = Get-ItemProperty -Path '{path}'; | |
$ShellApplication = New-Object -ComObject Shell.Application; | |
$ShellFolder = $ShellApplication.Namespace($fi.Directory.FullName); | |
$ShellFile = $ShellFolder.ParseName($fi.Name); | |
$nameParts = $ShellFolder.GetDetailsOf($ShellFile, 61) -split ' '; | |
$nameParts[0];"; | |
processInfo.RedirectStandardError = true; | |
processInfo.RedirectStandardOutput = true; | |
processInfo.UseShellExecute = false; | |
processInfo.CreateNoWindow = true; | |
Process process = new Process(); | |
process.StartInfo = processInfo; | |
process.Start(); | |
Console.Write(process.StandardOutput.ReadToEnd().Trim()); | |
Console.Read(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment