I’m trying to delete folders from multiple Backup servers remotely. Folder name represents server name itself. Executing below script is providing Access denied error though I’m admin on the server. Folders also have needed permissions.
Could someone please help where I’m going wrong?
If Backup Server names are Backup1, Backup2 etc, Folder names are Server1, Server2 which exists either in Backup1 or Backup2 Servers
Script
$BackupServers = Get-Content ‘C:\Scripts\BackupServers.txt’ # Backup Servers are the servers where folders exists $Servers = Get-Content ‘C:\Scripts\Serverlist.txt’ # contains folder names which are nothing but server names
Should work. I just ran a simple test using this with no issues:
remove-item -Path '\server\c$\temp\folder'
Are you certain you have permissions?
Without knowing the contents of your CSV files, this is difficult to figure. For example, in your for loop, you are enumerating $servers and also using that in your remove-item instead of $server.
I’m admin on the servers as well as on the servers trying to delete folder.
The contents in .txt file are below servernames.
Server1
Server2
Server3
Contents in Backup text file is below Backup file server names.
BackupServer1
BackupServer2
BackupServer3
I’m trying to find Server1 in any of Backupservers (Backup servers 1,2,3 because folder with servername will exists in any of these servers) and then when found, delete it.