0
文字列の値に基づいてADオブジェクト名を生成するGet-MatrixADNamesHC
と、これらの値を使用して新しいオブジェクトを作成するもう1つの関数Get-MatrixPermissionsHC
という2つの関数があります。ネストされたプロパティを取得することはできません
問題は、値を$Obj.ADObject
に保存しているようです。 Debugger
の1つの理由または他の理由により、ステップスルーしている間、正しい値を見つけて設定することがわかります。しかし、プロパティADObject
の結果をチェックすると、この値は空です。
コード:私はADObject.Input
またはADObject.Name
の値を取得するように見えることはできませんしてみてくださいどのような
Function Get-MatrixADNamesHC {
[CmdLetBinding()]
Param (
[Parameter(Mandatory)]
[ValidateCount(3,9999)]
[Array]$Matrix,
[Parameter(Mandatory)]
[String]$Begin,
[Parameter(Mandatory)]
[String]$Middle,
[ValidateNotNullOrEmpty()]
[String]$BeginTemplate = 'GroupName',
[ValidateNotNullOrEmpty()]
[String]$MiddleTemplate = 'SiteCode'
)
Process {
Try {
$Matrix | Select-Object -Index 2 | Get-Member | where {
($_.Name -ne ($Matrix[0].PSObject.Properties).Name[0]) -and
($_.MemberType -EQ 'NoteProperty')} | ForEach-Object {
$Header = $_.Name
$Value = $Matrix.($_.Name)
$End = $Matrix[0].($_.Name)
$SamAccountName = $null
$BeginResult = Switch ($Value[2]) {
$BeginTemplate {$Begin + ' ' ;break}
'' {break}
Default {$Value[2] + ' '}
}
$MiddleResult = Switch ($Value[1]) {
$MiddleTemplate {$Middle + ' ' ;break}
'' {break}
Default {$Value[1] + ' '}
}
if ($BeginResult -or $MiddleResult -or $End) {
$SamAccountName = ($BeginResult + $MiddleResult + $End).Trim()
}
Write-Verbose "Generated from the matrix AD Name '$SamAccountName'"
[PSCustomObject]@{
Path = $_.Name
Name = $SamAccountName
Input = [PSCustomObject]@{
Begin = $Value[2]
Middle = $Value[1]
End = $End
}
}
}
}
Catch {
throw "Failed generating the correct AD Name for $BeginTemplate '$Begin' and $MiddleTemplate '$Middle': $_"
}
}
}
Function Get-MatrixPermissionsHC {
[CmdletBinding()]
Param (
[parameter(Mandatory)]
[Array]$Matrix,
[parameter(Mandatory)]
[String]$GroupName,
[parameter(Mandatory)]
[String]$SiteCode
)
Process {
Try {
$ADObjectParams = @{
Begin = $GroupName
Middle = $SiteCode
Matrix = $Matrix
}
$ADObjects = Get-MatrixADNamesHC @ADObjectParams
foreach ($M in ($Matrix | Select-Object -Skip 3)) {
$Obj = [PSCustomObject]@{
Path = if ($M.P1) {($M.P1).Trim('\', ' ')} else {$null}
ADObject = $null
ACE = $null
Parent = $false
}
if (-not $FirstTimeThrough) {
$FirstTimeThrough = $true
$Obj.Parent = $true
}
$M | Get-Member | where {($_.Name -ne ($Matrix[0].PSObject.Properties).Name[0]) -and
($_.MemberType -EQ 'NoteProperty')} | ForEach-Object {
$Obj.ADObject = $ADObjects | where Path -eq $_.Name | Select Name, Input
$Obj.ACE = $M.($_.Name)
$Obj
Write-Verbose "Permission '$($Obj.ACE)' on '$($Obj.Path)' for '$($Obj.ADObject.Name)'"
}
}
}
Catch {
throw "Failed getting the permissions from the matrix with GroupName '$GroupName' and SiteCode '$SiteCode': $_"
}
}
}
$Matrix = @(
[PSCustomOBject]@{
P1 = 'R Read/W Write'
P2 = 'Manager'
P3 = 'Directors'
P4 = ''
P5 = 'All users'
P6 = 'cnorris'
P7 = 'Support staff'
P8 = ''
}
[PSCustomOBject]@{
P1 = 'SiteCode'
P2 = 'SiteCode'
P3 = 'SiteCode'
P4 = 'camerica'
P5 = ''
P6 = $null
P7 = ''
P8 = ''
}
[PSCustomOBject]@{
P1 = 'GroupName'
P2 = 'GroupName'
P3 = 'BEL TEAM'
P4 = ''
P5 = 'GroupName'
P6 = ''
P7 = 'BEL ROL-STAFF-IT'
P8 = ''
}
[PSCustomOBject]@{
P1 = 'Path'
P2 = 'L'
P3 = 'L'
P4 = 'L'
P5 = 'L'
P6 = 'L'
P7 = 'L'
P8 = 'L'
}
)
$Test = Get-MatrixPermissionsHC -Matrix $Matrix -GroupName 'BEL ROL-TEAM' -SiteCode 'Logistics' -Verbose
$Test
$Test.ADObject.Name
$Test.ADObject.Input
$Test[0] | fl *
$Test[0].ADObject.Input | fl *
。私は非常に明白な何かを見逃しているかもしれないが、私はそれを見ることができない。