【发布时间】:2021-03-25 15:38:57
【问题描述】:
使用如下代码:
param
(
[Parameter(Mandatory = $true)]
[string]$TenantId,
[Parameter(Mandatory = $true)]
[System.Uri]$HostUrl,
[Parameter(Mandatory = $true)]
[string]$SiteId,
[Parameter(Mandatory = $true)]
[guid]$WebId,
[Parameter(Mandatory = $true)]
[guid]$ListId,
[Parameter(Mandatory = $true)]
[guid]$UniqueId,
[Parameter(Mandatory = $true)]
[string]$OutFile
)
Connect-MgGraph -Scopes "Sites.FullControl.All" -TenantId $TenantId -ForceRefresh
Get-MgSiteListItemDriveItemContent -ListId $ListId -ListItemId $UniqueId -SiteId "$($HostUrl.DnsSafeHost),$SiteId,$WebId" -OutFile $OutFile
Disconnect-MgGraph
我希望最终用户知道如何获取所有必需的命名参数,例如在执行这个脚本时,我预计会发生这样的事情
cmdlet at command pipeline position 1
Supply values for the following parameters:
TenantId (to get TenantID go to Admin Center - Settings and copy TenantID): xxx
HostUrl (to get HostUrl copy HostUrl from the log files): yyy-yyy
SiteId (SiteId can be obtained directly in SharePoint site): zzz-zzz-zzz
等等
我知道有一个 HelpMessage 参数,例如
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage="Site name")]
但我希望在最终用户指定值时显示此消息。
【问题讨论】:
-
我想你在问一些类似于这篇文章的东西:stackoverflow.com/questions/5237723/…
标签: powershell named-parameters