First post in Stack Overflow so bear with me...
I update my profile to create/adjust custom functions as I complete my day-day work. After saving the edits to my profile, the new/updated function isn't working according to the new profile after running & $profile
in my current PowerShell session. It only works after closing my current session and reopening a new PowerShell instance. I am using PowerShell 7.3.5 and Windows Terminal.
For example....
In my profile I have a few custom functions to open the last X number of files downloaded to my Downloads folder. Running this command open_dnld
with no input will start the last file in this folder. Running this command with an input of 2 open_dnld(2)
starts the process for my last 2 files. Below is the function definition:
Old Function:
Function open_dnld ([Int16] $NumFiles = 1) {foreach($file in Get-ChildItem ~/Downloads
| Sort-Object LastWriteTime -Descending
| Select-Object -First $NumFiles){
Start-Process $file
}
}
For a test, I just updated the function with $NumFiles having a default value of 2 shown below. After running & $profile
and thereafter open_dnld(2)
the function works according to the previous definition and only opens 1 file. But, when I close my current terminal session, open a new instance of PowerShell using Windows Terminal, and then run the command open_dnld(2)
the function now works according to the new function definition.
Updated Function:
Function open_dnld ([Int16] $NumFiles = 2) {foreach($file in Get-ChildItem ~/Downloads
| Sort-Object LastWriteTime -Descending
| Select-Object -First $NumFiles){
Start-Process $file
}
}
Any idea on what I am doing wrong?