fb
Homepage 5 How-to Articles 5 How to Delete Files on Multiple Servers With Powershell | Action1 RMM

How to Delete Files on Multiple Servers With Powershell | Action1 RMM

Manage remote endpoints, deploy software and patches with Action1 cloud RMM solution.

Sign up and use free on up to 50 endpoints with no functionality limits or expiration.



October 5, 2018

PowerShell is an object-oriented software engine and a command-line scripting language that provides IT professionals with greater opportunities to configure the operating systems of the MS Windows family. Simply put, it is a kind of universal administration tool. This article will discuss the basic techniques for writing scripts on PowerShell, allowing you to automate the management of your Windows environment in a simple way.

PowerShell offers both a pure console interface and a full-fledged PowerShell ISE (Integrated Scripting Environment) integrated scripting environment. To launch the command line interface, enter powershell in the Run menu (WinKey + R). PowerShell ISE is launched using the “PowerShell ISE” command in the same menu.

ISE is more preferable, because it provides more opportunities for the developer due to syntax highlighting, code auto-completion function and other features inherent in many “big” IDEs.

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.

 

1. Create New File Named C:\Scripts\Active_Computers.txt

 

Using the keyboard, you should quickly launch “Windows Explorer.” You just need to press the keys Win + E and “Explorer” will be in front of your eyes.

Create new file directory C:\Scripts\ and file named Active_Computers.txt in this folder and populate the computer names.

Step 1 to Delete Files on Multiple Servers Using Powershell Script is to create new file directory

Create new file

 

2. The Next Step – Start Windows PowerShell

 

Click Start, type PowerShell, and then click Windows PowerShell. If Windows 10 is installed on your computer, then perhaps an even faster way to open PowerShell is to right-click on the “Start” button and select the desired menu item (there are two items at once – for easy launch and on behalf of the administrator). The same menu can be accessed by pressing the Win + X keys on the keyboard.

Start Windows PowerShell

 

3. Use This Script to Delete Files

 

In the PowerShell window that appears, enter the following code:

  • 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.

    Use this script

 

4. Also You Can Use This Script to Delete Files

 

You can find another script for deleting files below. The procedure is the same as the previous one.

  • $Computerlist = get-content C:\XXXXXXXX\Servers.txt
  • Foreach ($computer in $Computerlist) {
  • Get–ChildItem –Path \\$computer\c$\XXXXXXX\*.* –Include *.* –Recurse –Force | Remove–Item –Force
  • {

 

Consider using Action1 to delete files remotely if:

 

  • You need to perform an action on multiple computers simultaneously.
  • You have remote employees with computers not connected to your corporate network.

Action1 is a cloud-based platform for patch management, software deployment, remote desktop, software/hardware inventory, endpoint management and endpoint configuration reporting.

Related Articles

How To Delete User Profiles Remotely with PowerShell

When a user logs onto the computer for the first time (not via the network to access shared folders or printers), Windows creates a user profile. Among its contents are the NTUSER.DAT file (user profile settings), user-specific folders (My Documents, Desktop, etc.),...

About Action1 RMM

Action1 RMM is a cloud-based IT solution for remote monitoring and management, patching, and remote support.

Start your free two-week trial of Action1, or use RMM tools for free forever on 50 endpoints with no functionality limitations!



0 Comments

Submit a Comment

Your email address will not be published.

cloud patch management solutions action1

MSP Solution

Centralize endpoint management and boost efficiency of IT service delivery.

automated server patch management action compliance

Patch Management

Identify and deploy missing OS and third-party software updates.

cloud software deployment tools windows

Software Deployment

Distribute software and updates across managed endpoints.

software distribution tools software inventory action1

IT Asset Inventory

Keep a detailed inventory and manage hardware and software assets.

web client remote desktop

Remote Desktop

Support users via seamless remote desktop connection.

web based rdp client

Unattended Access

Provide administrative support and manage remote devices.

automated patch management action1

Endpoint Management

Run PowerShell, custom scripts, reboot computers and restart services.

API integrations action1

RESTful API

Integrate Action1 RMM to your IT ecosystem.

computer inventory tool for compliance

Reports and Alerts

Conduct endpoint security audits with comprehensive reporting.