PowerShell Help - its gone bezerk.

Discussion in 'Windows 10' started by maxama123, Sep 10, 2020.

  1. maxama123

    maxama123 MDL Senior Member

    Oct 22, 2009
    489
    184
    10
    Hi

    I've performed a clean install last night and try to run sfc /scannow (elevated) and i get the below error. Normal CMD works fine just won't work in PowerShell. Any help would be great as it's a clean install?

    ===========================================================
    PS C:\Windows\system32> sfc /scannow
    sfc : The term 'sfc' 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
    + sfc /scannow
    + ~~~
    + CategoryInfo : ObjectNotFound: (sfc:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Suggestion [3,General]: The command sfc was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\sfc". See "get-help about_Command_Precedence" for more details.
    PS C:\Windows\system32>
    ===========================================================
     
  2. Carlos Detweiller

    Carlos Detweiller Emperor of Ice-Cream

    Dec 21, 2012
    6,316
    7,023
    210
    As the error text tells you, use

    Code:
    .\sfc /scannow
    Powershell, just like Linux, does not load objects from the current directory (sfc.exe is in C:\Windows\System32), unless you explicitly specify it.
     
  3. AveYo

    AveYo MDL Expert

    Feb 10, 2009
    1,836
    5,685
    60
    I never had this problem - entering commands manually in the console should simply work by default on a clean install
    Seen many others experiencing it - it can be a symptom of a broken account rights and/or membership / missing environment variables.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. maxama123

    maxama123 MDL Senior Member

    Oct 22, 2009
    489
    184
    10
    #4 maxama123, Sep 10, 2020
    Last edited: Sep 10, 2020
    (OP)
    I'm very new to Powershell (I'm a beginner). Firstly, thank you for your reply and assistance.

    This now works .\sfc /Scannow

    Last night I did a clean install of Windows 10 and before the clean install I ONLY used to type sfc /scannow so my question is, why has this changed?

    IF wanted to check my computer in PowerShell so going forward, are you saying I will need to add .\ to every line as shown below.
    .\sfc /Scannow
    .\DISM /Online /Cleanup-Image /CheckHealth
    .\DISM /Online /Cleanup-Image /ScanHealth
    .\DISM /Online /Cleanup-Image /RestoreHealth

    PS C:\Windows\system32> .\sfc /Scannow
    Beginning system scan. This process will take some time.
    Beginning verification phase of system scan.
    Verification 100% complete.
    Windows Resource Protection did not find any integrity violations.


    PS C:\Windows\system32> .\DISM /Online /Cleanup-Image /CheckHealth
    Deployment Image Servicing and Management tool
    Version: 10.0.19041.329
    Image Version: 10.0.19041.508
    No component store corruption detected.
    The operation completed successfully.


    PS C:\Windows\system32> .\DISM /Online /Cleanup-Image /ScanHealth
    Deployment Image Servicing and Management tool
    Version: 10.0.19041.329
    Image Version: 10.0.19041.508
    [==========================100.0%==========================] No component store corruption detected.
    The operation completed successfully.


    PS C:\Windows\system32> .\DISM /Online /Cleanup-Image /RestoreHealth
    Deployment Image Servicing and Management tool
    Version: 10.0.19041.329
    Image Version: 10.0.19041.508
    [==========================100.0%==========================] The restore operation completed successfully.
    The operation completed successfully.

     
  5. AveYo

    AveYo MDL Expert

    Feb 10, 2009
    1,836
    5,685
    60
    a quick workaround would probably be to enter in Powershell (Admin):
    Code:
    .\setx /m PATH "$env:path;."
    And close the window and open a new one
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. maxama123

    maxama123 MDL Senior Member

    Oct 22, 2009
    489
    184
    10
    #6 maxama123, Sep 10, 2020
    Last edited: Sep 11, 2020
    (OP)
    PS C:\Windows\system32> .\setx /m PATH "$env:path;."

    SUCCESS: Specified value was saved.
    PS C:\Windows\system32> You're Amazing, Thank You :worthy:
     
  7. Carlos Detweiller

    Carlos Detweiller Emperor of Ice-Cream

    Dec 21, 2012
    6,316
    7,023
    210
    It's actually a security feature. If you're in C:\a_bad_directory and type "notepad", and a malicious file "notepad.com" or "notepad.exe" is in that directory, it will usually get executed in favor of the Windows binary.
    With the new feature in place, you actually have to call the executable from the current directory, explicitly. Just typing "notepad" will execute the Windows binary from the %PATH%.
     
  8. jcc2

    jcc2 MDL Member

    Mar 23, 2010
    119
    38
    10
    Stupid question... Why doesn't he just use sfc /scannow from an elevated CMD (run CMD as administrator) window? I have never had the need to run the command from PowerShell.

    JCC2
     
  9. maxama123

    maxama123 MDL Senior Member

    Oct 22, 2009
    489
    184
    10
    I have elevated CMD which works just not in powershell. Just a matter of preference.
     
  10. kaljukass

    kaljukass MDL Guru

    Nov 26, 2012
    3,390
    1,322
    120
    Interestingly, I have been using it for years and everything has always worked ... and even now works
    ScreenShot_20200913023155.png
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...