📎 AI Summary:
The thread discusses how to recursively delete files with specific extensions (.PRG and .P00) on a Windows partition. The original poster seeks a way to execute PowerShell scripts directly from context menu or batch files without manually opening PowerShell. The expert suggests using `powershell.exe -command` within batch files and provides guidance on embedding PowerShell commands into BAT or CMD scripts, concluding that the same method applies consistently.

MIRKOSOFT

Active Member
Joined
Sep 26, 2019
Messages
60
Thread Author #1
Hello!

I need to recursively to remove all extensions PRG and P00 on single partition.
I know that recursively can work XCOPY, but renaming is other task.
How to create batch to remove all these extensions of files and folders (if exist) recursively?

Thank you for each help, suggestion or reply and comments.
Miro
 

MIRKOSOFT

Active Member
Joined
Sep 26, 2019
Messages
60
Thread Author #3
Great!
Only last Q - how to execute PowerShell script by command without opening PS console?

Thank you very much.
Miro
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
You need to make sure your execution policy will allow powershell scripts Set-ExecutionPolicy -Scope MachinePolicy -ExecutionPolicy RemoteSigned then you should be able to just run a script by right clicking it and say "Run with Powershell"
 

MIRKOSOFT

Active Member
Joined
Sep 26, 2019
Messages
60
Thread Author #5
Policy I know that needs to allow.
I mean not execution by right click from menu.
Really command which can be used as submenu in context menu directly starting script, like BAT or CMD has batches - similar way.
Anything like
\CLASSES_ROOT\*\SHELL\Remove Extensions\command\(Default)...
...execute.bat "%1"
and so on...

Miro
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
You can run the command above from a context menu item
 

MIRKOSOFT

Active Member
Joined
Sep 26, 2019
Messages
60
Thread Author #7
Ok, tested, works.
How to embed PowerShell commands into BAT or CMD?
This is last Q.
Miro
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
You don't need to. Just call powershell.exe -command " & { <command> }"
 

Solution

MIRKOSOFT

Active Member
Joined
Sep 26, 2019
Messages
60
Thread Author #9
Ok, finally - how to create PowerShell batch or embed PS batch (lines with PS code) into BAT or CMD?

Thank you for both answers.
Miro
 

MIRKOSOFT

Active Member
Joined
Sep 26, 2019
Messages
60
Thread Author #11
Ok, how to embed whole script - this code:

Code:
$FilePath = $args[0]

$Filename = Split-Path -Path $FilePath -Leaf
$Content = Get-Content -Path "$FilePath" | Out-String
$MeasuredData = Measure-Object -InputObject $Content -Line -Word -Character

$FormattedOutput = "Extension $($FileName): Words: $($MeasuredData.Words) Lines: $($MeasuredData.Lines) Chars: $($MeasuredData.Characters)"

[System.Windows.Forms.MessageBox]::Show($FormattedOutput)