Windows 10: Pass command from a PS script to a new PS Window

Discus and support Pass command from a PS script to a new PS Window in Windows 10 Support to solve the problem; Just looking for some advice on how to run a command in a new Powershell Window from within an existing Powershell script. Currently I have the... Discussion in 'Windows 10 Support' started by Calm Horizons, Aug 20, 2021.

  1. Pass command from a PS script to a new PS Window


    Just looking for some advice on how to run a command in a new Powershell Window from within an existing Powershell script. Currently I have the following code that clears out any log files older than 21 days and then uses Robocopy to copy any new files from the Q:\ drive to the W:\ drive and while I have no doubt that it could be far more elegant than it currently is it does work: Code: Clear $CurrentDateTime = Get-Date -Format "HH-mm-ss dd-MM-yyyy" # Clean up logs files older than 21 days! Write-Host "Deleting logs files older than 21 days" forfiles /p Q:\logs\ /s /m *.txt /D -21 /C "cmd /c del /q @Path" Write-Host "`n" Write-Host "Done!" Write-Host "`n" Write-Host "Pausing for 5 seconds!" ; Start-Sleep -Seconds 5 # Sync files! cd q:\ Write-Host "`n" Write-Host "Sync files on Q:\ drive" robocopy q:\ W:\ /log:"q:\logs\$CurrentDateTime-robocopy_IMG_backup.txt" /np /s /mir /copyPass command from a PS script to a new PS Window :DAT /xd '$RECYCLE.BIN' Write-Host "Files copied!" ; Start-Sleep -Seconds 5 While that is running I know that if I manually open a second Powershell window and run the following command I can see the progress as the files are copied across: Code: Get-Content q:\logs\$CurrentDateTime-robocopy_IMG_backup.txt -Tail 5 -wait However what I can't figure out how to do is to add that code to the existing script so I don't need to manually open a second window and run it. From what I have tried so far based on Google searches etc. I think that it will involve the Start-Process and -ArgumentList commands but I am struggling to work out the syntax (assuming of course that I am even on the right track here). Any pointers would be appreciated.

    :)
     
    Calm Horizons, Aug 20, 2021
    #1
  2. Govi59 Win User

    Using these PS commands in CMD


    Hi there,
    thank you for this wonderfull tuto Pass command from a PS script to a new PS Window :)
    I have a specific demand, because I want to do things in my own way *chuckle

    Opening PS without Restricted policy --> Done
    Typing Get-AppxPackage *name* | Remove-AppxPackage --> Done. And it works ! Pass command from a PS script to a new PS Window :)
    Creating a uninstall-apps.ps1 script with many lines and executing it in PS with C:\Users\Govi\uninstall-apps.ps1 --> Done. And it works ! *Biggrin

    Now, I would like to execute my uninstall-apps.ps1 script from cmd or from a .bat script (back to old black cmd windows <3)... But it doesn't work...
    I tried :
    powershell.exe C:\Users\Govi\uninstall-apps.ps1
    powershell.exe -noexit C:\Users\Govi\uninstall-apps.ps1
    powershell.exe -noexit "& 'C:\Users\Govi\uninstall-apps.ps1'"
    powershell.exe -noexit -file "C:\Users\Govi\uninstall-apps.ps1"

    and many others...
    none of theese line work. *Sad
    With other commands in the .ps1 script, such as Write-Host Hello world!, it works... But not the command I want.

    Eventually, is there a way to execute this batch PS script from cmd or a .bat script ? *sarc

    Thank you very much !

    EDIT : I continued trying and it worked from a .bat script ! I don't know why it doesn't work from the cmd directly, but the .bat script with powershell C:\Users\Govi\uninstall-apps.ps1 works perfectly.
     
    Govi59, Aug 20, 2021
    #2
  3. GFR
    gfr Win User
    Running Optimize literally does nothing; in PS it yields an error

    After doing a clean install of Windows 10 20H2 (OS Build 19042.906) and fully updating it, and updating all of the Dell drivers from Dell.com, I tried the following Optimize and Defrag options from How to Optimize and Defragment Drives in Windows 10 (tenforums.com/tutorials/8933-optimize-defrag-drives-windows-10-a.html):

    • OPTION ONE: To Optimize Drives in Optimize Drives Tool: Steps 2, 3, and 4,
    • OPTION TWO: To Optimize Drives in Command Prompt: Step 2, and
    • OPTION THREE: To Optimize Drives in PowerShell: Step 3
    The four steps attempted from Options 1 and 2 resulted in no notice action; i.e., it appeared as though nothing happened after executing the commands.

    When I ran Step 3 of Option 3, I received the following error message.

    What does this mean and now what do I do?

    Thanks!




    Pass command from a PS script to a new PS Window [​IMG]
     
  4. FredTsui Win User

    Pass command from a PS script to a new PS Window

    Can't Completely delete USB printer through PS or command line

    Thanks for the info. But I need to be able to do it from a script either in PS or vbs.

    I've tried removing the printer driver from PS and vbs but still the printer icon is in the GUI.
     
    FredTsui, Aug 20, 2021
    #4
Thema:

Pass command from a PS script to a new PS Window

Loading...
  1. Pass command from a PS script to a new PS Window - Similar Threads - Pass command script

  2. ATP verification PS script Error on CMD "Access Denied"

    in AntiVirus, Firewalls and System Security
    ATP verification PS script Error on CMD "Access Denied": Hello, I have to verify the newly ATP on board PC and running below script to verify but the error say access denied although I have run cmd with admin privilege's and created a folder also in C as article says but still I don't know why it says "access denied" can anyone...
  3. PS Express Download

    in Microsoft Windows 10 Store
    PS Express Download: I tried to download PS express from Microsoft Store. I waited four hours and it was still not downloaded. There is no way to tell if it is actually working so I cancelled it. What can i do about it? I am working on Windows 10...
  4. Opinions on this PS

    in Windows 10 Support
    Opinions on this PS: I'm looking for something in this price range for my second computer. It's just used for mostly just browsing the internet. It will just be using the graphics built in to the intel i5-4670k processor the motherboard is an Asus Z 87A and it has 4 gigs of Gskill ram. I'm...
  5. How to click the 'Download and Install' Windows Update button from command prompt / PS?

    in Windows 10 Installation and Upgrade
    How to click the 'Download and Install' Windows Update button from command prompt / PS?: We and apparently many others have been having issues installing the latest round of Windows Updates 1903 & 1909. For whatever reason, the user is required to manually click this 'Download and install' button to initiate the update. This is not the same button as the 'Check...
  6. Networking 2 PS’s

    in Windows 10 Network and Sharing
    Networking 2 PS’s: In the office we have 2 PC’s that originally came with win8 but now are running win 10. Both where set up that they could see the other PC and also where able to open and change any file on it. After an update/upgrade this is no longer possible. The strange part is that they...
  7. PS/2 Mouse

    in Windows 10 Drivers and Hardware
    PS/2 Mouse: Hello, I have 2 PS/2 mouses. A Logitech TrackMan Vista and a Logitech TrackMan Marble FX. But they just won't work on my desktop (My desktop has a PS/2 port, so i just plug them in my PS/2 port). I tried al the sulutions that i found on the internet but none will work....
  8. Scripting, either PS or cmd, to change Windows Update Advanced options

    in Windows 10 Support
    Scripting, either PS or cmd, to change Windows Update Advanced options: Hello Everyone, Decided it was time to join, and reach out for help. I work for a Hardware Retailer and we just upgraded to windows 10 computers for our POS registers, Dell optiplex 9010 w/i5 and 8gb ram. I have no formal training and have learned along the way. When I...
  9. pup ps

    in Windows 10 BSOD Crashes and Debugging
    pup ps: I keep getting mail from en.safefrom.net - don't know how to stop it - thank you https://answers.microsoft.com/en-us/windows/forum/windows_10-performance/pup-ps/47c5ddde-0a86-4a7f-928f-639e308251fa
  10. Ibm ps/1

    in Windows 10 Network and Sharing
    Ibm ps/1: I cranked up my IBM PS/1 from 1993, she of the 386SX and 2 Megs of RAM, souped up to a 486SX with, wait for it, 6 Meg of RAM! I connected it to the Network and let it simmer overnight. Shows up in File Manager now. Whoop! 78604