Powershell Deleting Files and Folders

Powershell Deleting Files and Folders Here is a quick list of very useful File and Folder Deletion operation command-lets. Completely delete a folder along with files and sub-folders in it forcefully: Remove-Item “C:TempFldr” -Force -Recurse -ErrorAction SilentlyContinue   Completely delete a files and sub-folder under the folder but retain the folder. Remove-Item “C:TempFldr*” -Force -Recurse -ErrorAction SilentlyContinue   Delete only the files under the folder but not sub-folders and files in it. Remove-Item “C:TempFldr*.*” -Force -Recurse -ErrorAction SilentlyContinue   Delete ONLY files recursively under the folder and sub-folders while retaining the folder structure. forfiles /p C:temp-new /s /c “cmd /c […]

Read more

PS: Script to Save Share Permissions to a Text File

Specifications: It creates the log file afresh for every run Inserts two new lines after every folder ACLs output Uses Get-ACL Supports paths with spaces Script: $permsLogFile = "C:tempshare-permissions.txt" Write-Output "Start of the script" > $permsLogFile $networkPath = \<servername><sharename>" $subFolders = Get-ChildItem -Name $networkPath foreach ($Folder in $subFolders){ $cmd = ‘Get-Acl "’ + "$networkPath$Folder" + ‘"’ Write-Output "`r`n`r`nRunning Commamnd: $cmd" >> $permsLogFile Invoke-Expression $cmd | Write-Output >> $permsLogFile }   Output: Start of the script Running Commamnd: Get-Acl "\myserverusersFolder With Spaces" Directory: \myserverusers Path             Owner             Access            —-             —–             ——            Folder With Spaces          BUILTINAdministrators         NT AUTHORITYSYSTEM Allow FullControl…    Running Commamnd: Get-Acl […]

Read more