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