locked
Batch to Power Shell Line RRS feed

  • Question

  • Hello, I am trying to convert the line 

    FOR /F "tokens=1,2 delims= " %%G IN (%TEMP%\tokensonly.txt) DO cmdkey.exe /delete:%%H
    into powershell but the for loop keeps messing me up. Could someone help me out?

    • Moved by Stanly Fan Thursday, June 15, 2017 5:33 AM from windows form general
    Wednesday, June 14, 2017 6:10 PM

All replies

  • Hi Ericode,

    According to your description, your issue is more related about PowerShell. And this forum is discussing and asking questions about the Windows Form and ClickOnce, I will move this thread to corresponding forum: PowerShell Forum for dedicated information.

    You will get a more professional support from there, thank you for your understanding.

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 15, 2017 2:50 AM
  • Hi Ericode,

    Did you mean this?

    $contents = Get-Content "%TEMP%\tokensonly.txt"
    foreach($key in $contents)
    {
        cmdkey.exe /delete:$key
    }

    Besides, could you please post your script here for further assistance?

    Best regards,

    Andy


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

    Thursday, June 15, 2017 2:58 AM
  • Get-Content "$env:temp\tokensonly.txt" | ForEach-Object { cmdkey.exe /delete:$($_.split(' ')[1])}

    To display the command, pls use below.

    Get-Content "$env:temp\tokensonly.txt" | ForEach-Object { write-host "cmdkey.exe /delete:$($_.split(' ')[1])"}

    Best regards,

    AZ

    • Proposed as answer by I.T Delinquent Thursday, June 15, 2017 9:16 AM
    Thursday, June 15, 2017 8:07 AM
  • Hi,

    Try this:

    get-content $env:temp\tokensonly.txt | %{cmdkey.exe /delete ($_ -split " ")[1]}

    Sergei.

    • Proposed as answer by Hello_2018 Friday, June 16, 2017 8:29 AM
    Thursday, June 15, 2017 9:55 AM
  • Hi,

    Any updates?

    Andy


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

    Friday, July 7, 2017 1:36 AM