problem using psexec with diskpart remotely

Welcome Forums General PowerShell Q&A problem using psexec with diskpart remotely

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5681

    Points: 0
    Rank: Member

    by willbs at 2013-03-18 11:15:31

    whe i run this code with the literal values for the remote machine name, username and password, it works fine

    psexec \\ -u Username -p Password cmd /c 'echo . | diskpart /s "D:\serverfolders\documents\MSR-EFItest.txt" > "D:\serverfolders\documents\MSR-EFIlog.txt"'

    if i run the same code using global variables, it gets stuck, as if i have the incorrect remote machine name, username, or password

    psexec \\$global:uutName -u $global:usernamer -p $global:password cmd /c 'echo . | diskpart /s "D:\serverfolders\documents\MSR-EFItest.txt" > "D:\serverfolders\documents\MSR-EFIlog.txt"'

    or this too with quotes

    psexec \\"$global:uutName" -u "$global:usernamer" -p "$global:password" cmd /c 'echo . | diskpart /s "D:\serverfolders\documents\MSR-EFItest.txt" > "D:\serverfolders\documents\MSR-EFIlog.txt"'

    any suggestions to get it to work?

    by poshoholic at 2013-03-19 11:57:05

    Have you tried pushing the double backslash inside of your uutName variable? That would be my first guess as to why it isn't working with variables.

    by willbs at 2013-03-19 14:41:21

    that was a good guess but it didn't work

    by poshoholic at 2013-03-20 05:38:01

    Ok, here's another way you could do it: try using splatting instead to push the arguments into psexec, like this:
    $psexecArguments = @(
    'echo . | diskpart /s "D:\serverfolders\documents\MSREFItest.txt" > "D:\serverfolders\documents\MSR-EFIlog.txt"'
    psexec @psexecArguments

    You should also verify the contents of the array by outputting it to the console to make sure the arguments are what you think they should be as a part of testing this. If that fails then I can run some tests locally (don't have psexec installed right now, which is why I'm just putting out suggestions).

    by willbs at 2013-03-20 09:02:51

    hey poshoholic, you got me thinking about pushing the backslashes when it didn't work
    so what i did was remove them from the contents of the global variables and rewrote the command like this

    psexec \\$global:uutName -u \$global:DiskPartusername -p $global:password cmd /c 'echo . | diskpart /s "D:\serverfolders\documents\MSR-EFItest.txt" > "D:\serverfolders\documents\MSR-EFIlog.txt"'

    and it works fine

    thanks for the idea

    by poshoholic at 2013-03-20 12:12:26

    Excellent, glad you were able to work it out.

The topic ‘problem using psexec with diskpart remotely’ is closed to new replies.