Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. Param
  2. (
  3. [Parameter(Position=0,Mandatory=$false)]
  4. [ValidateNotNullorEmpty()]
  5. [Alias('cn')][String[]]$ComputerName=$Env:COMPUTERNAME,
  6. [Parameter(Position=1,Mandatory=$false)]
  7. [Alias('un')][String[]]$AccountName,
  8. [Parameter(Position=2,Mandatory=$false)]
  9. [Alias('cred')][System.Management.Automation.PsCredential]$Credential
  10. )
  11.  
  12. $Obj = @()
  13.  
  14. Foreach($Computer in $ComputerName)
  15. {
  16. If($Credential)
  17. {
  18. $AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" `
  19. -Filter "LocalAccount='$True'" -ComputerName $Computer -Credential $Credential -ErrorAction Stop
  20. }
  21. else
  22. {
  23. $AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" `
  24. -Filter "LocalAccount='$True'" -ComputerName $Computer -ErrorAction Stop
  25. }
  26.  
  27. Foreach($LocalAccount in $AllLocalAccounts)
  28. {
  29. $Object = New-Object -TypeName PSObject
  30.  
  31. $Object|Add-Member -MemberType NoteProperty -Name "Name" -Value $LocalAccount.Name
  32. $Object|Add-Member -MemberType NoteProperty -Name "Full Name" -Value $LocalAccount.FullName
  33. $Object|Add-Member -MemberType NoteProperty -Name "Caption" -Value $LocalAccount.Caption
  34. $Object|Add-Member -MemberType NoteProperty -Name "Disabled" -Value $LocalAccount.Disabled
  35. $Object|Add-Member -MemberType NoteProperty -Name "Status" -Value $LocalAccount.Status
  36. $Object|Add-Member -MemberType NoteProperty -Name "LockOut" -Value $LocalAccount.LockOut
  37. $Object|Add-Member -MemberType NoteProperty -Name "Password Changeable" -Value $LocalAccount.PasswordChangeable
  38. $Object|Add-Member -MemberType NoteProperty -Name "Password Expires" -Value $LocalAccount.PasswordExpires
  39. $Object|Add-Member -MemberType NoteProperty -Name "Password Required" -Value $LocalAccount.PasswordRequired
  40. $Object|Add-Member -MemberType NoteProperty -Name "SID" -Value $LocalAccount.SID
  41. $Object|Add-Member -MemberType NoteProperty -Name "SID Type" -Value $LocalAccount.SIDType
  42. $Object|Add-Member -MemberType NoteProperty -Name "Account Type" -Value $LocalAccount.AccountType
  43. $Object|Add-Member -MemberType NoteProperty -Name "Domain" -Value $LocalAccount.Domain
  44. $Object|Add-Member -MemberType NoteProperty -Name "Description" -Value $LocalAccount.Description
  45.  
  46. $Obj+=$Object
  47. }
  48.  
  49. If($AccountName)
  50. {
  51. Foreach($Account in $AccountName)
  52. {
  53. $Obj|Where-Object{$_.Name -like "$Account"}
  54. }
  55. }
  56. else
  57. {
  58. $Obj
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement