Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell Script Receiving Errors when Removing All Document Files on Network Share
    primarykey
    data
    text
    <p>I've been receiving errors when running the script. It will access the drive and write the filenames to my log as specified, but will not remove the files on the share drive due to a permissions error. I'm logged in as the Administrator and have re-wrote permissions to the whole drive, but still do not have access.</p> <p>Here is the code:</p> <pre><code>$servers = Get-content "D:\Scripts\servers.txt" $logpath = "d$\Documents" $logFile = "D:\Scripts\log.txt" $Date = Get-Date $error.clear() foreach($server in $servers){ $fail =" $Date - Failed. $server did not respond to a ping command. No files have been deletedfrom $server." $notpresent = "$Date - Failed. The specified log folder doesn't seem to be present on $server." $nologs = "There are no log files to be deleted on $server." $UNCpath = "\\" +$server+ "\" +$logpath #Ping server to validate the server is online and accessible If ($server|?{ (gwmi Win32_PingStatus -Filter "Address='$_'").StatusCode -eq 0 }){ # The server IS pingable, but the folder does not exist. If (!(Test-Path $UNCpath)){Write-output $notpresent `r`n | Out-File $logFile -append} # The server IS pingable, and the folder does exist else{ $files = (dir -r $UNCpath -include *.doc,*.pdf,*.docx,*.xls,*.xlsx | where {$_.lastwritetime -le (get-date).adddays(-90) -and !$_.psiscontainer}) foreach ($file in $files){ If ($file -eq $null){write-output $nologs `r`n | Out-File $logFile -append} Else{ write-output $file.name | Out-File $logFile -append remove-item $file } } } } # The server is NOT pingable. else{Write-output $fail `r`n | Out-File $logFile -append} If ($error.count -ne "0"){write-output $error | Out-File $logfile -append} Else{write-output "The log file removal script has completed successfully." | Out-File $logfile -append}' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload