How to add local groups to local user account PS script


hello, powershell 3.0 novice , want add feature first ever production script tool.

the script below local user accounts remote computers listed in a .txt file export .csv format.  how can incorporate local groups each local user account member of?  each local user account retrieved want list local groups member of.

get-ciminstance -classname win32_useraccount -filter “localaccount=’true’” -computername (get-content c:\ps\<listofcomputers>.txt) | export-csv c:\ps\<name>_localuseraccounts.csv (export .csv)

your insight appreciated,

matt, ps 3.0 novice


matt

hi matt,

give try:

get-content .\computerstocheck.txt | foreach {      $adsi = [adsi]"winnt://$_"     $adsi.children | {$_.schemaclassname -eq 'user'} | foreach-object {         $groups = $_.groups() | foreach-object {$_.gettype().invokemember("name", 'getproperty', $null, $_, $null)}         $_ | select-object @{n='computername';e={$adsi.name}},@{n='username';e={$_.name}},@{n='groups';e={$groups -join ';'}}     } } | export-csv -notypeinformation .\localuserslocalgroups.csv


create text file named computerstocheck.txt in same directory script 1 name per line.

edit: added in export-csv.

edit2: here's link started from:

http://stackoverflow.com/questions/4548476/powershell-list-local-users-and-their-groups





Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS