1 |
Get-WmiObject win32_service -computer gdc-slo-p-slg01 |select-object @{Label="Server Name"; Expression={$_.__SERVER}}, Name , Startname |ConvertTo-HTML | Out-File "C:\test.htm" |
Get Services on remote computer and save to file
1 2 3 4 |
foreach ($computer in $computerlist ) { Write-Host $computer +" - Admin list" (Get-LocalGroupMembers $computer).members } |
Loads a list of computes and looks who is in the admin group
* get-localGroupMembers is a function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<span class="powerShell__keyword">function</span> Get<span class="powerShell__operator">-</span>LocalGroupMembers { <span class="powerShell__keyword">param</span>( [parameter(Mandatory=<span class="powerShell__variable">$true</span>,ValueFromPipeline=<span class="powerShell__variable">$true</span>,ValueFromPipelineByPropertyName=<span class="powerShell__variable">$true</span>)] [Alias(<span class="powerShell__string">"Name"</span>)] [string]<span class="powerShell__variable">$ComputerName</span>, [string]<span class="powerShell__variable">$GroupName</span> = <span class="powerShell__string">"Administrators"</span> ) <span class="powerShell__keyword">begin</span> {} <span class="powerShell__keyword">process</span> { <span class="powerShell__com"># If the account name of the computer object was passed in, it will </span> <span class="powerShell__com"># end with a $. Get rid of it so it doesn't screw up the WMI query. </span> <span class="powerShell__variable">$ComputerName</span> = <span class="powerShell__variable">$ComputerName</span>.Replace(<span class="powerShell__string">"`$"</span>, <span class="powerShell__string">''</span>) <span class="powerShell__com"># Initialize an array to hold the results of our query. </span> <span class="powerShell__variable">$arr</span> = @() <span class="powerShell__com"># Get hostname of remote system. $computername could reference cluster/alias name. Need real hostname for subsequent WMI query.</span> <span class="powerShell__variable">$hostname</span> = (<span class="powerShell__cmdlets">Get-WmiObject</span> <span class="powerShell__operator">-</span>ComputerName <span class="powerShell__variable">$ComputerName</span> <span class="powerShell__operator">-</span>Class Win32_ComputerSystem).Name <span class="powerShell__variable">$wmi</span> = <span class="powerShell__cmdlets">Get-WmiObject</span> <span class="powerShell__operator">-</span>ComputerName <span class="powerShell__variable">$ComputerName</span> <span class="powerShell__operator">-</span>Query <span class="powerShell__string">"SELECT * FROM Win32_GroupUser WHERE GroupComponent=`"</span>Win32_Group.Domain=<span class="powerShell__string">'$Hostname'</span>,Name=<span class="powerShell__string">'$GroupName'</span>`<span class="powerShell__string">""</span> <span class="powerShell__com"># Parse out the username from each result and append it to the array. </span> <span class="powerShell__keyword">if</span> (<span class="powerShell__variable">$wmi</span> <span class="powerShell__operator">-</span>ne <span class="powerShell__variable">$null</span>) { <span class="powerShell__keyword">foreach</span> (<span class="powerShell__variable">$item</span> <span class="powerShell__keyword">in</span> <span class="powerShell__variable">$wmi</span>) { <span class="powerShell__variable">$data</span> = <span class="powerShell__variable">$item</span>.PartComponent <span class="powerShell__operator">-</span>split <span class="powerShell__string">"\,"</span> <span class="powerShell__variable">$domain</span> = (<span class="powerShell__variable">$data</span>[0] <span class="powerShell__operator">-</span>split <span class="powerShell__string">"="</span>)[1] <span class="powerShell__variable">$name</span> = (<span class="powerShell__variable">$data</span>[1] <span class="powerShell__operator">-</span>split <span class="powerShell__string">"="</span>)[1] <span class="powerShell__variable">$arr</span> <span class="powerShell__operator">+</span>= (<span class="powerShell__string">"$domain\$name"</span>).Replace(<span class="powerShell__string">""</span><span class="powerShell__string">""</span>,<span class="powerShell__string">""</span>) [Array]::<span class="powerShell__alias">Sort</span>(<span class="powerShell__variable">$arr</span>) } } <span class="powerShell__variable">$hash</span> = @{ComputerName=<span class="powerShell__variable">$ComputerName</span>;Members=<span class="powerShell__variable">$arr</span>} <span class="powerShell__keyword">return</span> <span class="powerShell__variable">$hash</span> } <span class="powerShell__keyword">end</span>{} } |
Found Here
https://gallery.technet.microsoft.com/scriptcenter/List-local-group-members-c25dbcc4