Quantcast
Channel: Spiceworks Community - Latest topics
Viewing all articles
Browse latest Browse all 182935

Powershell help with correct syntax

$
0
0

First off, I am by no means a powershell scripter. WHat I have currently is just snippets I am piecing together from what I've found online,

I currently have the following code:

$TargetFolder = “C:\test\”
$Deleted = "Deleted Folders.txt"

$Folders = (gci $TargetFolder -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName

foreach ($FullName in $Folders)
{write-output “Deleted Folder $Fullname” >>$Deleted; Remove-Item $FullName -recurse | out-null}

What is happening:

The code tries to delete the folder named @{FullName=C:\test\test1}

(I would assume this is because the output of the $Folders variable. The output is some sort of table not just lines of empty folders)

What I want it to do:

Delete the folder named C:\test\test1

I want the script to recursively delete folders that are empty and then output what folders were deleted into the variable $Deleted.

Possibly have the output of $Folders to not be a table and just output the Full path of empty folders. Would this require another pipe?


Viewing all articles
Browse latest Browse all 182935

Trending Articles