public static PSObject[] Find(string filter = "") { uint count = 0; int Flag = 0; IntPtr credentialArray = IntPtr.Zero; PSObject[] output = null; if (string.IsNullOrEmpty(filter)) { filter = null; Flag = 1; } NativeMethods.PSCredentialMarshaler helper = new NativeMethods.PSCredentialMarshaler(); if (NativeMethods.CredEnumerate(filter, Flag, out count, out credentialArray)) { IntPtr cred = IntPtr.Zero; output = new PSObject[count]; for (int n = 0; n < count; n++) { cred = credentialArray.ElementAt <IntPtr>(n); output[n] = (PSObject)helper.MarshalNativeToManaged(cred); } helper.CleanUpNativeData(credentialArray); } else { throw new Win32Exception(Marshal.GetLastWin32Error()); } return(output); }
public static PSObject[] Find(string filter = "", bool fix = true) { uint count = 0; int Flag = 0; IntPtr credentialArray = IntPtr.Zero; PSObject[] output = null; if (string.IsNullOrEmpty(filter)) { filter = null; Flag = 1; } else if (fix) { filter = FixTarget(filter); } NativeMethods.PSCredentialMarshaler helper = new NativeMethods.PSCredentialMarshaler(); if (NativeMethods.CredEnumerate(filter, Flag, out count, out credentialArray)) { IntPtr cred = IntPtr.Zero; output = new PSObject[count]; for (int n = 0; n < count; n++) { cred = credentialArray.ElementAt <IntPtr>(n); output[n] = (PSObject)helper.MarshalNativeToManaged(cred); } helper.CleanUpNativeData(credentialArray); } else { int error = Marshal.GetLastWin32Error(); if (error != (int)NativeMethods.CREDErrorCodes.ERROR_NOT_FOUND) { throw new Win32Exception(error); } } return(output); }