Posts tagged remote

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

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]

PowerShell: How to check list of computers for a specific remote file ?

image The following PowerShell script recipe will help you check a remote file based on a list of computers stored in a text file. A new PowerShell function will be created during the session which will be piped from the text file.

In the following PowerShell example I will check if install.exe exists on the remote systems and echo the computername if the file is there.

 

Create new text file named C:\Scripts\Active_Computers.txt and populate the file with computer names.

[PowerShell]

function check-remotefile {

    PROCESS {

                $file = "\\$_\c$\install.exe"

                if (test-path $file)

                {

                echo "$_ file install.exe exists"

                }

            }

}

Get-Content  C:\Scripts\Active_Computers.txt | check-remotefile

[PowerShell]