我正在创建一个批处理文件,其中涉及将 SID 转换为本地/域用户名。由于我们无法使用命令提示符实现这一点,因此我计划使用 powershell,并且我也有 PS 命令。我可以在 powershell 控制台中运行它而没有任何问题,但不确定如何在命令提示符下将其用作单行(在批处理文件中使用)。我已经尝试过以下方法。
在 PS 控制台中完美运行的 Powershell 命令 -
([System.Security.Principal.SecurityIdentifier]("S-1-5-32-544")).Translate([System.Security.Principal.NTAccount]).Value
我已经尝试过但没有成功的命令行 -
powershell -command ([System.Security.Principal.SecurityIdentifier]("S-1-5-32-544")).Translate([System.Security.Principal.NTAccount]).Value
powershell -command {([System.Security.Principal.SecurityIdentifier]("S-1-5-32-544")).Translate([System.Security.Principal.NTAccount]).Value}
我究竟做错了什么?是由于任何转义字符还是我缺少任何 powershell 命令参数?任何帮助是极大的赞赏。