Skip to content

Instantly share code, notes, and snippets.

@rnemeth90
Created April 28, 2022 17:25
Show Gist options
  • Save rnemeth90/965a158dad354eb0dff88adc108bf2ae to your computer and use it in GitHub Desktop.
Save rnemeth90/965a158dad354eb0dff88adc108bf2ae to your computer and use it in GitHub Desktop.
Get HostName Extended File Attribute using C# and Powershell
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