【发布时间】:2022-10-07 21:21:51
【问题描述】:
我的 Powershell 脚本接收多个 Microsoft Office365 DSC 策略配置策略文件作为文件夹中的输入,如下所示:
文件1.ps1
Configuration EXOSharingPolicy {
param (
[parameter()]
[System.Management.Automation.PSCredential]
$GlobalAdmin
)
if ($null -eq $GlobalAdmin) {
<# Credentials #>
$GlobalAdmin = Get-Credential -Message "Credentials"
}
else {
$Credential = $GlobalAdmin
}
$OrganizationName = $Credential.UserName.Split('@')[1]
Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.22.907.1'
Node localhost
{
EXOSharingPolicy 8b39ae5a-f4ed-4bdb-932d-fbb9397f7fc6
{
Credential = $Credential;
Default = $True;
Domains = @("Anonymous:CalendarSharingFreeBusyReviewer");
Enabled = $True;
Ensure = "Present";
Name = "Default Sharing Policy";
}
}
}
文件2.ps1
Configuration AADTenantDetails {
param (
[parameter()]
[System.Management.Automation.PSCredential]
$GlobalAdmin
)
if ($null -eq $GlobalAdmin) {
<# Credentials #>
$GlobalAdmin = Get-Credential -Message "Credentials"
}
else {
$Credential = $GlobalAdmin
}
$OrganizationName = $Credential.UserName.Split('@')[1]
Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.22.907.1'
Node localhost
{
AADTenantDetails 5cfcabd5-9c82-4bed-9934-09e1cf20c71b
{
Credential = $Credential;
IsSingleInstance = "Yes";
MarketingNotificationEmails = @();
SecurityComplianceNotificationMails = @();
SecurityComplianceNotificationPhones = @();
TechnicalNotificationMails = @("admin@tech.net.au");
}
}
}
文件3.ps1
Configuration EXOEmailAddressPolicy {
param (
[parameter()]
[System.Management.Automation.PSCredential]
$GlobalAdmin
)
if ($null -eq $GlobalAdmin) {
<# Credentials #>
$GlobalAdmin = Get-Credential -Message "Credentials"
}
else {
$Credential = $GlobalAdmin
}
$OrganizationName = $Credential.UserName.Split('@')[1]
Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.22.907.1'
Node localhost
{
EXOEmailAddressPolicy a2188f3f-80d5-419c-b229-063fc2c18dbf
{
Credential = $Credential;
EnabledEmailAddressTemplates = @("SMTP:@$OrganizationName");
EnabledPrimarySMTPAddressTemplate = "@$OrganizationName";
Ensure = "Present";
ManagedByFilter = "";
Name = "Default Policy";
Priority = "Lowest";
}
}
}
我有几个这样的配置文件。 powershell 中是否有一种方法可以组合/合并这些文件,所以我最终得到一个具有所有配置的文件,如下所示。
Configuration CombinedPolicy {
param (
[parameter()]
[System.Management.Automation.PSCredential]
$GlobalAdmin
)
if ($null -eq $GlobalAdmin) {
<# Credentials #>
$GlobalAdmin = Get-Credential -Message "Credentials"
}
else {
$Credential = $GlobalAdmin
}
$OrganizationName = $Credential.UserName.Split('@')[1]
Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.22.907.1'
Node localhost
{
EXOSharingPolicy 8b39ae5a-f4ed-4bdb-932d-fbb9397f7fc6
{
Credential = $Credential;
Default = $True;
Domains = @("Anonymous:CalendarSharingFreeBusyReviewer");
Enabled = $True;
Ensure = "Present";
Name = "Default Sharing Policy";
}
AADTenantDetails 5cfcabd5-9c82-4bed-9934-09e1cf20c71b
{
Credential = $Credential;
IsSingleInstance = "Yes";
MarketingNotificationEmails = @();
SecurityComplianceNotificationMails = @();
SecurityComplianceNotificationPhones = @();
TechnicalNotificationMails = @("jarrod@j-tech.net.au");
}
EXOEmailAddressPolicy a2188f3f-80d5-419c-b229-063fc2c18dbf
{
Credential = $Credential;
EnabledEmailAddressTemplates = @("SMTP:@$OrganizationName");
EnabledPrimarySMTPAddressTemplate = "@$OrganizationName";
Ensure = "Present";
ManagedByFilter = "";
Name = "Default Policy";
Priority = "Lowest";
}
}
}
因此,在合并的配置文件中,我只需要合并每个单独的配置文件中的 Node localhost 下的部分,而不是合并整个文件内容。
我需要这个,以便我可以一次将所有 DSC 配置应用到 Office 365 租赁,而不是应用单独的配置。
希望这是有道理的。
【问题讨论】:
标签: powershell office365 dsc