我有一个配置脚本,我想在 Autopilot 安装期间运行一次。我已使用设备配置 - Powershell 脚本实现了此操作。我已打开转录并在 Intune 执行脚本时获得此输出
***********************************************
Windows PowerShell transcript start
Start time: 20190411103038
Username: SWIB\OneDrive.Test
RunAs User: SWIB\OneDrive.Test
Configuration Name:
Machine: L06ALHFSU9YA5NS (Microsoft Windows NT 10.0.17763.0)
Host Application:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -executionPolicy bypass -file C:\Program Files (x86)\Microsoft Intune Management Extension\Policies\Scripts\69e660db-d578-4780-9f2e-348c495cd2c3_126e1cef-ade3-4672-a86c-623796621291.ps1
Process ID: 9812
PSVersion: 5.1.17763.134
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.134
BuildVersion: 10.0.17763.134
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\Temp\SWIB.Install.log
************************
问题是,当 Intune 执行脚本时,我收到 Rename-LocalUser 不存在的错误。但如果我使用 Powershell 或 ISE 在同一台机器上运行相同的脚本,脚本就会正常执行。
++++++++++++++++
Rename-LocalUser : The term 'Rename-LocalUser' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
+++++++++++++++++++++++++++
我想知道这里发生了什么,感觉 Intune 调用的 Powershell 进程与我从命令行启动的进程不同。
答案1
听起来你在一个较旧的系统上,它缺少/找不到Microsoft.PowerShell.LocalAccounts
包含Rename-LocalUser
命令?
尝试添加Import-Module Microsoft.PowerShell.LocalAccounts
到您的脚本中。否则可能需要重新安装Windows 管理框架 5.1。