{"content":"<div></div>","rawMetadata":{"metadata":{"_op_canonicalUrlPrefix":"https://learn.microsoft.com/zh-cn/powershell/","_op_gitContributorInformation":{"author":{"display_name":"Banreet Kaur","id":"92906285","name":"Banreet","profile_url":"https://github.com/Banreet"},"contributors":[{"display_name":"Aaron Czechowski","id":"26784733","name":"aczechowski","profile_url":"https://github.com/aczechowski"},{"display_name":"Dan Mabee","id":"40476441","name":"damabe","profile_url":"https://github.com/damabe"},{"display_name":"Chris Kibble","id":"39386226","name":"ChrisKibble","profile_url":"https://github.com/ChrisKibble"},{"display_name":"sankethka","id":"16908144","name":"sankethka","profile_url":"https://github.com/sankethka"}],"update_at":"2026/9/1","updated_at_date_time":"2026-09-01T12:21:34.8883548Z"},"_path":"module/configurationmanager/new-cmtssteprunpowershellscript.json","_rel":"../../","_tocRel":"../sccm-ps/toc.json","apiPlatform":"powershell","author":"Banreet","breadcrumb_path":"/powershell/sccm/bread/toc.json","canonical_url":"https://learn.microsoft.com/zh-cn/powershell/module/configurationmanager/new-cmtssteprunpowershellscript?view=sccm-ps","content_git_url":"https://github.com/MicrosoftDocs/sccm-docs-powershell-ref/blob/main/sccm-ps/ConfigurationManager/New-CMTSStepRunPowerShellScript.md","default_moniker":"sccm-ps","depot_name":"MSDN.sccm-powershell","external help file":"AdminUI.PS.dll-Help.xml","feedback_product_url":"https://feedbackportal.microsoft.com/feedback/forum/4669adfc-ee1b-ec11-b6e7-0022481f8472","feedback_system":"Standard","git_commit_id":"48cf632fb4b9ad92060012681a500478254de750","gitcommit":"https://github.com/MicrosoftDocs/sccm-docs-powershell/blob/48cf632fb4b9ad92060012681a500478254de750/sccm-ps/ConfigurationManager/New-CMTSStepRunPowerShellScript.md","github_contributors":["aczechowski","damabe","ChrisKibble","sankethka"],"locale":"zh-cn","manager":"laurawi","Module Name":"ConfigurationManager","monikers":["sccm-ps"],"ms.author":"dannygu","ms.date":"08/31/2021","ms.service":"configuration-manager","ms.subservice":"other","ms.topic":"reference","online version":"","open_to_public_contributors":true,"original_content_git_url":"https://github.com/MicrosoftDocs/sccm-docs-powershell/blob/live/sccm-ps/ConfigurationManager/New-CMTSStepRunPowerShellScript.md","original_content_git_url_template":"{repo}/blob/{branch}/sccm-ps/ConfigurationManager/New-CMTSStepRunPowerShellScript.md","PlatyPS schema version":"2.0.0","products":["https://authoring-docs-microsoft.poolparty.biz/devrel/f1499c3b-793f-48c3-a9ce-20285bcc6541"],"site_name":"Docs","titleSuffix":"Configuration Manager","uhfHeaderId":"MSDocsHeader-Powershell","updated_at":"2026-09-01 12:21 PM","xrefs":[{"href":"https://learn.microsoft.com/powershell/module/configurationmanager/new-cmtssteprunpowershellscript","monikerGroup":"f98fea35b6ac2b0f56c6ee5ec06ffce9","name":"New-CMTSStepRunPowerShellScript","schemaType":"PowershellCmdlet","summary":"<p>在任务序列中创建 <strong>“运行 PowerShell 脚本”</strong> 步骤。</p>\n","uid":"ConfigurationManager.New-CMTSStepRunPowerShellScript"}],"ocv-translation-feedback":true},"_xrefmap":{"ConfigurationManager":{"href":"./","monikerGroup":"f98fea35b6ac2b0f56c6ee5ec06ffce9","name":"ConfigurationManager","schemaType":"PowershellModule","uid":"ConfigurationManager"},"ConfigurationManager.New-CMTSStepRunPowerShellScript":{"href":"new-cmtssteprunpowershellscript","monikerGroup":"f98fea35b6ac2b0f56c6ee5ec06ffce9","name":"New-CMTSStepRunPowerShellScript","schemaType":"PowershellCmdlet","summary":"<p>在任务序列中创建 <strong>“运行 PowerShell 脚本”</strong> 步骤。</p>\n","uid":"ConfigurationManager.New-CMTSStepRunPowerShellScript"}},"description":"<p>此 cmdlet 创建一个新的 <strong>运行 PowerShell 脚本</strong> 步骤对象。 然后使用 <a href=\"add-cmtasksequencestep\">Add-CMTaskSequenceStep</a> cmdlet 将步骤添加到任务序列。 有关此步骤的详细信息，请参阅 <a href=\"/mem/configmgr/osd/understand/task-sequence-steps#BKMK_RunPowerShellScript\">关于任务序列步骤：运行 PowerShell 脚本</a>。</p>\n<div class=\"NOTE\">\n<p>注意</p>\n<p>从 Configuration Manager 站点驱动器运行 Configuration Manager cmdlet，例如 <code>PS XYZ:\\&gt;</code>。 有关详细信息，请参阅 <a href=\"/powershell/sccm/overview\">入门</a>。</p>\n</div>\n","examples":[{"code":"$step = New-CMTSStepRunPowerShellScript -Name \"Run PowerShell Script\" -PackageId \"XYZ00821\" -ScriptName \"Add-ContosoBranding.ps1\" -ExecutionPolicy AllSigned \n\n$tsNameOsd = \"Default OS deployment\"\n$tsOsd = Get-CMTaskSequence -Name $tsNameOsd -Fast\n\n$tsOsd | Add-CMTaskSequenceStep -Step $step -InsertStepStartIndex 11","description":"","summary":"<p>此示例首先为 <strong>运行 PowerShell 脚本</strong> 步骤创建对象。 它指定具有要运行的脚本名称的包。 它将 PowerShell 执行策略设置为最安全的 <strong>AllSigned</strong> 级别，这要求对脚本进行数字签名。</p>\n<p>然后，它获取任务序列对象，并将此新步骤添加到索引 11 处的任务序列。</p>\n","title":"示例 1"}],"inputs":[{"description":"","name":"<span class=\"no-loc xref\">None</span>\n"}],"links":[{"href":"get-cmtssteprunpowershellscript","text":"Get-CMTSStepRunPowerShellScript"},{"href":"remove-cmtssteprunpowershellscript","text":"Remove-CMTSStepRunPowerShellScript"},{"href":"set-cmtssteprunpowershellscript","text":"Set-CMTSStepRunPowerShellScript"},{"href":"/mem/configmgr/osd/understand/task-sequence-steps#BKMK_RunPowerShellScript","text":"关于任务序列步骤：运行 PowerShell 脚本"}],"module":"ConfigurationManager","name":"New-CMTSStepRunPowerShellScript","notes":"<p>有关此返回对象及其属性的详细信息，请参阅 <a href=\"/mem/configmgr/develop/reference/osd/sms_tasksequence_runpowershellscriptaction-server-wmi-class\">SMS_TaskSequence_RunPowerShellScriptAction服务器 WMI 类</a>。</p>\n","outputs":[{"description":"","name":"<span class=\"no-loc xref\">IResultObject</span>\n"}],"parameters":[{"aliases":"Conditions","defaultValue":"None","description":"<p>指定要用于此步骤的条件对象。 若要获取此对象，请使用任务序列条件 cmdlet 之一。 例如 <a href=\"get-cmtsstepconditionvariable\">Get-CMTSStepConditionVariable</a>。</p>\n","name":"Condition","parameterValueGroup":"","position":"Named","type":"<p><span class=\"no-loc xref\">IResultObject</span><span>[</span><span>]</span></p>\n"},{"aliases":"cf","defaultValue":"None","description":"<p>提示你在运行 cmdlet 之前进行确认。</p>\n","name":"Confirm","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>添加此参数以启用步骤选项“ <strong>出错时继续</strong>”。 启用此选项时，如果步骤失败，任务序列将继续。</p>\n","name":"ContinueOnError","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>为此任务序列步骤指定可选说明。</p>\n","name":"Description","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"DisableThisStep","defaultValue":"None","description":"<p>添加此参数以禁用此任务序列步骤。</p>\n","name":"Disable","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>此参数将通配符视为文本字符值。 不能将其与 <strong>ForceWildcardHandling</strong> 组合使用。</p>\n","name":"DisableWildcardHandling","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"PowerShellExecutionPolicy","defaultValue":"None","description":"<p>为允许在计算机上运行的脚本指定 PowerShell 执行策略。 选择以下策略之一：</p>\n<ul>\n<li><p>\n              <code>AllSigned</code>：仅运行由受信任的发布者签名的脚本。</p>\n</li>\n<li><p>\n              <code>Undefined</code>：不定义任何执行策略。</p>\n</li>\n<li><p>\n              <code>Bypass</code>：加载所有配置文件并运行所有脚本。 如果从 Internet 下载未签名的脚本，则 PowerShell 在运行脚本之前不会提示输入权限。</p>\n</li>\n</ul>\n","name":"ExecutionPolicy","parameterValueGroup":"AllSigned, Undefined, Bypass","position":"Named","type":"<span class=\"no-loc xref\">ExecutionPolicyType</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>此参数处理通配符，并可能导致意外行为， (不建议) 。 不能将其与 <strong>DisableWildcardHandling</strong> 组合使用。</p>\n","name":"ForceWildcardHandling","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"StepName","defaultValue":"None","description":"<p>指定此步骤的名称，以便在任务序列中标识它。</p>\n","isRequired":true,"name":"Name","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"Output, OutputVariable","defaultValue":"None","description":"<p>指定自定义任务序列变量的名称。 使用此参数时，该步骤会将命令输出的最后 1000 个字符保存到 变量。</p>\n","name":"OutputVariableName","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>为具有 PowerShell 脚本的包指定包 <strong>ID</strong> 。 包不需要程序。 一个包可以包含多个脚本。</p>\n<p>此值是标准包 ID，例如 <code>XYZ00821</code>。</p>\n<p>然后使用 <strong>ScriptName</strong> 参数指定脚本的名称。</p>\n","isRequired":true,"name":"PackageId","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"Parameters","defaultValue":"None","description":"<p>指定传递给 PowerShell 脚本的参数。 这些参数与命令行上的 PowerShell 脚本参数相同。 提供脚本使用的参数，而不是 PowerShell 命令行的参数。</p>\n<p>以下示例包含 <em>有效</em> 参数：</p>\n<p><code>-MyParameter1 MyValue1 -MyParameter2 MyValue2</code></p>\n<p>以下示例包含 <em>无效</em> 参数。 前两项是 PowerShell 命令行参数 (<strong>NoLogo</strong> 和 <strong>ExecutionPolicy</strong>) 。 脚本不使用这些参数。</p>\n<p><code>-NoLogo -ExecutionPolicy Unrestricted -File MyScript.ps1 -MyParameter1 MyValue1 -MyParameter2 MyValue2</code></p>\n<p>如果参数值包含特殊字符或空格，请使用单引号 (<code>'</code>) 值。 使用双引号 (<code>&quot;</code>) 可能会导致任务序列步骤错误地处理 参数。</p>\n<p>例如：<code>-Arg1 '%TSVar1%' -Arg2 '%TSVar2%'</code></p>\n<p>还可以将此参数设置为任务序列变量。 例如，如果指定 <code>%MyScriptVariable%</code>，则任务序列运行脚本时，它会将此自定义变量的值添加到 PowerShell 命令行。</p>\n","name":"Parameter","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"","defaultValue":"None","description":"<p>指定要运行的脚本的名称。 此脚本位于 <strong>PackageId</strong> 参数指定的包中。</p>\n","isRequired":true,"name":"ScriptName","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"SourceCode","defaultValue":"None","description":"<p>使用此参数直接指定脚本命令，而不是使用 <strong>PackageId</strong> 和 <strong>ScriptName</strong> 参数。 此字符串值是此步骤运行的 PowerShell 命令。</p>\n<p>可以将现有脚本文件的内容读入字符串变量，然后将该变量用于此参数。 例如：</p>\n<p><code>$script = [IO.File]::ReadAllText( &quot;C:\\temp\\script.ps1&quot; )</code></p>\n","isRequired":true,"name":"SourceScript","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"SuccessCodes","defaultValue":"None","description":"<p>指定一个整数值数组作为脚本中的退出代码，步骤应将其评估为成功。</p>\n","name":"SuccessCode","parameterValueGroup":"","position":"Named","type":"<p><span class=\"no-loc xref\">Int32</span><span>[</span><span>]</span></p>\n"},{"aliases":"TimeoutInMinutes","defaultValue":"None","description":"<p>指定一个整数值，该值表示 Configuration Manager 允许脚本运行的时间。 此值可以是从 <code>1</code> 分钟到 <code>999</code> 分钟。 默认值 <code>15</code> 为分钟。</p>\n<p>如果输入的值不允许指定脚本有足够的时间成功完成，则此步骤将失败。 整个任务序列可能会失败，具体取决于步骤或组条件。 如果超时过期，Configuration Manager 将终止 PowerShell 进程。</p>\n","name":"TimeoutMins","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">Int32</span>\n"},{"aliases":"User","defaultValue":"None","description":"<p>使用此参数以 Windows 用户帐户（而不是本地系统帐户）的形式运行脚本。 指定 Windows 用户帐户的名称。 若要指定帐户密码，请使用 <strong>UserPassword</strong> 参数。</p>\n","name":"UserName","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"},{"aliases":"Password","defaultValue":"None","description":"<p>使用此参数指定使用 <strong>UserName</strong> 指定的帐户的密码。</p>\n","name":"UserPassword","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SecureString</span>\n"},{"aliases":"wi","defaultValue":"None","description":"<p>显示在 cmdlet 运行时发生的情况。 cmdlet 不会运行。</p>\n","name":"WhatIf","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">SwitchParameter</span>\n"},{"aliases":"StartIn","defaultValue":"None","description":"<p>指定启动命令的文件夹。 此路径最多可包含 127 个字符。</p>\n","name":"WorkingDirectory","parameterValueGroup":"","position":"Named","type":"<span class=\"no-loc xref\">String</span>\n"}],"schema":"PowershellCmdlet","summary":"<p>在任务序列中创建 <strong>“运行 PowerShell 脚本”</strong> 步骤。</p>\n","syntaxes":["New-CMTSStepRunPowerShellScript -Name <String> [-SuccessCode <Int32[]>] [-Condition <IResultObject[]>]\n [-ContinueOnError] [-Description <String>] [-Disable] [-DisableWildcardHandling] [-ForceWildcardHandling]\n [-WhatIf] [-Confirm] [<CommonParameters>]","New-CMTSStepRunPowerShellScript [-ExecutionPolicy <ExecutionPolicyType>] -Name <String>\n [-OutputVariableName <String>] [-Parameter <String>] -SourceScript <String> [-SuccessCode <Int32[]>]\n [-TimeoutMins <Int32>] [-UserName <String>] [-UserPassword <SecureString>] [-WorkingDirectory <String>]\n [-Condition <IResultObject[]>] [-ContinueOnError] [-Description <String>] [-Disable]\n [-DisableWildcardHandling] [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]","New-CMTSStepRunPowerShellScript [-ExecutionPolicy <ExecutionPolicyType>] -Name <String>\n [-OutputVariableName <String>] -PackageId <String> [-Parameter <String>] -ScriptName <String>\n [-SuccessCode <Int32[]>] [-TimeoutMins <Int32>] [-UserName <String>] [-UserPassword <SecureString>]\n [-WorkingDirectory <String>] [-Condition <IResultObject[]>] [-ContinueOnError] [-Description <String>]\n [-Disable] [-DisableWildcardHandling] [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]"],"uid":"ConfigurationManager.New-CMTSStepRunPowerShellScript","hideEdit":true,"ms.translationtype":"MT","ms.contentlocale":"zh-cn","loc_version":"2024-08-21T21:18:36.7205003Z","loc_source_id":"Github-72476255#live","loc_file_id":"Github-72476255.live.MSDN.sccm-powershell.sccm-ps/ConfigurationManager/New-CMTSStepRunPowerShellScript.md","xrefs":[{"href":"https://learn.microsoft.com/powershell/module/configurationmanager/new-cmtssteprunpowershellscript","monikerGroup":"f98fea35b6ac2b0f56c6ee5ec06ffce9","name":"New-CMTSStepRunPowerShellScript","schemaType":"PowershellCmdlet","summary":"<p>在任务序列中创建 <strong>“运行 PowerShell 脚本”</strong> 步骤。</p>\n","uid":"ConfigurationManager.New-CMTSStepRunPowerShellScript"}],"canonical_url":"https://learn.microsoft.com/zh-cn/powershell/module/configurationmanager/new-cmtssteprunpowershellscript?view=sccm-ps","_op_canonicalUrl":"https://learn.microsoft.com/zh-cn/powershell/module/configurationmanager/new-cmtssteprunpowershellscript?view=sccm-ps"},"pageMetadata":"<meta name=\"description\" content=\"<p>此 cmdlet 创建一个新的 <strong>运行 PowerShell 脚本</strong> 步骤对象。 然后使用 <a href=&quot;add-cmtasksequencestep&quot;>Add-CMTaskSequenceStep</a> cmdlet 将步骤添加到任务序列。 有关此步骤的详细信息，请参阅 <a href=&quot;/mem/configmgr/osd/understand/task-sequence-steps#BKMK_RunPowerShellScript&quot;>关于任务序列步骤：运行 PowerShell 脚本</a>。</p>\n<div class=&quot;NOTE&quot;>\n<p>注意</p>\n<p>从 Configuration Manager 站点驱动器运行 Configuration Manager cmdlet，例如 <code>PS XYZ:\\&amp;gt;</code>。 有关详细信息，请参阅 <a href=&quot;/powershell/sccm/overview&quot;>入门</a>。</p>\n</div>\n\" />\r\n<meta name=\"hideEdit\" content=\"true\" />\r\n<meta name=\"loc_file_id\" content=\"Github-72476255.live.MSDN.sccm-powershell.sccm-ps/ConfigurationManager/New-CMTSStepRunPowerShellScript.md\" />\r\n<meta name=\"loc_source_id\" content=\"Github-72476255#live\" />\r\n<meta name=\"loc_version\" content=\"2024-08-21T21:18:36.7205003Z\" />\r\n<meta name=\"module\" content=\"ConfigurationManager\" />\r\n<meta name=\"ms.contentlocale\" content=\"zh-cn\" />\r\n<meta name=\"ms.translationtype\" content=\"MT\" />\r\n<meta name=\"name\" content=\"New-CMTSStepRunPowerShellScript\" />\r\n<meta name=\"notes\" content=\"<p>有关此返回对象及其属性的详细信息，请参阅 <a href=&quot;/mem/configmgr/develop/reference/osd/sms_tasksequence_runpowershellscriptaction-server-wmi-class&quot;>SMS_TaskSequence_RunPowerShellScriptAction服务器 WMI 类</a>。</p>\n\" />\r\n<meta name=\"schema\" content=\"PowershellCmdlet\" />\r\n<meta name=\"summary\" content=\"<p>在任务序列中创建 <strong>“运行 PowerShell 脚本”</strong> 步骤。</p>\n\" />\r\n<meta name=\"syntaxes\" content=\"New-CMTSStepRunPowerShellScript -Name <String> [-SuccessCode <Int32[]>] [-Condition <IResultObject[]>]\n [-ContinueOnError] [-Description <String>] [-Disable] [-DisableWildcardHandling] [-ForceWildcardHandling]\n [-WhatIf] [-Confirm] [<CommonParameters>]\" />\r\n<meta name=\"syntaxes\" content=\"New-CMTSStepRunPowerShellScript [-ExecutionPolicy <ExecutionPolicyType>] -Name <String>\n [-OutputVariableName <String>] [-Parameter <String>] -SourceScript <String> [-SuccessCode <Int32[]>]\n [-TimeoutMins <Int32>] [-UserName <String>] [-UserPassword <SecureString>] [-WorkingDirectory <String>]\n [-Condition <IResultObject[]>] [-ContinueOnError] [-Description <String>] [-Disable]\n [-DisableWildcardHandling] [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]\" />\r\n<meta name=\"syntaxes\" content=\"New-CMTSStepRunPowerShellScript [-ExecutionPolicy <ExecutionPolicyType>] -Name <String>\n [-OutputVariableName <String>] -PackageId <String> [-Parameter <String>] -ScriptName <String>\n [-SuccessCode <Int32[]>] [-TimeoutMins <Int32>] [-UserName <String>] [-UserPassword <SecureString>]\n [-WorkingDirectory <String>] [-Condition <IResultObject[]>] [-ContinueOnError] [-Description <String>]\n [-Disable] [-DisableWildcardHandling] [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]\" />\r\n<meta name=\"uid\" content=\"ConfigurationManager.New-CMTSStepRunPowerShellScript\" />\r\n","themesRelativePathToOutputRoot":"_themes/"}