C#-输入字符串的格式不正确(Set-UserPhoto)

public static bool SetUserPhoto(OnboardingEmployee employee)
{
    employee.IsSuccess = false;
    string filePath = "([System.IO.File]::ReadAllBytes(\"C:\\" + employee.Lønnummer.ToString() + ".jpg\"))";

    using (Runspace runspace = GetExchangeonlineRunspace())
    {
        Pipeline pl = runspace.CreatePipeline();
        Command cmd = new Command("Set-UserPhoto");
        cmd.Parameters.Add(new commandparameter("-Identity",employee.UserPrincipalName));
        cmd.Parameters.Add(new commandparameter("-PictureData",filePath));
        cmd.Parameters.Add(new commandparameter("-Confirm",false));
        pl.Commands.Add(cmd);
        List<PSObject> psoList = new List<PSObject>(pl.Invoke());
        employee.IsSuccess = ResolvePipelineErrors(pl,"Exchange.SetUserPhoto");
        runspace.Close();
    }
}

我收到以下错误:

{"Cannot process argument transformation on parameter 'PictureData'.  Cannot convert value \"([System.IO.File]::ReadAllBytes(\"C:\\729.jpg\"))\" to type \"System.Byte[]\". Error: \"Cannot convert value \"([System.IO.File]::ReadAllBytes(\"C:\\729.jpg\"))\" to type \"System.Byte\". Error: \"Input string was not in a correct format.\"\""}

我什至试图在第5行写字符串“ 729”而不是employee.Lønnummer.ToString()也是729。

期待您的回复。

亲切的问候

Jakob

iCMS 回答:C#-输入字符串的格式不正确(Set-UserPhoto)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2131797.html

大家都在问