DJ Mogarych
29-11-2022, 18:01
Привет!
Подскажите, как заменить команду в функции по условию. У меня отчёт по Exchange, и надо поменять команду в зависимости от того, обычная это группа рассылки или динамическая.
Идея такая:
function Get-ExtendedPerms ($value) {
$command = if ($value.recipienttype -match "dynamic") {"Get-DynamicDistributionGroup $($value.name)"} else {"Get-DistributionGroup $($value.name)"}
($command | Get-ADPermission |
? {$_.isInherited -eq $false -and $_.ExtendedRights -and $_.user -notmatch "Authenticated Users"} |% {
($_.user -replace "^.*?\\") + ' (' + $_.ExtendedRights + ')'
} |sort) -join ", "
}
Просто большая часть команды одна и та же, хочется заменить только часть, а не дублировать её всю целиком.
$command просто так как строка не вставляется, ошибка следующая:
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipel
ine input.
+ CategoryInfo : InvalidArgument: (Get-DistributionGroup DG-test:PSObject) [Get-ADPermission], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Get-ADPermission
+ PSComputerName : srv-mail3.example.com
Тип выдаёт
($command).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
Но в строку переделать не получается никаким из способов ниже:
$command -as [string]
$command |out-string
[string]$command
Заранее спасибо!
Подскажите, как заменить команду в функции по условию. У меня отчёт по Exchange, и надо поменять команду в зависимости от того, обычная это группа рассылки или динамическая.
Идея такая:
function Get-ExtendedPerms ($value) {
$command = if ($value.recipienttype -match "dynamic") {"Get-DynamicDistributionGroup $($value.name)"} else {"Get-DistributionGroup $($value.name)"}
($command | Get-ADPermission |
? {$_.isInherited -eq $false -and $_.ExtendedRights -and $_.user -notmatch "Authenticated Users"} |% {
($_.user -replace "^.*?\\") + ' (' + $_.ExtendedRights + ')'
} |sort) -join ", "
}
Просто большая часть команды одна и та же, хочется заменить только часть, а не дублировать её всю целиком.
$command просто так как строка не вставляется, ошибка следующая:
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipel
ine input.
+ CategoryInfo : InvalidArgument: (Get-DistributionGroup DG-test:PSObject) [Get-ADPermission], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Get-ADPermission
+ PSComputerName : srv-mail3.example.com
Тип выдаёт
($command).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
Но в строку переделать не получается никаким из способов ниже:
$command -as [string]
$command |out-string
[string]$command
Заранее спасибо!