Last active
November 14, 2016 17:38
-
-
Save FooBartn/916d9f15bc6667b837befa8e33508edb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-RDCManFile () { | |
param ( | |
# AD Group Names | |
[Parameter(Mandatory=$true)] | |
[string[]] | |
$ADGroupName, | |
# Output File | |
[Parameter(Mandatory=$false)] | |
[string] | |
$OutputFile = '.\MyRDCFile.rdg' | |
) | |
Begin { | |
# Get XML template | |
$RdcXmlTemplatePath = Join-Path -Path $PSScriptRoot -ChildPath 'RCTemplate.xml' | |
[xml]$RdcXml = Get-Content $RdcXmlTemplatePath | |
$FileElement = $RdcXml.RDCMan.file | |
$FileProperties = $FileElement.properties | |
$GroupTemplate = $RdcXml.RDCMan.file.group | |
$ServerTemplate = $RdcXml.RDCMan.file.group.server | |
# Update file properties | |
$FileProperties.name = $env:userdomain | |
$FileProperties.logonCredentials.Username = $env:username | |
$FileProperties.logonCredentials.Domain = $env:userdomain | |
} Process { | |
foreach ($ADGroup in $ADGroupName) { | |
# Add Group | |
$NewGroup = $GroupTemplate.Clone() | |
$NewGroup.properties.name = $ADGroup | |
$FileElement.AppendChild($NewGroup) | |
# Add Servers | |
Get-ADComputer -LDAPFilter "(operatingsystem=*server*)" | | |
Where-Object { | |
$_.DistinguishedName -Match "$ADGroup" | |
} | | |
ForEach-Object { | |
$NewServer = $ServerTemplate.Clone() | |
$NewServer.DisplayName = $_.Name | |
$NewServer.Name = $_.DNSHostName | |
$NewGroup.AppendChild($NewServer) | |
} | |
} | |
} End { | |
$FileElement.RemoveChild($GroupTemplate) | |
$FileElement.RemoveChild($ServerTemplate) | |
$RdcXml.Save($OutputFile) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment