PowerShell script run fine on desktop but fail to run on laptop


PhilB

Well-known member
Power User
VIP
Local time
9:28 PM
Posts
903
Location
Western USA
OS
Windows 11 2H25
Before I post a screenshot of Powershell on the laptop, let me not that both systems are running the latest version of Windows, both running PS 7.5.3 and I'm running with the same username on both systems. I use Goodsync to ensure that directories and files are sync'ed between systems. I get the same error message when I try to to run the script starting with CH. My bold.

Here is the PowerShell screenshot


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 9/28/2025 2:46 PM 5098 CHcountallfiles.ps1
-a---- 9/24/2025 9:38 PM 13525 CLcountallfiles.ps1
-a---- 8/15/2025 9:36 PM 1723 printoutallRAWandJPGcounts.ps1


PS F:\scripts\test\photo\filecountsperfolder> ..\CLcountallfiles.ps1
..\CLcountallfiles.ps1 : The term '..\CLcountallfiles.ps1' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:1
+ ..\CLcountallfiles.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (..\CLcountallfiles.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
 

My Computer My Computer

At a glance

Windows 11 2H25AMD 9900X64 GBAMD 9070 XT
OS
Windows 11 2H25
Computer type
PC/Desktop
Manufacturer/Model
DIY
CPU
AMD 9900X
Motherboard
MSI X870E Carbon
Memory
64 GB
Graphics Card(s)
AMD 9070 XT
Sound Card
built-in
Monitor(s) Displays
Dell 24"
Hard Drives
Sabrent 1 TB NVMe, 4 x SSD (need to check models), 4 x 3.5" HDD, 8-16 TB, all WD
PSU
Seasonic 850
Case
Fractal Design North XL (which I likw)
Cooling
Corsair AIO for CPU, fans for case
Keyboard
Das Keyboard 4
Mouse
Corsair M65 (white)
Internet Speed
1 TB download
Browser
Firefox
Antivirus
Bitdefender
Other Info
Also have Lenovo T14S laptop (me) and Lenovo Slim 71 (wife)
One dot is generally used.

.\CHcountallfiles.ps1

And that's assuming you're in the same directory in which the script is saved.
 
Last edited:

My Computer My Computer

At a glance

Windows 11 Enterprise 25H2
OS
Windows 11 Enterprise 25H2
.\ means "the current folder' (or F:\scripts\test\photo\filecountsperfolder)
..\ means "the parent folder above the current folder" (or F:\scripts\test\photo)
 
Last edited:

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
.\ means "the current folder' (or F:\scripts\test\photo\filecountsperfolder)
..\ means "the parent folder above the current folder" (or F:\scripts\test\photo)
I am so embarrassed. What a noob error, which I not.

Moderators: Please don't cancel my account because of this rookie error.
 

My Computer My Computer

At a glance

Windows 11 2H25AMD 9900X64 GBAMD 9070 XT
OS
Windows 11 2H25
Computer type
PC/Desktop
Manufacturer/Model
DIY
CPU
AMD 9900X
Motherboard
MSI X870E Carbon
Memory
64 GB
Graphics Card(s)
AMD 9070 XT
Sound Card
built-in
Monitor(s) Displays
Dell 24"
Hard Drives
Sabrent 1 TB NVMe, 4 x SSD (need to check models), 4 x 3.5" HDD, 8-16 TB, all WD
PSU
Seasonic 850
Case
Fractal Design North XL (which I likw)
Cooling
Corsair AIO for CPU, fans for case
Keyboard
Das Keyboard 4
Mouse
Corsair M65 (white)
Internet Speed
1 TB download
Browser
Firefox
Antivirus
Bitdefender
Other Info
Also have Lenovo T14S laptop (me) and Lenovo Slim 71 (wife)
At least you understood there needs to be a ".\" combination. A number of PS rookies just type in a plain filename, and don't get why nothing runs.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
Useless info.... Double dots work in the root of a drive, because there's no parent.
Code:
D:\
ps> .\Hello.ps1
Hello, world. 09/28/2025 21:54:41

D:\
ps> ..\Hello.ps1
Hello, world. 09/28/2025 21:54:45
 

My Computer My Computer

At a glance

Windows 11 Enterprise 25H2
OS
Windows 11 Enterprise 25H2
I changed the PS command line to just 1 "." but then I got an error message about scripts being disabled on my laotop. So a Microsoft page said that I needed to enter Set-ExecutionPolicy unrestricted. Once I did that, scripts did run OK.
 
Last edited:

My Computer My Computer

At a glance

Windows 11 2H25AMD 9900X64 GBAMD 9070 XT
OS
Windows 11 2H25
Computer type
PC/Desktop
Manufacturer/Model
DIY
CPU
AMD 9900X
Motherboard
MSI X870E Carbon
Memory
64 GB
Graphics Card(s)
AMD 9070 XT
Sound Card
built-in
Monitor(s) Displays
Dell 24"
Hard Drives
Sabrent 1 TB NVMe, 4 x SSD (need to check models), 4 x 3.5" HDD, 8-16 TB, all WD
PSU
Seasonic 850
Case
Fractal Design North XL (which I likw)
Cooling
Corsair AIO for CPU, fans for case
Keyboard
Das Keyboard 4
Mouse
Corsair M65 (white)
Internet Speed
1 TB download
Browser
Firefox
Antivirus
Bitdefender
Other Info
Also have Lenovo T14S laptop (me) and Lenovo Slim 71 (wife)
At least you understood there needs to be a ".\" combination. A number of PS rookies just type in a plain filename, and don't get why nothing runs.
Sure. but you have to ask. Why was powershell designed that way.
 

My Computer My Computer

At a glance

Windows 11 2H25AMD 9900X64 GBAMD 9070 XT
OS
Windows 11 2H25
Computer type
PC/Desktop
Manufacturer/Model
DIY
CPU
AMD 9900X
Motherboard
MSI X870E Carbon
Memory
64 GB
Graphics Card(s)
AMD 9070 XT
Sound Card
built-in
Monitor(s) Displays
Dell 24"
Hard Drives
Sabrent 1 TB NVMe, 4 x SSD (need to check models), 4 x 3.5" HDD, 8-16 TB, all WD
PSU
Seasonic 850
Case
Fractal Design North XL (which I likw)
Cooling
Corsair AIO for CPU, fans for case
Keyboard
Das Keyboard 4
Mouse
Corsair M65 (white)
Internet Speed
1 TB download
Browser
Firefox
Antivirus
Bitdefender
Other Info
Also have Lenovo T14S laptop (me) and Lenovo Slim 71 (wife)
PowerShell doesn't include the current directory in the search path. If you just type in the name of a script file, it will look in the Path environment variable's paths.* To run a script from the current directory, you have to be explicit about your intent.

Some people will say that it keeps you from running a script in the current directory that may be malicious, but there can be malicious scripts in the path too, so meh.

* Edit: Actually it looks for a cmdlet, function, or alias with that name first, then for a script in the path.
 

My Computer My Computer

At a glance

Windows 11 Enterprise 25H2
OS
Windows 11 Enterprise 25H2
If you type an unknown command in CMD, it will assume you're looking for an executable to run. CMD starts looking for the file in the current folder, and then searching folders in your PATH variable.

For security reasons, PS doesn't want to automatically run scripts in the current folder (unless it was already listed in your $env:PATH variable). You can say it's more strongly typed than CMD on basic script security. It's like having an UAC pop-up, it's there get you into the habit of knowing exactly what's going on and mentally justify why you're doing it.

Or you can blame Jeffrey Snover (father of PowerShell).
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
It does also make it more Unix-like, but since cross-platform PowerShell came much later, I don't know if that was a reason.
 

My Computer My Computer

At a glance

Windows 11 Enterprise 25H2
OS
Windows 11 Enterprise 25H2

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
And in all honesty, enough smart (or bad) people already know the trick to read PS script contents into a buffer, and execute the script block. So code signing isn't such an insurmountable barrier. Sites may mandate it as part of their security policy, but it's just lip service.

It's still useful to check for script integrity.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
Back
Top Bottom