Add-Type@" using System; using System.Runtime.InteropServices; public class Win32Cred { [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct CREDENTIAL { public int Flags; public int Type; public IntPtr TargetName; public IntPtr Comment; public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten; public int CredentialBlobSize; public IntPtr CredentialBlob; public int Persist; public int AttributeCount; public IntPtr Attributes; public IntPtr TargetAlias; public IntPtr UserName; } [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern bool CredReadW(string target, int type, int reservedFlag, out IntPtr credentialPtr); [DllImport("advapi32.dll", SetLastError = true)] public static extern void CredFree(IntPtr buffer); public static string CredRead(string targetName, int type = 1) { IntPtr credPtr; if (CredReadW(targetName, type, 0, out credPtr)) { CREDENTIAL cred = (CREDENTIAL)Marshal.PtrToStructure(credPtr, typeof(CREDENTIAL)); string pass = Marshal.PtrToStringAnsi(cred.CredentialBlob, cred.CredentialBlobSize); CredFree(credPtr); return pass; } throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); } } "@