首页 > 解决方案 > 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。

期待您的回复。

亲切的问候

雅各布

标签: c#system.io.file

解决方案


推荐阅读