c# - 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。
期待您的回复。
亲切的问候
雅各布
解决方案
推荐阅读
- java - 输入读取后出现意外的无限循环
- python-3.x - 从 Quart 中的自定义转换器访问 app_context
- c++ - C++:如何更正我的代码的读取访问冲突
- kframework - KFramework:`#isConcrete` 和函数全局配置查找的问题
- amazon-dynamodb - 用于事务写入操作的 DynamoDB 流排序
- python - Pandas 将嵌入 JSON 的 CSV 读取到数据框中
- ios - 单击消息后的 MessageKit 动画
- python - 为什么 Spark 在正确的代码上一直说“UnboundLocalError:分配前引用的局部变量”?
- html - 文本和图像对齐
- sql - 更新列中的时间戳值,使最新的时间戳是当前时间,同时保持行之间的相对时间差