Good morning all!
I've been messing around with the switch statement since I found out about it on another post I made.
I have this issue with the code below, where its printing multiple rows with the same information and, I get why its doing so but, I dont know how to fix it. I believe its messing up when im assigning the variable but, im not too sure. Can someone point me in the right direction on what may be causing the issue? Any help is appreciated.
$gc = Get-ChildItem -Path 'C:\users\abrah\OneDrive\Desktop'
Foreach ($File in $gc) {
switch -Wildcard ($file) {
"deskt*" { $Desk = "This is the location: $($File.FullName)" }
"*v*" { $VA = "This is the location: $($File.FullName)" }
}
$VCount = $va | Measure-Object | Select-Object -ExpandProperty Count
$Dcount = $Desk | Measure-Object | Select-Object -ExpandProperty Count
$PS = [pscustomobject]@{
DesktopLocation = $Desk
DCount = $Dcount
VLocation = $VA
VCount = $VCount
}
$PS
}
About the script: Im just looking to find any files on my desktop that begin with deskt, and any with the letter V in it. Then im throwing it into a custom object while attempting to count how many files contain those key letters.
Here are the results btw: