sans_souciの日記

無憂茶房

sample/パスワード生成/powershell

パスワード生成

sample

add-type -AssemblyName System.Web

$mysmall=0
$mybig=0
$mysign = 0
$mynumber = 0
$myother = 0  
#$myarray = "abcABC!@#$%^&*()_-+=[{]};:<>|./?" -split ""
#$myarray = "abcABC%" -split ""

$xresult = ([System.Web.Security.Membership]::GeneratePassword(8,1))    
$myarray = $xresult -split ""

foreach ( $myindex in $myarray){
#  echo $myindex
  if($myindex -cmatch "[a-z]" ){      # a-z
    $mysmall += 1
  }elseif($myindex -cmatch "[A-Z]"){ # A-Z
    $mybig += 1
  }elseif($myindex -cmatch "[\!@#\$%\^\&\*\(\)_\-\+\=\[\{\]\}\;\:\<\>\|\.\/\?]" ){     # SIGN
    $mysign += 1
  }elseif($myindex -cmatch "[0-9]"){
    $mynumber +=1
  }else{
    echo "xxxmyindex : $myindex"
    $myother += 1
  }
}
echo "small: $mysmall"
echo "big: $mybig"
echo "sign: $mysign"
echo "number: $mynumber"
echo "other: $myother"
if($mysmall -ge 1 -and $mybig -ge 1 -and $mysign -ge 1 -and $mynumber -ge 1){
  echo "OK"
}else{
  echo "FALSE"
}
echo $xresult
  • 課題/記号、メタ文字の判定
  • GeneratePassword の根っこ