Cannot invoke this function because the current host does not implement it By Vb.net & Powershell RRS feed

  • Question

  • I am geeting error "Cannot process argument transformation on parameter 'Credential'. Cannot invoke this function because the current host does not implement it."

    Please help.

    Mycode  Here....


    Imports System.Management.Automation
    Imports System.Management.Automation.Host
    Imports System.Management.Automation.Runspaces
    Imports System.Collections.Generic
    Imports System.Collections.ObjectModel
    Imports System.String


    Dim rs As Runspace = RunspaceFactory.CreateRunspace()

    Dim userName As String = "dev@liveatvn.com"
    Dim password As String = "xxxx"
    Dim cred As New PSCredential(userName, StringToSecureString(password))

    Dim ps As PowerShell = PowerShell.Create
    Dim cmd As New PSCommand

    Dim strcmdlet1 As String = "Set-Variable -Name LiveCred -Value {0}"
    cmd.AddScript(String.Format(strcmdlet1, cred))
    ps.Commands = cmd
    ps.Runspace = rs
    ps.Invoke(Of PSObject)()

    Tuesday, December 13, 2011 3:54 AM

All replies

  • Hi,
    I thing you used Exchange 2010 Bcoz U used Remote powershell code and In exchange 2007 only works Local Powershell
    So try the below code.
    It works for me.

     Dim strUserName As String = "UserName"
     Dim strPassword As String = "Password"
     Dim SecuredPSWD As New System.Security.SecureString()

     For Each character As Char In strPassword
     Dim wsmConnectionInfo As WSManConnectionInfo
     Dim runspace As Runspace = Nothing

     Dim strSystemURI As String = "hTTP:// MAchineName.domainName.comg/powershell?serializationLevel=Full"
     Dim strShellURI As String = "http://schemas.microsoft.com/powershell/Microsoft.Exchange"
     Dim powerShellCredentials As PSCredential = New PSCredential(strUserName, SecuredPSWD)
     wsmConnectionInfo = New WSManConnectionInfo(New Uri(strSystemURI), strShellURI, powerShellCredentials)
     runspace = RunspaceFactory.CreateRunspace(wsmConnectionInfo)

     Dim command As Command = New Command("Command1")
     pipeline = runspace.CreatePipeline()
     Dim psObjCollection As Collection(Of PSObject) = pipeline.Invoke()
    For Each psObj As PSObject In psObjCollection


    By A Pathfinder.. JoSwa. ___________________________________________________________ If you find an answer helpful, click the helpful button. If you find an answer to your question, mark it as the answer.
    Tuesday, December 13, 2011 6:44 AM
  • I'd suggest you try something like this instead

              Command connect = new Command("Set-Variable");
              System.Security.SecureString secureString = new System.Security.SecureString();
              string myPassword = "password";
              foreach (char c in myPassword)
              connect.Parameters.Add("Value", new PSCredential("blah@onmicrosoft.com", secureString));




    Tuesday, December 13, 2011 6:50 AM