In: Computer Science
Windows PowerShell Scripting
Please answer using a switch statement. I have asked this question already and it was wrong. Thank you and I will upvote.
1) Write a PowerShell script that displays the total count of each type (dll, txt, log) of files in c:\windows using switch statement.
I have used switch statement and executed all the 3 queries at once. If you want to execute only one or two, you can specify that in switch and give only a single value or two. Please comment if you need any modifications and I'll help you.
$Dir = get-childitem C:\windows # goes to windows directory
$dllList = $Dir | where {$_.extension -eq ".dll"} #get names of all files which has .dll extension
$txtList = $Dir | where {$_.extension -eq ".txt"} #get names of all files which has .txt extension
$logList = $Dir | where {$_.extension -eq ".log"} #get names of all files which has .log extension
switch (1,2,3)
{
1 {Write-Host "Number of dll files" $dllList.Count}
2 {Write-Host "Number of txt files"$txtList.Count}
3 {Write-Host "Number of log files"$logList.Count}
}
If you have any doubts, leave a comment below and I'll help you out.