Go to content|Go to the main menu|Go to search

edhouse-CookieGdpr-Policy-s
1073657
2
/en/gdpr/
107650B6A

Back to Blog

TutorialsSQA

Downloading Folders Using PowerShell

Tech_blog

Many tasks we often perform manually can be automated. This saves time and also reduces the likelihood of errors.

One such task could be downloading the latest build of an application we are testing. In this article, we will look at how to easily (semi-)automatically download folders (not just) from a shared drive using PowerShell.

Imagine this scenario: We have a network drive or shared storage where the latest development versions of an application are automatically stored. If we want to test this version, we have to open Explorer, find the required folder, identify the latest version, and download it to our disk. It’s a simple operation, but it takes some time, and if we need to repeat it multiple times a day, efficiency drops significantly.

To write the script, basic PowerShell knowledge will suffice.

We use Get-ChildItem to get the list of folders:

$directories = Get-ChildItem -Path $sourcePath -Directory | Where-Object { $_.Name -like $folderMask }

Then, we sort the folders using Sort-Object starting with the latest one:

$directories | Sort-Object -Property LastWriteTime -Descending | Select-Object -Last 10

We get a list of folders, from which we will later create a “menu” and add information about the folder's creation date and time, as well as whether the folder has already been downloaded:

$downloadList += [pscustomobject]@{
    Index = $downloadIndex;
    DateTime = $_.LastWriteTime.ToString("yyyy-MM-dd HH:mm");
    Name = $_.Name;
    FullName = $_.FullName;
    IsDownloaded = $isDownloaded;
}
 

Create the menu is done by displaying the list in a table format using Format-Table. Folder number to download is then prompted using Read-Host:

$downloadList | Format-Table -Property Index, DateTime, Name, IsDownloaded -AutoSize
$PROMPT = Read-Host "Select a number of build to download"

You can find the entire script on our GitHub: folder_downloader.ps1.

This simple script is just an example that even straightforward operations are worth automating, and creating them doesn’t have to be complicated. I personally use a similar script several times a day (running them using Sekubu). After downloading, I can also immediately run the application installer.

Share article

Author

Jan Zatloukal

Jan ZatloukalTester and developer with a passion for automation and improving the development process. I am currently working on an electron microscope automation project in Python.

Edhouse newsletter

Get the latest updates from the world of Edhouse – news, events, and current software and hardware trends.

By signing up, you agree to our Privacy Policy.

Thank you! You have successfully subscribed to the newsletter.