Project 1 audit user
This commit is contained in:
21
week 1/projects/User audit Script/userAudit.ps1
Normal file
21
week 1/projects/User audit Script/userAudit.ps1
Normal file
@@ -0,0 +1,21 @@
|
||||
$users = Get-LocalUser
|
||||
|
||||
foreach($username in -split $users){
|
||||
|
||||
$badChar = $false
|
||||
|
||||
foreach ($char in $username.ToCharArray()) {
|
||||
if($char -notmatch "[A-Za-z]"){
|
||||
$badChar = $true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
$fistChar = $username[0]
|
||||
$validFirstLetter = $fistChar -match "[A-Za-z]"
|
||||
|
||||
if ($badChar -or $username.Length -ge 20 -or -not $validFirstLetter ){
|
||||
Write-Host "the userName " + $username + " is invalid"
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user