#Requires -Version 5
if ($PSVersionTable.PSVersion.Major -ge 6) {Import-Module Microsoft.Powershell.LocalAccounts -SkipEditionCheck}
$OutTable=@()
get-localuser | sort LastLogon,Name | select Name,Enabled,LastLogon,PasswordLastSet,SID | % {
$RegPath='"'+'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\'+$_.SID+'"'
$ProfilePath='C:\Users\'+$_.Name
if (Test-Path $RegPath) {$ProfileImagePath=(Get-ItemProperty -Path $RegPath).ProfileImagePath
} elseif (Test-Path ($ProfilePath)) {$ProfileImagePath=$ProfilePath
} else {$ProfileImagePath=$null}
$Size='0 GB'
if (!($ProfileImagePath -eq $null)) {
$Size='{0:N2} GB' -f ((ls $ProfileImagePath -Recurse -force -ErrorAction SilentlyContinue | `
Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum/1gb)
}
$TableRow=New-Object psobject -Property @{
"Login"=$_.Name
"Enabled"=$_.Enabled
"LastLogon"=$_.LastLogon
"PasswordLastSet"=$_.PasswordLastSet
"SID"=$_.SID
"Size"=$Size
}
$OutTable+=$TableRow
}
$OutTable | Sort Login | ft Login,Size,Enabled,LastLogon,SID,PasswordLastSet
if ($PSVersionTable.PSVersion.Major -ge 6) {Import-Module Microsoft.Powershell.LocalAccounts -SkipEditionCheck}
$OutTable=@()
get-localuser | sort LastLogon,Name | select Name,Enabled,LastLogon,PasswordLastSet,SID | % {
$RegPath='"'+'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\'+$_.SID+'"'
$ProfilePath='C:\Users\'+$_.Name
if (Test-Path $RegPath) {$ProfileImagePath=(Get-ItemProperty -Path $RegPath).ProfileImagePath
} elseif (Test-Path ($ProfilePath)) {$ProfileImagePath=$ProfilePath
} else {$ProfileImagePath=$null}
$Size='0 GB'
if (!($ProfileImagePath -eq $null)) {
$Size='{0:N2} GB' -f ((ls $ProfileImagePath -Recurse -force -ErrorAction SilentlyContinue | `
Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum/1gb)
}
$TableRow=New-Object psobject -Property @{
"Login"=$_.Name
"Enabled"=$_.Enabled
"LastLogon"=$_.LastLogon
"PasswordLastSet"=$_.PasswordLastSet
"SID"=$_.SID
"Size"=$Size
}
$OutTable+=$TableRow
}
$OutTable | Sort Login | ft Login,Size,Enabled,LastLogon,SID,PasswordLastSet
Комментариев нет:
Отправить комментарий