cawasaki
asked on
query computers remotely to find if specific profile folder exist with
hello,
i need from a csv computer list to execute this script to get all profile folder contain X letter
Get-WmiObject -Query "SELECT Name FROM Win32_Directory WHERE Drive = 'C:' AND Path = '\\Users\\' AND Name like '%X%'"
the result must be on a csv file like this:
computername,Name
computer1,c:\users\shfdkjs dXdsqfd
....
if a computer is not on or not respond, the scipt must go to the next computer.
thanks for help
i need from a csv computer list to execute this script to get all profile folder contain X letter
Get-WmiObject -Query "SELECT Name FROM Win32_Directory WHERE Drive = 'C:' AND Path = '\\Users\\' AND Name like '%X%'"
the result must be on a csv file like this:
computername,Name
computer1,c:\users\shfdkjs
....
if a computer is not on or not respond, the scipt must go to the next computer.
thanks for help
ASKER
hello,
the script work, but with certain computer the script stop at processing computer99 and not go to the next one, its possible to put a timer of 5 sec for exemple for every computer?
the script work, but with certain computer the script stop at processing computer99 and not go to the next one, its possible to put a timer of 5 sec for exemple for every computer?
What makes these machines special? I've never had Get-WmiObject just hang there. It might take a while, but Get-WmiObject should always time out.
Is that behavior reliably reproducible for these machines, or is it intermittent?
Is that behavior reliably reproducible for these machines, or is it intermittent?
ASKER
YES i have get the problem with 2 machine and it hang on processing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hello,
same think it hang on processing
same think it hang on processing
ASKER
finally its work TIMEOUT: Not responding! but the timeout is very long
You might want to try it from a different machine, just in case this is an issue with the local machine's WMI, not the remote ones.
ASKER
already test it from other server same think, i have also try it from my computer machine same problem
Can't tell how optimized the Win32_Directory WMI query is - could it be that the machines are just really slow on delivering results?
How about just querying the UNC?
How about just querying the UNC?
$Pattern = '*X*'
Import-Csv -Path C:\Temp\ComputerList.csv | ForEach-Object {
$computerName = $_.ComputerName
Write-Host "Processing $($computerName)"
Try {
If ($Directories = Get-ChildItem -Path "\\$($ComputerName)\C$\Users" -Directory -ErrorAction Stop | Where-Object {$_.Name -like $Pattern}) {
$Directories | Select-Object -Property @{n='ComputerName'; e={$computerName}}, @{n='Name'; e={$_.Name}}, Error
}
} Catch {
$_ | Select-Object -Property @{n='ComputerName'; e={$computerName}}, Name, @{n='Error'; e={$_.Exception.Message}}
}
} | Export-Csv -NoTypeInformation -Path C:\Temp\XUserProfiles.csv
ASKER
this one do the job, thank you
Which one works for you finally ?
Open in new window