#Requires -Version <N>[.<n>] #Requires -Modules { <Module-Name> | <Hashtable> } #Requires -PSEdition <PSEdition-Name> #Requires -RunAsAdministrator 有关语法的详细信息,请见 ScriptRequirements。 使用规则 一个脚本可以包含多个 #Requires 语句。 #Requires 语句可以出现在脚本中的任何一行上。 在...
有关详细信息,请参阅about_Requires。 $PSCommandPath- 包含正在运行的脚本的完整路径和名称。 此参数在所有脚本中都有效。 PowerShell 3.0 中引入了此自动变量。 $PSScriptRoot- 包含从中运行脚本的目录。 在 PowerShell 2.0 中,此变量仅在) (.psm1脚本模块中有效。 从 PowerShell 3.0 开始,它在所有脚本中都有...
script now supports the following features: Feature 1 Feature 2 Feature 3 Feature 4 Feature 5 .PRIVATEDATA #> #Requires -Module 1 #Requires -Module 2 #Requires -Module RequiredModule1 #Requires -Module @{ModuleName = 'RequiredModule2'; ModuleVersion = '1.0'} #Requires -Module @{Required...
如果未配置此策略设置,则每个模块的LogPipelineExecutionDetails属性将确定 PowerShell 是否记录该模块的执行事件。 默认情况下,所有模块的LogPipelineExecutionDetails属性设置为$False。 若要为模块启用模块日志记录,请使用以下命令格式。 模块必须导入到会话中,并且设置仅在当前会话中有效。 PowerShell复制 Import-Mod...
#Requires 的新Module參數 改善的Import-ModuleCmdlet (包含MinimumVersion與RequiredVersion參數)。 簡化的命令探索 您不需要再匯入所有模組即可探索您的工作階段中可用的命令。 在 Windows PowerShell 3.0 中,Get-CommandCmdlet 會從所有已安裝的模組中取得所有命令。 而且,當您使用命令時,匯出命令的模組就會自動匯入...
Scripts have additional features, such as the#Requiresspecial comment, the use of parameters, support for data sections, and digital signing for security. You can also write Help topics for scripts and for any functions in the script.
In the above case, theFictionalToolsmodule requires a newer version ofMicrosoft.Extensions.Loggingthan theFilesystemManagermodule. Let’s imagine these modules load their dependencies by placing the dependency assemblies in the same directory as the root module assembly and allowing .NET to implicitly ...
Script C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Appx\Appx.psm1 Name: BestPractices Name ModuleType Path --- --- --- BestPractices Manifest C:\Windows\system32\WindowsPowerShell\v1.0\Modules\BestPractices\BestPractices.psd1 Name: BitsTransfer Name ModuleType Path --- --- --- Bits...
Add-ScriptHelpISEAddOn Utils\Add-ScriptHelpISEAddOn.ps1 Function to create an ISE Add-On that will generate comment based help for functions. The functions requires the Show-UI module. Link Link ConvertFrom-ExcelClipboard Utils\ConvertFrom-ExcelClipboard.ps1 Convert copied range from excel to an ar...
PowerShell 复制 New-Module -Script {function SayHello {"Hello!"}; Set-Alias Hi SayHello; Export-ModuleMember -Alias Hi -Function SayHello}此命令演示如何在使用 New-Module cmdlet 创建的动态模块中使用 Export-ModuleMember。在此示例中,Export-ModuleMember 用于导出动态模块中的 Hi 别名和 SayHello 函数。