說明:
1、密碼一共8位。
2、由2個數(shù)字,2個大寫字符,2個小寫字符,2個特殊字符組成。
3、字符的次序是隨機組成的。
復(fù)制代碼 代碼如下:
function CreatePassword
{
$figure=1,2,3,4,5,6,7,8,9;
$capital="Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M";
$lowercase="q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m";
$specialCharacter="~","!","@","#","$","%","^","","*","(",")","-","+";
$order=New-Object System.Collections.ArrayList;
for($i=0;$i -lt 8;$i++)
{
[void]$order.Add($i);
}
$newOrder=@();
for($i=0;$i -lt 8;$i++)
{
$produceOrder=Get-Random -InputObject $order;
$newOrder+=$produceOrder;
$order.Remove($produceOrder);
}
$newPassword=@();
foreach($i in $newOrder)
{
if($i -eq 0)
{
$index=Get-Random -Maximum 8;
$newPassword+=$figure[$index];
}
if($i -eq 1)
{
$index=Get-Random -Maximum 8;
$newPassword+=$figure[$index];
}
if($i -eq 2)
{
$index=Get-Random -Maximum 25;
$newPassword+=$capital[$index];
}
if($i -eq 3)
{
$index=Get-Random -Maximum 25;
$newPassword+=$capital[$index];
}
if($i -eq 4)
{
$index=Get-Random -Maximum 25;
$newPassword+=$lowercase[$index];
}
if($i -eq 5)
{
$index=Get-Random -Maximum 25;
$newPassword+=$lowercase[$index];
}
if($i -eq 6)
{
$index=Get-Random -Maximum 12;
$newPassword+=$specialCharacter[$index];
}
if($i -eq 7)
{
$index=Get-Random -Maximum 12;
$newPassword+=$specialCharacter[$index];
}
}
return $newPassword -join "";
}
測試結(jié)果:
您可能感興趣的文章:- PowerShell腳本 隨機密碼生成器(ps隨機密碼生成器)
- PowerShell批量修改AD用戶密碼屬性的代碼
- PowerShell中實現(xiàn)混淆密碼示例
- Powershell讀取PFX證書并輸入密碼的腳本分享
- PowerShell小技巧之獲取Windows系統(tǒng)密碼Hash
- PowerShell生成隨機密碼的方法
- PowerShell 腳本中的密碼保存的方法