获取本地用户及其所属组
$Res_Path = "d:\temp\" $Time = Get-Date -UFormat "%Y%m%d%H%M" $ComputerName = $env:computername $IP = ((gwmi win32_networkadapterconfiguration | ? {$_.DefaultIPGateway -ne $null}).IPAddress)[0] $Res_File_Path = $Res_Path + $ComputerName + "_" + $Time + ".csv" $Users = Get-LocalUser "计算机名称,IP,用户名,用户状态,密码过期时间,用户所属组" |Out-File $Res_File_Path -Append -Encoding default foreach ($User in $Users) { $Groups = Get-LocalGroup | Where-Object { $user.SID -in ( Get-LocalGroup $_ | Get-LocalGroupMember | Select-Object -ExpandProperty "SID" ) } $UGS = $Null foreach ($g in $Groups) {$UGS += $g.Name + "; "} if ( $User.PasswordExpires -eq $Null) { $PasswordExpireDate = "永不过期" } else { $PasswordExpireDate = Get-Date $user.PasswordExpires -UFormat "%Y-%m-%d %H:%M:%S" } $ComputerName + "," + $IP + "," + $User.Name + "," + $User.Enabled + "," + $PasswordExpireDate + "," + $UGS |Out-File $Res_File_Path -Append -Encoding default }