Functions/Get-DryADDomainProperty.ps1
Using NameSpace System.Management.Automation.Runspaces # DryActiveDirectory is an AD config module for use with DryDeploy, or by itself. # # Copyright (C) 2021 Bjørn Henrik Formo (bjornhenrikformo@gmail.com) # LICENSE: https://raw.githubusercontent.com/bjoernf73/DryActiveDirectory/main/LICENSE # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Function Get-DryADDomainProperty { [CmdletBinding(DefaultParameterSetName='Local')] Param ( [Parameter(Mandatory,HelpMessage="The property to get")] [String] $Property, [Parameter(Mandatory,ParameterSetName='Remote', HelpMessage="PSSession to run the script blocks in")] [PSSession] $PSSession, [Parameter(Mandatory,ParameterSetName='Local', HelpMessage="For 'Local' sessions, specify the Domain Controller to use")] [String] $DomainController ) Try { If ($PSCmdlet.ParameterSetName -eq 'Remote') { $Server = 'localhost' } Else { $Server = $DomainController } $ArgumentList = @($Property,$Server) $InvokeParams = @{ ScriptBlock = $DryAD_SB_ADDomainProperty_Get ArgumentList = $ArgumentList } If ($PSCmdlet.ParameterSetName -eq 'Remote') { $InvokeParams += @{ Session = $PSSession } } $Return = $Null; $Return = Invoke-Command @InvokeParams If ($Return -is [ErrorRecord]) { Throw $Return } Else { Return $Return } } Catch { $PSCmdlet.ThrowTerminatingError($_) } } |