Windows 10: How to run batch file with powershell

Discus and support How to run batch file with powershell in Windows 10 Network and Sharing to solve the problem; I created a basic batch file that uses "net share" to share a local path. I saved the batch file. When I double click the file I get "access is... Discussion in 'Windows 10 Network and Sharing' started by eeps24, Mar 2, 2018.

  1. eeps24 Win User

    How to run batch file with powershell


    I created a basic batch file that uses "net share" to share a local path. I saved the batch file. When I double click the file I get "access is denied"... note, I am logged on as a admin.

    Anyways... I figure it has to be run using power shell. I do not know much about powershell. Can anyone tell me how I can run this batch file (by double clicking on the icon) using power shell?

    Thank you

    edit.... if I right click the file and click "run as administrator" it runs fine. I want the ability to just double click it and execute.

    :)
     
    eeps24, Mar 2, 2018
    #1

  2. Task Scheduler trigger "On disconnect from user session" does not work in Windows 10 Home?

    We are volunteers willing to help you try to resolve this issue.

    How to: Run PowerShell Scripts from Task Scheduler

    https://community.spiceworks.com/how_to/17736-r...

    PowerShell for beginners: Scripts and loops

    https://www.computerworld.com/article/2879205/d...

    OR

    How to schedule a Batch File to run automatically in Windows 10/8/7

    http://www.thewindowsclub.com/how-to-schedule-b...

    How to run a batch file at a specific time

    How to run a batch file at a specific time

    More support for Task Scheduler and scripting in the Microsoft TechNet

    Forums.

    TechNet - Windows 10 IT Pro - Forums

    https://social.technet.microsoft.com/Forums/win...

    Windows - PowerShell

    https://social.technet.microsoft.com/Forums/Win...

    Please let us know the results and if you need further assistance.
     
    SpiritX MS MVP, Mar 2, 2018
    #2
  3. wiens Win User
    Not all command lines of CMD are working in Powershell

    In build 14971.1000 Microsoft has changed Command prompt with Powershell in the right-click context Startmenu, see screenshot below.

    Batch files (.bat or .cmd) will also not run properly in Powershell because not all command lines of HELP are working in the Powershell. How do we run batch (.bat) files with command lines that aren't supported in it.

    Consider you have a file "test.bat" on the root of the D: dirve. You can't run in it Powershell by entering "test.bat" on the D: drive. The term will not be recognized. You have to write "D:\test.bat" to run it in Powershell. That is strange behaviour. In
    the old CMD you didn't had to add "D:\" path in the line to run it in the opened directory.

    I know CMD can still be executed in the Startmenu of build 14971.1000, but it looks they are changing this behaviour. It is now hidden from the contextmenu by default.

    For those who prefer to use Command Prompt, you can opt out of the WIN + X change by opening Settings > Personalization > Taskbar, and turning “Replace Command Prompt with Windows PowerShell in the menu when I right-click the Start button or press Windows
    key+X” to “Off”.
     
    wiens, Mar 2, 2018
    #3
  4. How to run batch file with powershell

    Create a shortcut to your batch file (right-click drag+drop the file). Then edit the shortcut's Properties->Shortcut->Advanced.


    How to run batch file with powershell [​IMG]
     
    PolarNettles, Mar 2, 2018
    #4
  5. lx07 Win User
    Or you can auto elevate your .bat by sticking this at the start (copied from UUPtoISO) Code: set "params=%*" cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B ) <whatever>[/quote] Either way you'll get a UAC warning asking you to authorize running as Administrator. You can avoid this (see following tutorials...) if you want.

    If you are admin user: Create Elevated Shortcut without UAC prompt in Windows 10 Windows 10 Tutorials

    else (but a bit risky I think): Elevated Program Shortcut - Create for Standard User - Windows 7 Help Forums
     
    lx07, Apr 5, 2018
    #5
Thema:

How to run batch file with powershell

Loading...
  1. How to run batch file with powershell - Similar Threads - run batch file

  2. Cant run Batch file

    in Windows 10 Software and Apps
    Cant run Batch file: When i try to run a batch file all it says is this app can't run on your pc i tried going to my property and going to compatibility but it isn't there im on windows 11 btw but if someone can pls help...
  3. run a powershell command like a batch file

    in Windows 10 Installation and Upgrade
    run a powershell command like a batch file: I am working as a temp on a Windows 7 to Windows 10 migration team. We've encountered a problem with some software, and a solution has been found that requires us to execute a a single command with PowerShell. However, the command is extremely long and complex, and very...
  4. Syntax for Batch file &/or powershell script to run multiple commands

    in Windows 10 Support
    Syntax for Batch file &/or powershell script to run multiple commands: I wanted a batch file to run the following commands: Start Powershell as administrator cd "C:\Program Files\Macrium\Reflect" regsvr32 RContextMenu.dll regsvr32 RShellEx.dll I can get as far as: Code: echo Start "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" cd...
  5. Batch Rename in Powershell

    in Windows 10 Network and Sharing
    Batch Rename in Powershell: I'm trying to rename all the image files in a folder by appending a 1- in front of each file name using this command: Dir Rename-Item -NewName {$_.name -replace "IMG_*.*","1-IMG_*.*"} A typical file name is IMG_0001-Wolf.jpg. I get the following error message for each...
  6. how to add powershell batch file shortcut to taskbar

    in Windows 10 Support
    how to add powershell batch file shortcut to taskbar: Hi I have several batch files which I've created shortcuts for, and added to my windows taskbar. I now have a new batch file which contains some powershell which instructs pc to switch off screen. Please can anyone advise why Windows won't let me place this shortcut on the...
  7. how to add powershell batch file shortcut to taskbar

    in Windows 10 Performance & Maintenance
    how to add powershell batch file shortcut to taskbar: Hi I have several batch files which I've created shortcuts for, and added to my windows taskbar. I now have a new batch file which contains some powershell which instructs pc to switch off screen. Please can anyone advise why Windows won't let me place this shortcut on the...
  8. Batch Numbering Files through Powershell

    in Windows 10 Network and Sharing
    Batch Numbering Files through Powershell: Hello, I'm trying to come up with a solution through Powershell that batch numbers files at the beginning of a file name without interrupting the rest of the file name. For example: Current File Names: John Smith.pdf Abel Anderson.pdf Mary Trinity.pdf ..... Rocky...
  9. Running PowerShell script as a batch file

    in Windows 10 Network and Sharing
    Running PowerShell script as a batch file: Can I run the Power Shell line: "C:\Windows\System32>get-appxpackage *3dbuilder* | remove-appxpackage" from a .Bat file? ***Original title: Removing bloatware***...
  10. Running an uneditable Batch file

    in AntiVirus, Firewalls and System Security
    Running an uneditable Batch file: Hi people, Got a task to run a certain CMD command on a number of PCs as administrator. So I thought i would create a batch file doing this. This is not the issue. The issue is that I am unable to lock down successfully so people cannot just edit the file to see the admin...

Users found this page by searching for:

  1. run batch file from powershell in windows xp 2018