Last active
April 19, 2018 12:03
-
-
Save SasStu/3eca866d420cf745ac7650e267d7240f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-LocalUserAccount { | |
[CmdletBinding()] | |
param ( | |
[Parameter( | |
ValueFromPipeline = $true, | |
ValueFromPipelineByPropertyName = $true | |
)] | |
[string[]] $Computer = $env:COMPUTERNAME, | |
[Parameter(Mandatory = $true)] | |
[string] $Name | |
) | |
foreach ($item in $Computer) { | |
[ADSI] $host = [string]::Format("WinNT://{0}", $item) | |
if ($Name) { | |
foreach ($user in $Name) { | |
$host.Children | where { $_.SchemaClassName -eq "User" -and $_.Name -eq $user } | |
} | |
} | |
else { | |
$host.Children | where {$_.SchemaClassName -eq "User"} | |
} | |
} | |
} | |
$AdminAccountName = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft Services\AdmPwd' -Name 'AdminAccountName' -ErrorAction SilentlyContinue).AdminAccountName | |
$item = Get-LocalUserAccount -Name $AdminAccountName | |
if ($item -eq $null -and $AdminAccountName -ne $null -and ((Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft Services\AdmPwd' -Name 'AdmPwdEnabled' -ErrorAction SilentlyContinue).AdmPwdEnabled) -eq '1' -and (Get-Item -Path ($env:ProgramFiles + '\LAPS\CSE\AdmPwd.dll') -ErrorAction SilentlyContinue)) { | |
return $false | |
} | |
else { | |
return $true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment