1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
function login0 { param([Parameter(Mandatory=$true, ValueFromPipeline=$true)][String[]]$User,[System.Security.SecureString]$Pass) begin { Add-Type -AssemblyName System.DirectoryServices.AccountManagement $account = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([DirectoryServices.AccountManagement.ContextType]::Machine, $env:userdomain) Write-Host "Principio de login" } process { $password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)) $ok = $account.ValidateCredentials($User, $password) } end { if($ok) { Write-Host "User correcto" } else { Write-Host "User no correcto" } Write-Host "Fin de login" } } login0 -User (Read-Host "Introduzca usuario") -Pass (Read-Host "Introduzca password" -AsSecureString) |
