需求是如果有一百台SERVER ,每台SERVER上我都需要打N次
net user %username% /DOMAIN findstr "上次登入時間"
變成100*N次
想問vbscript 有辦法去撈一百台SERVER上的 上次登入時間嗎??
我想net user %username% /DOMAIN findstr "上次登入時間" 中的上次登入時間 應該是有存在電腦某個地方才是
謝謝
---------------解決方法-----------------
後來解決方法是
平常就有紀錄每台SERVER 記錄那些帳號允取那些使用者可以遠端登入
所以把這份表單記錄 跟我另外一篇文章中的程式跑出來的結果作比對
就知道那些人是從來沒有登入過,以及程式跑出來的結果可以得知那些人是超過90天未登入
程式碼如下
#
# All User Profile & OS Info - Santhosh Sivarajan
#
# www.sivarajan.com
#
Cls
$UserInfoFile = New-Item -type file -force "d:\UserInfo.csv"
$FailedComputers_File = New-Item -type file -force "d:\FailedCompuers.csv"
"ComputerName,Profile,LastAccessTime,OSVersion,SPVersion" | Out-File $UserInfoFile -encoding ASCII
"ComputerName" | Out-File $FailedComputers_File -encoding ASCII
write-host -fore Blue "`t--------------------------------------------------------------------------------------------------"
write-host -fore Blue "`tComputer Name`tProfile`t`tLast Access Date`t`tOS Verions`t`t`t`tSP Level`t`tdatdate"
write-host -fore Blue "`t--------------------------------------------------------------------------------------------------"
Import-CSV "D:\input.csv" | % {
$Computer = $_.ComputerName
$ppath1 = "$compuer\c$\Documents and Settings"
$ppath2 = "$computer\c$\Users"
$profileaccess1 = Test-Path \\$ppath1
$profileaccess2 = Test-Path \\$ppath2
If ($profileacces1 -eq "TRUE")
{
$compOS = get-wmiobject Win32_OperatingSystem -comp $computer
$compOSF = $compOS.Caption
$compSP = get-wmiobject Win32_OperatingSystem -comp $computer
$compSPF = $compSP.ServicePackMajorVersion
$profileNames = get-item "\\$ppath1\*"
foreach ($profilename in $profilenames)
{
$accountName = (get-item $profilename).PSChildName
$lastaccesstime = (get-item $profilename).LastAccessTime | get-date –f "MM/dd/yyyy"
"$Computer,$AccountName,$LastAccesstime,$compOSF,$compSPF" | Out-File $UserInfoFile -encoding ASCII -append
write-host -fore Green "`t$Computer`t`t$AccountName`t`t$LastAccesstime`t`t$CompOSF`t`t$CompSPF"
write-host -fore Blue "`t--------------------------------------------------------------------------------------------------"
}
}
ElseIf ($profileaccess2 -eq "TRUE")
{
$compOS = get-wmiobject Win32_OperatingSystem -comp $computer
$compOSF = $compOS.Caption
$compSP = get-wmiobject Win32_OperatingSystem -comp $computer
$compSPF = $compSP.ServicePackMajorVersion
$profileNames = get-item "\\$ppath2\*"
foreach ($profilename in $profilenames)
{
$accountName = (get-item $profilename).PSChildName
$ntuserfolder = "\\$ppath2\$accountName\NTUSER.DAT"
$Dat = Get-Item $ntuserfolder -force
$Dat = $Dat.LastWriteTime| get-date –f "yyyy/MM/dd"
$lastaccesstime = (get-item $profilename).LastAccessTime | get-date –f "yyyy/MM/dd"
"$Computer,$AccountName,$LastAccesstime,$compOSF,$compSPF,$Dat" | Out-File $UserInfoFile -encoding ASCII -append
write-host -fore Green "`t$Computer`t`t$AccountName`t`t$LastAccesstime`t`t$CompOSF`t`t$CompSPF`t`t$Dat`t"
write-host -fore Blue "`t--------------------------------------------------------------------------------------------------"
}
}
Else
{
Write-Host -fore Red "Can't access Computer -> $computer"
"$Computer" | Out-File FailedComputers_File -encoding ASCII -append
}
}