Write Shell script to perform operations like display, list, make directory and copy, rename, delete, edit file.
The following command renames a file:
Rename-Item -Path "\\fs\Shared\temp.txt" -NewName "new_temp.txt"
This command to copy files from a remote file server to the local C: directory:
Copy-Item \\fs\c$\temp -Recurse C:\data\
Example of Shell script to Delete files from multiple computers in one script
$filelist = @(" \c$\Temp", "\c$\Backups") #variable to delete files and folder
$computerlist = Get-Content C:\data\pc.txt #get list of remote pc's
foreach ($computer in $computerlist){
foreach ($file in $filelist){
$filepath= Join-Path "\\$computer\" "$filelist" #generate unc paths to files or folders
if (Test-Path $filepath)
{
Remove-Item $filepath -force -recurse -ErrorAction Continue}}}
Comments
Leave a comment