locked
Need help transferring a CMD script to PowerShell RRS feed

  • Question

  • Hello,

    I've got a script that I used to run through cmd, but I want to hide whatever is typed into the window and I don't think I can do that if I'm not using PowerShell instead. So I would appreciate if anyone could help me.

    The script is very simple: if the correct password is entered, a command runs (a file is opened) then the window closes itself, if the password is wrong, the window just closes. Here is the old one:

    -

    @echo OFF
    set/p "pass=>"
    if NOT %pass%== password goto :END
    if %pass%== y goto :RUN

    :RUN:
    @echo OFF
    start FILE.exe
    @echo OFF
    timeout/t 2 /nobreak


    :END
    exit

    -

    Thanks in advance.

    Wednesday, January 17, 2018 12:27 PM

All replies

  • John,

    because this is not a free scripting service you will have to migrate your script by yourself. Anyway it is a really bad idea to store the password in clear text in the script. 

    Regardless of that, migrating this simple script to Powershell is a very easy task. You would learn how to do in just a few hours and I think it would pay of for you in the future.

    Also find prewritten scripts here: PowerShell Gallery or here: TechNet Gallery - resources for IT professionals.

    Learn PowerShell: Microsoft Virtual Academy - Getting Started with Microsoft PowerShell.

    Script requests: Microsoft Technet Script Center - Requests.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, January 17, 2018 12:56 PM
  • Oh, I'm really sorry for posting it here then.

    About storing the password in plain text, this is just one layer, there is going to be at least another password. But you're right, and it would be awesome to learn how to hide it. I've only been able to find how to hide credentials on PowerShell so far, and being this script stored on a removable drive, that wouldn't work.

    I'll definitely check the links you posted to learn it and I'll keep looking for how to hide the text password instead of storing it in clear text in the script.

    Thanks for the help.

    Wednesday, January 17, 2018 1:07 PM
  • Hi,

    I'm checking how the issue is going, was your issue resolved?

    And if the replies as above are helpful, we would appreciate you to mark them as answers, and if you resolve it using your own solution, please share your experience and solution here. It will be greatly helpful to others who have the same question.

    Appreciate for your feedback.

    Best Regards,
    Albert


    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, January 18, 2018 5:51 AM