Networknet.nl Blog

Stay Connected

PowerShell: How to delete a file based on a list of computers?

without comments

image[1]The following PowerShell script recipe will help you delete a remote file based on a list of computers stored in a text file. New PowerShell function will be created during the session which will be piped from the text file.

 

 

 

Generate C:\Scripts\Active_Computers.txt with computer names.

[PowerShell]
function delete-remotefile {
    PROCESS {
                $file = "\\$_\c$\install.exe"
                if (test-path $file)
                {
                echo "$_ install.exe exists"
                Remove-Item $file -force
                echo "$_ install.exe file deleted"
                }
            }
}

Get-Content  C:\Scripts\Active_Computers.txt | delete-remotefile
[/PowerShell]

Written by Ivan

January 31st, 2010 at 11:50 am

Posted in PowerShell

Tagged with , , , ,

Leave a Reply