2014-03-13 1 views
0

사용자 및 암호의 두 가지 범주로 해시 테이블을 만들려고합니다. 이것은 지금까지의 코드입니다. 그러나 문제는 출력이 명령을 표시하고 실행하지 않는다는 것입니다. 해시 테이블에 gc 출력 값

for ($i=1; $i -le 10; $i++){ 
$caps = [char[]] "ABCDEFGHJKMNPQRSTUVWXY" 
$lows = [char[]] "abcdefghjkmnpqrstuvwxy" 
$nums = [char[]] "2346789" 
$spl = [char[]] "[email protected]#$%^&*?+" 

$first = $lows | Get-Random -count 1; 
$second = $caps | Get-Random -count 1; 
$third = $nums | Get-Random -count 1; 
$forth = $lows | Get-Random -count 1; 
$fifth = $spl | Get-Random -count 1; 
$sixth = $caps | Get-Random -count 1; 

$pwd = [string](@($first) + @($second) + @($third) + @($forth) + @($fifth) + @($sixth)) 

Out-File C:\Users\Administrator\Documents\L8_userpasswords.txt -InputObject $pwd -Append 

} 

$here = @' 
$users=Get-Content C:\\Users\\Administrator\\Desktop\\L8_users.txt 
$passwords=Get-Content C:\\Users\\Administrator\\Documents\\L8_userpasswords.txt 
'@ 
convertfrom-stringdata -stringdata $here 

내가 무엇입니까 출력입니다 :

PS C:\Users\Administrator> C:\Users\Administrator\Documents\l8.ps1 

Name   Value 
----   ----- 
$users   Get-Content C:\Users\Administrator\Desktop\Lab8_users.txt 
$passwords  Get-Content C:\Users\Administrator\Documents\L8_userpasswords.txt 

답변

1

난 당신이 원하는 생각하는 HashTable으로 사용자와 암호 목록을 설정 한 다음 PSCustomObject에 캐스팅되며, 이는 두 가지 속성을 갖습니다 : UsersPasswords.

$Data = [PSCustomObject]@{ 
    Users = Get-Content -Path C:\Users\Administrator\Desktop\L8_users.txt; 
    Passwords = Get-Content -Path C:\Users\Administrator\Desktop\L8_userpasswords.txt; 
} 
$Data; 
+0

: 동일한 수의 항목, 당신은 이런 일을 할 수 '이름 값 ---- ----- 값 {dV7a @ H, wT9x + U, bU3y @ Y, vC9s & R ...} 이름 {마이크 베이커, 메리 마틴, 우마 Siveram, 우리 Demisky ...}' – Musa

+0

@ TazB. 해당 정보로 질문을 업데이트하십시오. 이 모든 것을 읽을 수있는 것은 아닙니다. –

0

또는 이봐, 당신은 아마 단지 하나 라이너로 전체 스크립트를 대체 할 수있다 : 당신은 최고입니다 비밀번호 생성 루프

GC C:\Users\Administrator\Desktop\L8_users.txt|%{[PSCustomObject]@{User=$_;Password=[System.Web.Security.Membership]::GeneratePassword(10,3)}} 

을 부착하지 않는. [System.Web.Security.Membership]::GeneratePassword(X,Y)은 X가 길이이고 Y가 특수 문자의 수인 복잡한 암호를 생성합니다 (나머지는 대문자, 소문자 및 숫자의 임의의 조합입니다). 따라서 내 코드 (10,3)에는 영숫자가 아닌 문자가 3 개인 10 자 암호가 있습니다.

파일에 저장 하시겠습니까? 그걸 파이프 Export-CSV. 또는 접두어로 $UserList = <code>과 같은 변수를 지정하십시오.

또는 당신은 정말, 정말 해시 테이블은 당신이 빈 하나를 만든 다음 그냥 조금이 같은 테이블에 각 쌍을 추가 변경할 수 원하는 경우 : L8_users.txtL8_userpasswords.txt 포함한다고 가정

$UserList = @{} 
GC C:\Users\Administrator\Desktop\L8_users.txt|%{$UserList.add($_,[System.Web.Security.Membership]::GeneratePassword(10,3))} 
0

나는이 노력하고 있지만 지금 내 출력 그냥 상태

$users  = Get-Content 'C:\Users\Administrator\Desktop\L8_users.txt' 
$passwords = Get-Content 'C:\Users\Administrator\Documents\L8_userpasswords.txt' 

$userpasswords = @{} 
for ($i = 0; i -lt $users.Length; $i++) { 
    $userpasswords[$users[$i]] = $passwords[$i] 
}