When I right-click on folder or white-space inside folder, I want to have a menu option that will launch PowerShell in that location, then I want to run a function/alias which will perform the job of flattening the directory and overwrite if file with same name exists.
Update: Using get-help cmdlet on powershell, I managed to hack this command that flattens the working directory and overwrites if file exists.
gci -r -file | move -force -destination $PWD
Update:
I added "Open with PowerShell" to context-menu by regedit
[HKEY_CLASSES_ROOT\Directory\Background\shell\Open with PowerShell]
[HKEY_CLASSES_ROOT\Directory\Background\shell\Open with PowerShell\command]
@="powershell.exe -noexit -command Set-Location '%V'"
[HKEY_CLASSES_ROOT\Directory\shell\Open with PowerShell]
[HKEY_CLASSES_ROOT\Directory\shell\Open with PowerShell\command]
@="powershell.exe -noexit -command Set-Location '%V'"
then adding a function
was similar to many other languages:
function flatten { gci -r -file | move -force -destination $PWD }
But I can't seem to get this to automatically load when I open powershell. In bash, I would put this in .bashrc
or .profile
and it would be loaded.
I added profile.ps1
file with the function
in $pshome
, now I get this error:
. : File C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 cannot be loaded because running scripts is disabled
on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3
+ . 'C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Not sure if changing security setting is the only way around this.
How do I allow loading script/alias as safe as possible?
Update:
Changing command to entry below in regedit
loads the function I need:
powershell.exe -noexit -command Set-Location '%V'; function flatten { gci -r -file | move -destination $PWD -force }
This is a workaround. I'm still interested in knowing how to load a profile without making risky changes to OS security.