以下のスクリプトでは、-liveまたは-testパラメーターのいずれかが必要です。ただし、スクリプトはどちらのスイッチも使用せずに実行されます。これらのパラメータのいずれかを使用すると、以下のエラーが発生します。-liveまたは-testのいずれかを必要としないのはなぜですか?また、それらのいずれかを使用すると失敗するのはなぜですか?
C:\ Users \ Administrator \ Documents \ Disable-ADAccounts.ps1:指定された名前付きパラメーターを使用してパラメーターセットを解決できません。行:1文字:1+。。\ Disable-ADAccounts.ps1 -days 7 -all -live + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ + CategoryInfo:InvalidArgument :( :) [Disable-ADAccounts.ps1]、ParameterBindingException + FullyQualifiedErrorId:AmbiguousParameterSet、Disable-ADAccounts.ps1
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnly')]
[Switch]
$usersOnly,
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnly')]
[Switch]
$computersOnly,
[Parameter(Mandatory = $true, ParameterSetName = 'All')]
[Switch]
$all,
[Parameter(Mandatory=$true)]
[string]
$days,
[switch]
$console,
[Parameter(Mandatory = $true, ParameterSetName = 'Test')]
[switch]
$test,
[Parameter(Mandatory = $true, ParameterSetName = 'Live')]
[switch]
$live
)
Process {
$DC = Get-ADDomainController
$OUs = Get-ADOrganizationalUnit -Filter * # Uncomment this line to search ALL OUs. Comment Next Variable.
#$OUs = Get-ADOrganizationalUnit -Filter 'Name -eq "test"' # Use this line to test on a single OU
$TimeStamp = get-date -format D
$description = "Disabled on " + $TimeStamp
$noDisableComputer = Get-ADGroupMember -Identity DoNotDisableComputers -Recursive | Select -ExpandProperty Name
$noDisableUser = Get-ADGroupMember -Identity DoNotDisableUsers -Recursive | Select -ExpandProperty Name
$noDisable = $noDisableComputer+$noDisableUser
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('yyMMdd_hhmmss')
$tempDir = [System.Environment]::GetEnvironmentVariable('TEMP','Machine')
$logFile = $tempDir + "\DisabledAccounts_$CurrentDate.csv"
# If -test switch is used enable -WhatIf parameter.
If($test) { $whatIf = @{ WhatIf = $true } }
ElseIf($live) { $whatIf = @{ WhatIf = $false } }
# Set parameter to UsersOnly, ComputersOnly, or do not use a perameter
If($usersOnly) { $scope = @{ UsersOnly = $true } }
ElseIf($computersOnly) { $scope = @{ ComputersOnly =$true } }
ElseIf($all) { $scope = @{} }
# Disable User and/or Computer Objects inactive for XX days.
# Iterate through Organizational Units
foreach ($OU in $OUs) {
# Search for User and/or Computer Objects inactive for XX days. Disable object if not in DoNotDisable Security Groups
$days = $days + "D"
$accounts = Search-ADAccount -SearchBase $OU.DistinguishedName -SearchScope OneLevel -AccountInactive -TimeSpan ([timespan]7D) @scope
foreach($account in $accounts){
If ($noDisable -notcontains $account.Name) {
Write-Host $account
# #Disable-ADAccount -Identity $account.DistinguishedName -Verbose $whatIf | Export-Csv $logFile
}
}
}
}
# Move Disabled Users to Disabled Users OU & Add Timestamp to Description
#Search-ADAccount –AccountDisabled –ComputersOnly –SearchBase $OU.DistinguishedName | Foreach-object {
#Set-ADComputer $_ -Description $description -Verbose -WhatIf
#Move-ADObject $_ –TargetPath “OU=Disabled Computers, DC=COH,DC=net” -Verbose -WhatIf
#}
#}
パラメータセットについて混乱していると思います。あなたが行ったことは、5つの異なるパラメータセットを作成し、それらの5つのうちの1つだけがいつでもアクティブにできることです。私があなたの意図を正しく読んだ場合、あなたが必要とするのは、次のいずれかを行う能力です。
\Disable-ADAccounts.ps1 -days 7 -all -live
\Disable-ADAccounts.ps1 -days 7 -UsersOnly -live
\Disable-ADAccounts.ps1 -days 7 -ComputersOnly -live
\Disable-ADAccounts.ps1 -days 7 -all -test
\Disable-ADAccounts.ps1 -days 7 -UsersOnly -test
\Disable-ADAccounts.ps1 -days 7 -ComputersOnly -test
その場合、5つではなく6つの異なるパラメータグループが必要です。各パラメーターは、必要なグループのメンバーである必要があるため、次のようになります。
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyTest')]
[Switch]
$usersOnly,
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyTest')]
[Switch]
$computersOnly,
[Parameter(Mandatory = $true, ParameterSetName = 'AllLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'AllTest')]
[Switch]
$all,
[Parameter(Mandatory=$true)]
[string]
$days,
[switch]
$console,
[Parameter(Mandatory = $true, ParameterSetName = 'AllTest')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyTest')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyTest')]
[switch]
$test,
[Parameter(Mandatory = $true, ParameterSetName = 'AllLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'UsersOnlyLive')]
[Parameter(Mandatory = $true, ParameterSetName = 'ComputersOnlyLive')]
[switch]
$live
パラメータセットの詳細については、このMicrosoftの記事を参照してください。
これがお役に立てば幸いです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加