$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 }
标签:ComputerName,Get,Res,本地用户,获取,User,File,Path,所属 From: https://www.cnblogs.com/dreamer-fish/p/17770177.html