troubleshooting Question

Run a powershell script asynchronously

Avatar of Can
Can asked on
3 Comments1 Solution57 ViewsLast Modified:
Hi All,

I got a powershell script to export all local admin accounts from ad computers to a CSV:

$servers= Get-Content -Path 'C:\Localdata\ADcomputers.csv'
$output = 'C:\localdata\PRODadmin.csv' 

$servers | ForEach-Object {
	$server = $_
	Write-Host "Processing $($server)"
	$group = [ADSI]"WinNT://$($server)/Administrators" 
	$group.psbase.Invoke('Members') | ForEach-Object {
		New-Object PSObject -Property ([ordered]@{
			Server = $server
			Admin = $_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null)
} |
	Where-Object {$_.Admin -notmatch '^(L RG.*|Locbeh|Domain Admins|Enterprise Admins|Administrator|G RB.*|SA_.*)$'} |
	Export-csv $Output -NoTypeInformation

Yet this is taking a very long time since its running the script synchronously. Is there a way to edit the script so it runs asynchronous?

Thanks in advance.
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros