您可以创建如下所示的函数并将其放入 .psm1 中,然后将其作为模块导入或导入 .ps1 并将其点源到您的会话中。然后你可以像我在下面显示的那样调用这个函数。请注意,您可能需要添加一些错误处理。
function Set-CustomDistributionGroup
{
[CmdletBinding()]
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
[ValidateNotNullorEmpty()]
[Alias('DistributionGroupName')]
[String] $Name,
[Parameter(
Position = 1,
Mandatory = $true
)]
[ValidateNotNullorEmpty()]
[Alias('DistributionGroupDisplayName')]
[String] $DisplayName,
[Parameter(
Position = 2,
Mandatory = $true
)]
[ValidateNotNullorEmpty()]
[Alias('DistributionGroupAlias')]
[String] $Alias,
[Parameter(
Position = 3,
Mandatory = $true
)]
[ValidateNotNullorEmpty()]
[Alias('DistributionGroupPrimarySmtpAddress')]
[String] $PrimarySmtpAddress,
[Parameter(
Position = 4,
Mandatory = $true
)]
[ValidateNotNullorEmpty()]
[Alias('DistributionGroupManagedBy')]
[String] $ManagedBy
)
process
{
# General
New-DistributionGroup -Name $Name -DisplayName $DisplayName -Alias $Alias -PrimarySmtpAddress $PrimarySmtpAddress
# Ownership
Set-DistributionGroup -Identity $Name –ManagedBy $ManagedBy -BypassSecurityGroupManagerCheck
# Membership approval
Get-DistributionGroup | Set-DistributionGroup -MemberJoinRestriction:closed -MemberDepartRestriction:closed
# Delivery Management
Set-DistributionGroup -Identity $Name -RequireSenderAuthenticationEnabled $False
}
}
然后像这样调用它:
Set-CustomDistributionGroup -Name 'dis_its3' -DisplayName 'dis_its3' -Alias 'dis_its3' -PrimarySmtpAddress 'jackson.k12.ms.us' -ManagedBy 'Robinson Mykal'
但是我会小心这个电话,因为你没有指定要得到什么。许多 powershell cmdlet 只会返回所有内容,最终效果是您更新所有这些。
# Membership approval
Get-DistributionGroup | Set-DistributionGroup -MemberJoinRestriction:closed -MemberDepartRestriction:closed