Invoke-Command into a remote host works in PowerShell terminal, not in vb.net -


this script works in powershell terminal (32 bit host 64 bit target) :

ps c:\users\administrateur> $username=login ps c:\users\administrateur> $pass=convertto-securestring -asplaintext password -force ps c:\users\administrateur> $cred= new-object system.management.automation.pscredential                                      -argumentlist $username,$pass   ps c:\users\administrateur> set-item wsman:\localhost\client\trustedhosts                                      targethost -force ps c:\users\administrateur> invoke-command -computername targethost                               -scriptblock { icacls "f:\www\file.txt" /grant group:f }                               -authentication negotiate -credential $cred 

i need set authentication negociate able log local remote user (targethost\administrator).

i'm trying reproduce in vb.net :

imports system.management.automation imports system.security imports system.management.automation.runspaces  public class remoterightsmanager   ' credential set here '  ' [...] '  public function setremoterights(byval path string,                                      byval icaclsentry string) boolean         dim icaclscommand string = "icacls """ + path + """ /grant """ & icaclsentry & """"         setremoterights = true          dim psi powershell         dim initial initialsessionstate = initialsessionstate.createdefault()         dim runspace runspace = runspacefactory.createrunspace(initial)         runspace.open()          psi = powershell.create         psi.runspace = runspace         psi.addcommand("set-variable")         psi.addparameter("name", "credential")         psi.addparameter("value", me.credential)         psi.addcommand("set-item")         psi.addargument("wsman:\localhost\client\trustedhosts")         psi.addargument(me.host)         psi.addparameter("force")         psi.addcommand("invoke-command")         psi.addparameter("computername", me.host)         dim block scriptblock = scriptblock.create(icaclscommand )         psi.addparameter("scriptblock", block)         psi.addparameter("authentication", "negotiate")         psi.addparameter("credential", credential)          each item psobject in psi.invoke()             console.writeline(item)         next     end function end class 

i don't understand why, psi.invoke() seems absolutly nothing ; execution never enters in for each loop, except if comment psi lines except scriptblock one, , even, don't catch console output (seems issue though).


Comments