none
Script With .bat RRS feed

  • Question

  • How can I run these .bat files with powershell instead of command prompt? I think they work fine but I don't have admin permissions to run them in command prompt but I do in powershell.

    @ECHO OFF
    :: variables
    /min
    SET odrive=%odrive:~0,2%
    set backupcmd=xcopy /s /c /d /e /h /i /r /y
    echo off
    %backupcmd% "%USERPROFILE%\pictures" "%drive%\all\My pics"
    %backupcmd% "%USERPROFILE%\Favorites" "%drive%\all\Favorites"
    %backupcmd% "%USERPROFILE%\videos" "%drive%\all\vids"
    @echo off 
    cls
    and 
    wscript.exe \invisible.vbs file.bat

    Wednesday, March 25, 2015 2:12 PM

All replies

  • Hi RileyMcKee,

    Rather than using old batch scripts, you should try re-writing it in powershell. (Provided you are still not with older clients)

    Anyways you can easily switch between "cmd" and "Powershell" using just these keywords.

    1. Open up Powershell with Admin Permissions (Rt. click->Run As Administrator)
    2. Type "cmd" Enter
    3. The console looks the same, but you are now in cmd prompt and if you notice non of the powershell commands work anymore.
    4. Type "powershell" Enter
    5. This will switch back the console to PowerShell.

    Sample below:

    Windows PowerShell
    Copyright (C) 2012 Microsoft Corporation. All rights reserved.
    
    PS C:\Users\test> get-process | select name -first 4
    
    Name
    ----
    brmsvc
    audioda
    AamExec
    BbSvcHst
    
    
    PS C:\Users\test> cmd
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\test>get-process | select name -first 4
    'get-process' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\Users\test>powershell
    Windows PowerShell
    Copyright (C) 2012 Microsoft Corporation. All rights reserved.
    
    PS C:\Users\test>
    


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    Thursday, April 30, 2015 4:21 AM
  • Hi RileyMcKee,

    Any Updates.


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    Monday, May 4, 2015 11:52 AM