1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
Function Set-OSCLogonHours
{
<#
repris du script de
https://gallery.technet.microsoft.com/scriptcenter/How-to-set-Users-Logon-1bb4b1a2
merci a l'equipe OneScript Team
.SYNOPSIS
Set-OSCLogonHours is an advanced function which can be used to set active directory user's logon time.
.DESCRIPTION
Set-OSCLogonHours is an advanced function which can be used to set active directory user's logon time.
.PARAMETER DayofWeek
Specifies le/les jours au format 3 lettres
.PARAMETER From
Specifies l'heure de debut au format 24h (de 0 à 23h) .
.PARAMETER To
Specifies l'heure de fin (heure inclu).
.EXAMPLE
C:\PS> Set-OSCLogonHours -DayofWeek Mar,Mer,Jeu,Ven,Sam -From 8h -To 20h
du lundi au samedi de 8h à 20h
.EXAMPLE
C:\PS> Set-OSCLogonHours -DayofWeek Mer,Ven -From 14h -To 22h
le mercredi et le vendredi de 14 à 22h
.EXAMPLE
Set-OSCLogonHours -DayofWeek Lun,Mar,Mer,Jeu,Ven -From 0h -To 23h
du lendi au vendredi de toutes la journée
#>
Param
(
[ValidateSet("Dim","Lun","Mar","Mer","Jeu","Ven","Sam")]
[Alias('day')][String[]]$DayofWeek,
[ValidateSet("0h","1h","2h","3h","4h","5h","6h","7h","8h","9h","10h","11h","12h",
"13h","14h","15h","16h","17h","18h","19h","20h","21h","22h","23h")]
[Alias('f')][String]$From,
[ValidateSet("0h","1h","2h","3h","4h","5h","6h","7h","8h","9h","10h","11h","12h",
"13h","14h","15h","16h","17h","18h","19h","20h","21h","22h","23h")]
[Alias('t')][String]$To
)
$Objs = @()
Foreach($i in 0..23) {
$Obj = New-Object -TypeName PSObject
$Obj | Add-Member -MemberType NoteProperty -Name "position" -Value $([byte]$([math]::pow( 2, ($i%8))))
$Obj | Add-Member -MemberType NoteProperty -Name "octet" -Value $([Math]::Floor($i/8))
$Objs += $Obj
}
$HrsFrom = ($From.Split("h"))[0] - 1
$HrsTo = ($To.Split("h"))[0] - 1
If ($HrsFrom -le $HrsTo) {
[byte[]]$HourBinary = @(0,0,0)
$TimePeriod = $HrsFrom..$($HrsTo)
Foreach ($Time in $TimePeriod) {
$HourBinary[$Objs[$time].octet] += $Objs[$time].position
}
#Define Initial logon time
$HoursBinary = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
#Iterating replace the specified value
Foreach ($day in $DayofWeek) {
Switch ($day) {
"Dim" {$HoursBinary[1],$HoursBinary[2],$HoursBinary[3] = $HourBinary[0],$HourBinary[1],$HourBinary[2];Break}
"Lun" {$HoursBinary[4],$HoursBinary[5],$HoursBinary[6] = $HourBinary[0],$HourBinary[1],$HourBinary[2];Break}
"Mar" {$HoursBinary[7],$HoursBinary[8],$HoursBinary[9] = $HourBinary[0],$HourBinary[1],$HourBinary[2];Break}
"Mer" {$HoursBinary[10],$HoursBinary[11],$HoursBinary[12] = $HourBinary[0],$HourBinary[1],$HourBinary[2];Break}
"Jeu" {$HoursBinary[13],$HoursBinary[14],$HoursBinary[15] = $HourBinary[0],$HourBinary[1],$HourBinary[2];Break}
"Ven" {$HoursBinary[16],$HoursBinary[17],$HoursBinary[18] = $HourBinary[0],$HourBinary[1],$HourBinary[2];Break}
"Sam" {$HoursBinary[19],$HoursBinary[20],$HoursBinary[0] = $HourBinary[0],$HourBinary[1],$HourBinary[2];Break}
}
}
}
$HoursBinary
} |
Partager