There are several syntax error in your post, in that param block. There are not any commas after
param
(
[Parameter()]
[uint32]$Inactive = 90,
[Parameter()]
[switch]$Disable,
[Parameter()]
[switch]$Move
[Parameter()]
[switch]$Expired
[Parameter()]
[switch]$NoLogon
[Parameter()]
[switch]$DisabledAccounts
)
Should be this…
param
(
[Parameter()]
[uint32]$Inactive = 90,
[Parameter()]
[switch]$Disable,
[Parameter()]
[switch]$Move,
[Parameter()]
[switch]$Expired,
[Parameter()]
[switch]$NoLogon,
[Parameter()]
[switch]$DisabledAccounts
)
… and the use case you are after does not fit this.
Consider this…
1 - First change the function name. Since you are setting states on the object not just getting. Suggestion:
# using one of the approved verbs
Get-Verb | Sort-Object -Property Verb
Verb Group
---- -----
Add Common
Resume Lifecycle
Restart Lifecycle
Request Lifecycle
…
Request-InactiveUser
2 - Second is you are passing multiple switches, then this if/elseif is not a thing as the first true response wins, by design, that is how conditional statements work.
3 - Some of the combinations, you appear to want to be able to use, is really a logic error as well.
Request-InactiveUser
{
[CmdletBinding()]
[Alias('siu')]
param
(
# Just by the name,, this is filter condition
[Parameter()]
[uint32]$Inactive = 90,
# Just by the name, this is an action
[Parameter()]
[switch]$Disable,
# Just by the name, this is an action
[Parameter()]
[switch]$Move,
### Which means maybe, it should be one or the other, not both.
# Just by the name, this is an state
[Parameter()]
[switch]$Expired,
# Just by the name, this is a state
[Parameter()]
[switch]$NoLogon,
# Just by the name, this is filter condition
[Parameter()]
[switch]$DisabledAccounts
)
}
You need to think this out more. Meaning, what condition(s)/filter(s) to you want to check, and what combinations are really valid based on actions or end state to be determined. So, before write any real code, Pseudo this out based on use case you imagine., then construct your code to meet each use case. For example:
Use case 1
Check for inactive user within a given set of days
Use case 2
Check for inactive user within a given set of days, that are also disabled accounts - which is really a misnomer, if they are disabled then of course they are inactive.
Use case 3
Check for inactive user account disabled in a target date range.
Use case 4
Check for users who have not logged on in a target date range. Nologon
Use case 5
Check for users who have not logged on in a target date range, disable and potentially move the account
… etc.
So, all-in-all, when you do this evaluation, this may be should not be all in one function.