这个问题让我挠头。对于 Powershell 来说也很陌生。
\n\n目标:机器启动时,Powershell 脚本启动并询问计算机名称,然后将其添加到域中,进行清理并重新启动机器。
\n\n这是我的脚本:
\n\n$getName = Read-Host -Prompt "Enter the new name for this computer"\n$user = "mdt_join"\n$password = Read-Host -Prompt "Enter password for $user" -AsSecureString\n$username = "bc\\mdt_join"\n$credential = New-Object System.Management.Automation.PSCredential($username,$password)\n\nAdd-Computer -NewName $getName -DomainName DOMAIN -OUPath "OU=Managed Stations,DC=DC,DC=DC,DC=DC" -Credential $credential -restart\n\nRename-Computer \xe2\x80\x93NewName $getName\n\nRemove-Item C:\\Users\\ladmin\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\startup.cmd\n\nRemove-Item $MyINvocation.InvocationName\nRun Code Online (Sandbox Code Playgroud)\n\n如果我手动运行该脚本,但是当我使用此startup.cmd时,该脚本可以工作
\n\nREM Attempt to set the execution policy by using PowerShell version 2.0 syntax.\nPowerShell -Version 2.0 -ExecutionPolicy Unrestricted .\\script1.ps1 >> "%TEMP%\\StartupLog.txt" 2>&1\n\nIF %ERRORLEVEL% EQU -393216 (\n REM PowerShell …Run Code Online (Sandbox Code Playgroud)