none
Picking up local computername for attach command RRS feed

  • Question

  • Does anyone know if it is possible to pickup the local computername to insert into the attach-productionserver.ps1 command?

    I've tried defining it as a variable and then calling it but that has not worked. Any ideas?

    $Computer = Get-WmiObject -Class Win32_ComputerSystem
    $PCname = $computer.name
    "Computer Name is: {0}" -f $PCname

    Invoke-Command -Session $pss -ScriptBlock {attach-productionserver.ps1 DPMSERVER $PCname}

     

     


    MCITP Windows 7 Enterprise Administrator
    Thursday, December 29, 2011 4:28 PM

Answers

  • Hi Reue,

    $PCname variable doesn't exist on the session you are connecting to. It only exists on the machine you created that variable.

    If you want to pass $PCname to the new session, your invoke command should be like:

    Invoke-Command -Session $pss -ScriptBlock {param ($PCname1) attach-productionserver.ps1 DPMSERVER $PCname1} -ArgumentList $PCname
    

    In the example above, the -ArgumentList switch pass the value of $PCname to $PCname1. $PCname1 is the variable we will be using within the new session


    Thanks, Wilson Souza - MSFT This posting is provided "AS IS" with no warranties, and confers no rights
    Thursday, December 29, 2011 8:12 PM
    Moderator