OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Doing a remote delete using powershell and seeing the results of the operation (success/fail+exception)

  • Thread starter Thread starter Menelaos
  • Start date Start date
M

Menelaos

Guest
The below command is using

Code:
$results = Invoke-Command -ComputerName $remoteComputers -ScriptBlock{
     (get-childitem "C:\tmp" | where-object {$_.Name -like "*MATCHINGfiles*"} | foreach ($_) {remove-item $_.fullname})
        }

$remoteComputers contains a list of computer names

The command works but there is no diagnostic information about which files were deleted, what went well, and what didn't.

(I'm adding this question as it seems quite useful and I had to write a script for it).
<p>The below command is using</p>
<pre><code>$results = Invoke-Command -ComputerName $remoteComputers -ScriptBlock{
(get-childitem "C:\tmp" | where-object {$_.Name -like "*MATCHINGfiles*"} | foreach ($_) {remove-item $_.fullname})
}
</code></pre>
<p><code>$remoteComputers</code> contains a list of computer names</p>
<p>The command works but there is no diagnostic information about which files were deleted, what went well, and what didn't.</p>
<p>(I'm adding this question as it seems quite useful and I had to write a script for it).</p>
Continue reading...
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top