locked
Powershell Remote Pre-Staging to wds RRS feed

  • Question

  • I,m having problem in my powershell script I,m trying to remote prestage a client to my wds, i hope someone can help

    this is the secript

    ============================================================

    $Username = "WDS\administrator"
    $Password = "PassWord"
    $Pass = ConvertTo-SecureString $Password -asPlainText -force
    $Cred = new-object System.Management.Automation.PSCredential($UserName, $pass)

    $DevGuid = Get-WmiObject Win32_NetworkAdapter -Filter "netenabled = true" | Select -Expand Guid
    $DevNam = Get-WmiObject -Class Win32_Bios | Select -Expand SerialNumber

    Invoke-Command -ComputerName WDS -ScriptBlock { New-WdsClient -DeviceID $DevGuid -DeviceName $DevNam -BootImagePath "Boot\x64\Images\LiteTouchPE_x64.wim" } -credential $Cred

    ============================================================

    When i run the secript i get this error message.

    (Cannot validate argument on parameter 'DeviceID'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. )



    First i hade this command and it worked well

    =============================================================

    $Username = "WDS\administrator"
    $Password = "PassWord"
    $Pass = ConvertTo-SecureString $Password -asPlainText -force
    $Cred = new-object System.Management.Automation.PSCredential($UserName, $pass)

    Invoke-Command -ComputerName WDS -ScriptBlock { New-WdsClient -DeviceID "ComputerGUID" -DeviceName "ComputerName" -BootImagePath "Boot\x64\Images\LiteTouchPE_x64.wim" } -credential $Cred

    =============================================================


    powershell version 5.0

    Best regards to you all

    Best Regards Al

    Wednesday, May 24, 2017 9:48 AM

All replies

  • Variables have to be passed as arguments.

    Read the help very carefully to understand how to do this:

    help Invoke-Command -Full


    \_(ツ)_/

    Wednesday, May 24, 2017 2:42 PM
  • Hi,

    Try this:

    $Username = "WDS\administrator"
    $Password = "PassWord"
    $Pass = ConvertTo-SecureString $Password -asPlainText -force
    $Cred = new-object System.Management.Automation.PSCredential($UserName, $pass)
    
    $DevGuid = Get-WmiObject Win32_NetworkAdapter -Filter "netenabled = true" | Select -Expand Guid
    $DevNam = Get-WmiObject -Class Win32_Bios | Select -Expand SerialNumber
    
    Invoke-Command -ComputerName WDS -ScriptBlock { New-WdsClient -DeviceID $DevGuid123 -DeviceName $DevNam123 -BootImagePath "Boot\x64\Images\LiteTouchPE_x64.wim" }  -ArgumentList $DevGuid,$DevNam  -credential $Cred

    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.

    • Proposed as answer by Hello_2018 Monday, June 5, 2017 7:06 AM
    Thursday, May 25, 2017 7:58 AM
  • You forgot the "Param" statement in the scriptblock.


    \_(ツ)_/

    • Proposed as answer by Hello_2018 Monday, June 5, 2017 7:06 AM
    Thursday, May 25, 2017 8:36 AM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    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.

    Monday, June 5, 2017 7:06 AM