0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ランダムなパスワード作成スクリプト

Posted at

記事というよりも、完全に個人的なメモ用ですが、PowerShellを使用してランダムな文字でパスワードを作成するスクリプトです。パスワードを作成するときに、適当にPCのキーボードを打つというのもありですが、癖もあって同じような文字列になりがちでした。
そこでPowerShellでランダムにパスワードを作成するようにしました。
生成されたものをコピペで使用しようかなと思っていますwww

  • 記号も使う場合は、コメントになっている$charsを替わりに使用してください
  • $passwordlengthでパスワードの長さを指定しています

パスワード作成

# 定数の設定
# 記号も使用する場合
#$chars = @('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
#           'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
#           '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
#           '!', '#', '$', '%', '&', '(', ')', '{', '{', '@', '[', ']', '+', ';', ':', '*', '\', '-', '=')

# 英数字のみ
$chars = @('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
           'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
           '0', '1', '2', '3', '4', '5', '6', '7', '8', '9')

$charCount = $chars.Length
$passwordLength = 20

# パスワード生成用の配列
$pass = @()

# ランダムな文字を配列に追加
for ($cnt = 0; $cnt -lt $passwordLength; $cnt++) {
    $pass += $chars[(Get-Random -Minimum 0 -Maximum $charCount)]
}

# パスワードを生成
$PASSWORD = -join $pass

# 結果を出力
Write-Output "ランダム作成されたパスワード"
Write-Output $PASSWORD
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?