Few PowerShell Functions Around Windows Security

As parts of the PowerShell project that I’m currently working on, with the help with other people’s contribution in various forums and blogs, I have produced few PowerShell functions around Windows security: Validate Credential [sourcecode language=”PowerShell”] function Validate-Credential($Cred) { $UserName = $Cred.Username $Password = $Cred.GetNetworkCredential().Password Add-Type -assemblyname System.DirectoryServices.AccountManagement $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine) Try { $ValidCredential = $DS.ValidateCredentials($UserName, $Password) } Catch { #if the account does not have required logon rights to the local machine, validation failed. $ValidCredential = $false } Return $ValidCredential } [/sourcecode] Usage: [sourcecode language=”PowerShell”] $MyCredential = Get-Credential $ValidCredential = Validate-Credential $MyCredential [/sourcecode] Get Current User Name [sourcecode

Continue reading
%d bloggers like this: