0
我有一個CSV文件中的用戶列表,我想查明他/她們上次登錄時我可以得到此信息對於個人帳戶,但我需要將其寫入多個帳戶的文件。錯誤代碼爲「Missing =操作符後鍵入哈希文字,哈希文字不完整」
我得到的錯誤:
At line:5 char:7
import-module activedirectory
Missing = operator after key in hash literal
hash literal was incomplete
我的代碼:
$resultList = @()
Import-Csv C:\Users\admin\Desktop\SamAccountName.csv -header("SamAccountName") | Foreach-Object{
$user = ([adsisearcher]"(samAccountName=$($_.SamAccountName))").FindOne()
$resultList += New-Object -TypeName PSObject -Property @{
SamAccountName = $_.SamAccountName
Import-Module ActiveDirectory
function Get-ADUserLastLogon([string]$_.userName)
{
$dcs = Get-ADDomainController -Filter {Name -like "*"}
$time = 0
foreach($dc in $dcs)
{
$hostname = $dc.HostName
$user = Get-ADUser $userName | Get-ADObject -Properties lastLogon
if($user.LastLogon -gt $time)
{
$time = $user.LastLogon
}
}
$dt = [DateTime]::FromFileTime($time)
Write-Host $username "last logged on at:" $dt }
Get-ADUserLastLogon -UserName $user
}
}
}
$resultList | export-csv -Path c:\users\admin\desktop\SamAccountName_results.csv -NoTypeInfo
它告訴你到底發生了什麼問題 - 在執行'Import-Module'之前,你從未關閉過'@ {'''。 –
[所有域控制器CSV輸出中的Lastlogon可能重複](http://stackoverflow.com/questions/41042336/lastlogon-from-all-domain-controllers-csv-output) –
Jeff您是對的。它現在說我錯過了')' 函數get-aduserlastlogon([string] $ _。username)有什麼想法? –