I want to delete all the files under “W3SVC*” folder , from list of servers .
for the import servers I used :
Get-ADComputer -filter * -searchbase “OU=Servers,OU=Apps1,DC=QA,DC=com” | select - ExpandProperty Name | out-file C:\LM.txt
$servers =Get-Content -Path “C:\LM.txt”
for the files deletion I used :
$MyPath=(Get-ChildItem -path d:\ -Filter “W3SVC*” -Recurse -Directory).Fullname
Get-ChildItem -Path $MyPath -Recurse -Force | Where-Object { !$_.PSIsContainer} | Remove-Item -Force
How can I run the 2 last rows only on the servers in “C:\LM.txt”.
(or how can I run the whole thing more efficiently)