Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-credential support for local users #9

Open
majkinetor opened this issue Sep 27, 2017 · 0 comments
Open

test-credential support for local users #9

majkinetor opened this issue Sep 27, 2017 · 0 comments

Comments

@majkinetor
Copy link
Owner

<#
.Synopsis
Verify Local SAM store

.DESCRIPTION
This function takes a user name and a password as input and will verify if the combination is correct. The function returns a boolean based on the result. The script defaults to local user accounts, but a remote computername can be specified in the -ComputerName parameter.

.NOTES   
Name: Test-LocalCredential
Author: Jaap Brasser
Version: 1.0
DateUpdated: 2013-05-20

.PARAMETER UserName
The samaccountname of the Local Machine user account
	
.PARAMETER Password
The password of the Local Machine user account

.PARAMETER ComputerName
The computer on which the local credentials will be verified

.EXAMPLE
Test-LocalCredential -username jaapbrasser -password Secret01

Description:
Verifies if the username and password provided are correct on the local machine, returning either true or false based on the result
#>
function Test-LocalCredential {
    [CmdletBinding()]
    Param
    (
        [string]$UserName,
        [string]$ComputerName = $env:COMPUTERNAME,
        [string]$Password
    )
    if (!($UserName) -or !($Password)) {
        Write-Warning 'Test-LocalCredential: Please specify both user name and password'
    } else {
        Add-Type -AssemblyName System.DirectoryServices.AccountManagement
        $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$ComputerName)
        $DS.ValidateCredentials($UserName, $Password)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant