Hey all,
First time posting on these forums. I can usually figure out scripting issues with some google searching, but I am having a hell of a time finding help on this one.
I’m currently attempting to write a PowerShell script that will change all of the folders and sub-folders of a specified parent directory to windows built in Details view. I’d like to do this programmatically so that I don’t have to manually go through every folder and change the view myself. I could simulate key presses to do this, but that seems cumbersome and potentially problematic. Especially because each folder has it’s own set of sub-folder structures. Below is the code that I’ve pieced together through research and trial and error.
$wshell = New-Object -Com WScript.Shell
$WorkingFolder = "C:\Users\Colton\Desktop\Test"
ii $WorkingFolder
start-sleep -m 100
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
[Microsoft.VisualBasic.Interaction]::AppActivate("$WorkingFolder")
Start-Sleep -m 100
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
Start-Sleep -m 100
for ($i = 1; $i -le 100; $i++ ) {
Write-Progress -Activity "Setting all folders to 'Details' view..." -Status "$i% Complete:" -PercentComplete $i
Start-Sleep -Milliseconds 250
Get-ChildItem -Path $WorkingFolder -Recurse | ForEach-Object {
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
[System.Windows.Forms.SendKeys]::SendWait("{F6}")
}
}
I have the F6 key bound to set the view to Details, which works when I use it manually. Currently, the script successfully opens the parent directory that I want it to, but then does nothing more to the folder structure(s). I’ve tried to debug it with tracing enabled but haven’t had much luck.
Any help with this would be greatly appreciated. This all started when I needed to move all the data on an external HDD to format and re-partition the drive. I’d like to not have to manually reset my view options for every folder should I do this again in the future.