无法使用 Set-MsolUserLicense 命令发送字符串以删除用户的许可证

Cannot send string to remove licenses for user with the Set-MsolUserLicense command

我正在尝试在 c# 中使用 Set-MsolUserLicense Msol Powershell 命令来删除具有字符串

的用户的许可证
string removeLicense = "Set-MsolUserLicense -UserPrincipalName " + "\"" 
+  selectedUPN + "\"" + " -RemoveLicenses " + accountSkuId + ":ENTERPRISEPACK";

其中 selectedUPN 是从文本框中获得的选定选项。

它以某种方式不接受字符串,但如果我在 removelicense 字符串中按字面键入 UPN,它就可以工作。

终于设法得到这个排序...创建的字符串如下并且有效:

string removeLicense = "Set-MsolUserLicense -UserPrincipalName \"" + selectedUPN + "\" -RemoveLicenses " + accountSkuId + ":ENTERPRISEPACK";