windows - Powershell's Invoke-Command won't take in a variable for -ComputerName parameter -


i can't seem work, , can't figure out how google issue. similar script working remotly need made work localy. but... please check script...

function local-install { $computername = "$env:computername" $appname = "deployment"  invoke-command -computername $computername ,$appname -scriptblock ` { param ($computername,$appname) write-host "getting parameters '$appname' on $computername"} $application = get-wmiobject -computername $computername -namespace "root\ccm\clientsdk" -class ccm_application | {$_.name -like "$appname"} | select-object id, revision, ismachinetarget $appid = $application.id $apprev = $application.revision $apptarget = $application.ismachinetarget ([wmiclass]'root\ccm\clientsdk:ccm_application').install($appid, $apprev, $apptarget, 0, 'normal', $false)  } 

and error this:

invoke-command : 1 or more computer names not valid. if trying pass uri, use -connectionuri parameter, or pass uri objects ins tead of strings. @ line:5 char:1 + invoke-command -computername $computername ,$appname -scriptblock ` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + categoryinfo          : invalidargument: (system.string[]:string[]) [invoke-command], argumentexception     + fullyqualifiederrorid : pssessioninvalidcomputername,microsoft.powershell.commands.invokecommandcommand  exception calling "install" : "" @ line:13 char:1 + ([wmiclass]'root\ccm\clientsdk:ccm_application').install($appid, $apprev, $appta ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + categoryinfo          : notspecified: (:) [], methodinvocationexception     + fullyqualifiederrorid : wmimethodexception 

since local run "env:computername" call in method. however, if want work is, need add -argumentlist argument invoke-command call:

invoke-command -computername $computername, $appname -argumentlist $computername, $appname -scriptblock ` 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -