Forum Discussion
fhoext
Nov 24, 2023Copper Contributor
update powershell - script doesn't work anymore
Dear coll,
HELP ME!
I am a dummy powershell user; please, don't feed me with 10 line of code.
I have a simple script, replacing some text in a coda file; I made it with notepad++
It runs for years, but this week I updated to powershell7 and notepad++
and trouble started.
If I run the script as usual (with powershell) I get a powershell popup, very briefly (some red text) and that's it.
I checked all from every side, but I can not find any errors.
Enclosed, I sent the first 3 lines of the script.
Get-ChildItem 'C:\Users\skidc\Downloads\CODA\*.*' -Recurse | ForEach {
(Get-Content $_ | ForEach { $_ -replace '00403278488', '00463026629' }) |
Set-Content $_}
Get-ChildItem 'C:\Users\skidc\Downloads\CODA\*.*' -Recurse | ForEach {
(Get-Content $_ | ForEach { $_ -replace 'BE24733054476038 GBP', 'BE24733054476038GBP GBP' }) |
Set-Content $_}
Get-ChildItem 'C:\Users\skidc\Downloads\CODA\*.*' -Recurse | ForEach {
(Get-Content $_ | ForEach { $_ -replace 'BE86731028224850 GBP', 'BE86731028224850GBP GBP' }) |
Set-Content $_}
You could capture the error with an extra line at the top with Start-Transcript c:\temp\log.txt and a Stop-Transcript at the end. Run the script, and check the c:\temp\log.txt afterward...
- fhoextCopper ContributorDear,
I got a hint from IT support. It looks like Microsoft has blocked standard all script :
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): a
Supplies !
let's try this one and see what happens.- Suppose you run a script like "pwsh,exe c:\scripts\script.ps1". That could be the case. You could add the -ExecutionPolicy bypass parameter, which would be "pwsh,exe c:\scripts\script.ps1 -ExecutionPolicy bypass" If you run it in a Terminal window, just use "Set-ExecutionPolicy Bypass" or Unrestricted.
You could get this warning:
"Set-ExecutionPolicy: PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will retain its current effective execution policy of Bypass. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information please see "Get-Help Set-ExecutionPolicy".
That means that there is a policy configured for you system...