For official Microsoft content, see Microsoft 365 documentation. So we at least know that much is working properly. But opting out of some of these cookies may affect your browsing experience. NoNewWindow starts the process in the current window (add this at end of the script to mention not to open the cmd window). So, we'll write a batch file to call the PowerShell script from the command line for us. Your run command is incorrect. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. You will need to login as an admin to run the script. The shell runs the SharePoint.ps1 script at startup and executes the following code: $ver = $host | select version if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = ReuseThread}. There is no need to nest files or use CMD in this case. 2 How do I make a PowerShell script run automatically? Hey Mrityunjayd . Type cmd into start. Is there a proper earth ground point in this switch box? Are you just running cmd.exe from Run or the Start Menu? This step will guide you on how to Add the Batch file to a PowerShell script to run automatically when the PowerShell script is being run. Unfortunately, theres no way to trigger UAC for elevation from within a batch file or CMD session. However, there are some important bits demonstrated here: The profile, in this case, is a simple one-line script used for this demonstration to generate output whenever the profile is active. Lets see what happens when we double-click MyScript.bat. I had to remove the machine from the domain Before doing that . When to run PowerShell without a CMD prompt? How do I run a batch file as administrator in PowerShell? How to Open Windows PowerShell as an Admin in Windows 10 Hi all, The batch code that I showed you will get the user name of the currently logged on user and set the appropriate %AppData% path for that user. Now enter the following command and press the enter key: I tried running the command in powershell, it works but having trouble after merging it with .bat file. Right-click on Command Prompt . These cookies do not store any personal information. The user running the script needs to be local administrator to access \\$computername\c$. pringtef over 6 years ago. Follow Up: struct sockaddr storage initialization by network format-string, How do you get out of a corner when plotting yourself into a corner.