There is only a limited amount of time during your day. Things get busy, and you fall behind in your work. I am always looking for tools to boost productivity on Windows. One way of doing this is to use PowerShell to speed up my workflow. Several scripts can be run in the CLI to automate tasks, so you don’t need to work through the GUI and can focus on more important matters.
Plus, since PowerShell is an open-source CLI, you can run it on platforms other than Windows. Many commands and scripts will work on Windows, Mac, and Linux systems. Any time you want to speed up your workflow, using the CLI will be faster than navigating the GUI. With scripts, you can also tweak them and build upon them to improve how it functions on your specific system.
This PowerShell script is essential for any fresh Windows install
Save precious time setting up your new system with this simple PowerShell script
6 Move Files and folders
Copy files and folders and delete them from the source to save space
Moving files and folders from one location to another is typically faster using the CLI. File Explorer can be clunky, and once items are copied over, you need to go back to the source directory to delete them to save space. The Move-item cmdlet automates the process. It copies files and folders to a new directory and automatically deletes the ones in the source directory. This is the basic idea of getting started by moving one file.
Move-Item -Path “C:\source path” -Destination “D:\destination path”
For instance, to move and delete an image file from the destination, you use something similar to the following, but replace the source and destination path accordingly.
Tired of dealing with Windows updates? Here's how to automate them with PowerShell
Make your life easier
5 View users and account types
The easy way to see all user accounts
If you are the administrator of a shared Windows 11 PC, your workflow might involve managing users and accounts on it. A simple cmdlet will show you all users with an account and their type. This saves you time by not having to navigate through the Settings app or going through Lusrmgr to view them. Just use the following.
Get-LocalUser
That simply generates a list of users and a description of their accounts. If you want to step things up a notch and generate a report of current and disabled users, users who haven’t logged into the system in the past 30 days, users with passwords that never expire and more, you can run the following.
# Get all local users
Write-Host "All local users:" -ForegroundColor Cyan
Get-LocalUser | Format-Table Name, Enabled, LastLogon
# Get a specific user by name
$specificUser = "Administrator"
Write-Host "`nDetails for user '$specificUser':" -ForegroundColor Cyan
Get-LocalUser -Name $specificUser | Format-List Name, FullName, Enabled, LastLogon, PasswordLastSet, PasswordExpires
# Get disabled users
Write-Host "`nDisabled users:" -ForegroundColor Cyan
Get-LocalUser | Where-Object { -not $_.Enabled } | Format-Table Name, LastLogon
# Get users who haven't logged in for the last 30 days
$thirtyDaysAgo = (Get-Date).AddDays(-30)
Write-Host "`nUsers who haven't logged in for 30 days:" -ForegroundColor Cyan
Get-LocalUser | Where-Object { $_.LastLogon -lt $thirtyDaysAgo -and $_.Enabled } | Format-Table Name, LastLogon
# Get users with passwords that never expire
Write-Host "`nUsers with passwords that never expire:" -ForegroundColor Cyan
Get-LocalUser | Where-Object { $_.PasswordExpires -eq $null } | Format-Table Name, PasswordLastSet
# Export all user information to CSV
$csvPath = "$env:USERPROFILE\Desktop\LocalUsers.csv"
Get-LocalUser | Select-Object Name, Enabled, LastLogon, PasswordLastSet, PasswordExpires |
Export-Csv -Path $csvPath -NoTypeInformation
Write-Host "`nLocal user information exported to: $csvPath" -ForegroundColor Green
Once you know what you're dealing with, you can manage the account privileges and delete old ones that are no longer needed. In addition, this will save space on your drive, so you have room for your real work. Of course, you can change the parameters to suit your needs and have the CSV report saved to a location that works best for you.
5 reasons you should use PowerShell even if you don’t use Windows
PowerShell can be used in a mulitude of ways outside of Windows.
4 Reinstall the Microsoft Store
When you need apps, but the Store isn’t working
Installing apps from the Store is beneficial in many ways, including trust, functionality, and security. However, sometimes, you might be in a situation where you need to install an app from the Microsoft Store, but it isn’t working. Perhaps it became corrupt, or apps simply don’t download. Or, maybe you need an app feature update that gets stuck.
Whatever the reason, you don’t have time to troubleshoot or reinstall the Store from the Settings app. Reinstalling it from PowerShell is far more effective and typically resolves the problem. You can reinstall it with two basic scripts. Open PowerShell as Admin and run the following two scripts in order. The first completely uninstalls the Store, and the second reinstalls it to its full functioning glory.
Get-AppxPackage -allusers *WindowsStore* | Remove-AppxPackage
Get-AppxPackage -AllUsers Microsoft.WindowsStore* | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
Once you run the scripts, the store will be installed in its original state and whatever issues you have been having should be resolved. This will speed your workflow since you don’t have to take time troubleshooting what the problem might be.
11 PowerShell modules you should try out on your Windows 11 PC
Take PowerShell's functionality to the next level with these amazing modules
3 Automate disk space monitoring
Know when your disk space reaches a certain level
While it is important to keep your local disk as clear as possible for data by enabling Storage Sense or using the legacy Disk Cleanup utility, it is also helpful to know when your drive reaches a certain amount of space left. This PowerShell script allows you to get an alert when the drive reaches a set amount of space. Using this method lets you plow through your workflow without wasting time on drive maintenance. Open PowerShell as Admin and run the following.
$threshold = 10GB
$drives = Get-PSDrive -PSProvider FileSystem
foreach ($drive in $drives) {
if ($drive.Free -lt $threshold) {
Send-MailMessage -To "admin@domain.com" -From "monitor@domain.com" -Subject "Disc Space Alert" -Body "Drive $($drive.Name) is running low on space." -SmtpServer "smtp.domain.com"
}
}
Windows will monitor your drive and email you alerts when it reaches the amount of space you specified. So, add your own email address to the script and change the disk space threshold if you want.
6 reasons PowerShell is one of the best built-in applications on Windows
If you only use CMD as your CLI, check out why PowerShell is a phenomenal built-in utility on Windows 11.
2 Update apps
Get app package updates from all sources
When you need new features in certain apps, you can wait for them to update in the background, or automate the process through all repositories, including the Microsoft Store, Chocolaty, and Windows Package Manager (winget) if installed. This script will check for updates from all sources and if one of them, like winget, isn’t installed, it will skip it. Run the following script in PowerShell as administrator.
# Automated App Update Script for Windows
# Function to update Windows Store apps
function Update-WindowsStoreApps {
Write-Host "Updating Windows Store apps..."
Get-CimInstance -Namespace "Root\cimv2\mdm\dmmap" -ClassName "MDM_EnterpriseModernAppManagement_AppManagement01" |
Invoke-CimMethod -MethodName UpdateScanMethod
}
# Function to update Chocolatey packages
function Update-ChocolateyApps {
if (Get-Command choco -ErrorAction SilentlyContinue) {
Write-Host "Updating Chocolatey packages..."
choco upgrade all -y
} else {
Write-Host "Chocolatey is not installed. Skipping Chocolatey updates."
}
}
# Function to update Winget packages
function Update-WingetApps {
if (Get-Command winget -ErrorAction SilentlyContinue) {
Write-Host "Updating Winget packages..."
winget upgrade --all
} else {
Write-Host "Winget is not installed. Skipping Winget updates."
}
}
# Main execution
Write-Host "Starting automated app updates..."
Update-WindowsStoreApps
Update-ChocolateyApps
Update-WingetApps
Write-Host "App update process completed."
Note that you may need to restart your system to finish certain package installations. You will get a notification once the script installs updates to let you know. To truly automate the script, copy the code into Notepad and save it as AppUpdates.ps1 and create a new task in Task Scheduler to run it weekly or monthly. In fact, you can automate all scripts by saving them as a .ps1 file and setting them to run on a schedule using Task Scheduler.
PowerShell vs Windows PowerShell: How are they different?
Microsoft's scripting tooling has changed
1 Generate running services CSV Report
Looking through Task Manager and services.msc is inefficient
When you are deep into your workflow and your system starts to slow down, it’s annoying. Looking for a resource-hogging app or service in Task Manager is a good start. However, if you need to go deeper, you may want to generate a CSV report of running system services. This is also helpful if your workflow is system troubleshooting and maintenance. You can create the CSV by running the following script. It will list all running services and be available on your local drive.
# List all running services and export to CSV
Get-Service | Where-Object {$_.Status -eq "Running"} |
Export-Csv -Path "C:\RunningServices.csv" -NoTypeInformation
3 of the biggest differences between Command Prompt and PowerShell
PowerShell has taken over CMD in the last decade, but how do they differ?
Running PowerShell scripts saves you time
As you can see, running just one or two of the PowerShell scripts above will save you time while getting things done. The number of commands and scripts you can run in PowerShell for various tasks is virtually endless. Any scripts you run can be customized to be tailored to specific tasks and systems. When you run a script or command in PowerShell, the task is typically always going to be faster than using GUI-based tools and speed up your workflow. These are just a few examples of scripts you can run that will speed up various tasks you need to complete while running Windows.
PowerShell
For more ideas and script examples, you can check out the collection of PowerShell scripts on GitHub, which includes over 500 free scripts for PowerShell on Windows, macOS, and Linux. Keep in mind that you want the PowerShell app and not Windows PowerShell when working between platforms.
