WFConnectionDate/WFConnectionDate.psm1

<#
.SYNOPSIS
 
Gets the Wi-Fi Profile's Frist Connection date.
 
.DESCRIPTION
 
The Get-WFConnectionDate cmdlet Gives the First connection date of Profile which connected over the Wi-Fi.
 
.EXAMPLE
PS> Get-WFConnectionDate -ProfileName "abcd"
  
The Profile First Connection Date :
Friday , 31 May 2019 , 22 : 32 : 37
 
#>

Function Get-WFConnectionDate {
          [cmdletbinding()]
    param(
        [parameter(mandatory=$true,
                   valuefrompipeline=$true)]
        [string]$ProfileName
    )

    write-host " "
    write-host " The Profile First Connection Date : "
    write-host " "
$x = Get-ItemProperty "HKLM:\\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\*" | where -Property profilename -Like $ProfileName | Get-ItemPropertyValue -name Datecreated

#$x = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\{0814AAE5-6E7D-4847-AFA1-6E8461D26512}" | Get-ItemPropertyValue -name Datecreated

$Count = 0
$string = $null
$val = $null
while($Count -ine $x.count)
{
        $y = "{0:x}" -f $x[$Count]
        [System.Array]$val += $y
    $Count++
}

$Count = 0
$VarStor = $null
while($Count -ine $val.Count){
    
    if ($val[$Count].Length -eq '2'){
        [System.Array]$VarStor += $Val[$Count]
    }

    if ($val[$Count].Length -ne '2'){
        $Var = $val[$Count]
        [System.Array]$VarStor += "0$Var"
    }
    
    $Count++
}

$Count = 0
while ($Count -ne $VarStor.Count){
$string += $VarStor[$Count].ToString()
$Count++
}

    #swaping the values--->

    $swap1 = $string[2]+$string[3]+$string[0]+$string[1]
    $swap2 = $string[6]+$string[7]+$string[4]+$string[5]
    $swap3 = $string[10]+$string[11]+$string[8]+$string[9]
    $swap4 = $string[14]+$string[15]+$string[12]+$string[13]
    $swap5 = $string[18]+$string[19]+$string[16]+$string[17]
    $swap6 = $string[22]+$string[23]+$string[20]+$string[21]
    $swap7 = $string[26]+$string[27]+$string[24]+$string[25] 


    #Finding the Year--->

    [int]$year = "0x$swap1"

    #Finding the month

    [int]$mn = "0x$swap2"

    switch ($mn)
    {
        '1' {$month = "January"}
        '2' {$month = "February"}
        '3' {$month = "March"}
        '4' {$month = "April"}
        '5' {$month = "May"}
        '6' {$month = "June"}
        '7' {$month = "July"}
        '8' {$month = "August"}
        '9' {$month = "September"}
        '10' {$month = "October"}
        '11' {$month = "November"}
        '12' {$month = "December"}
        Default { write-host "The input is not valid" }
    }

    #Finding the Weekday--->

    switch ($swap3[3])
    {
        '0' {$day = "Sunday"}
        '1' {$day = "Monday"}
        '2' {$day = "Tuesday"}
        '3' {$day = "Wednesday"}
        '4' {$day = "Thursday"}
        '5' {$day = "Friday"}
        '6' {$day = "Saturday"}
        '7' {$day = "Sunday"}
        Default { write-host "The input is not valid" }
    }

    #Finding the Date--->

    [int]$Date = "0x$swap4"

    #finding the Time--->

    [int]$Hour = "0x$swap5"
    [int]$Minute = "0x$swap6"
    [int]$Seconds = "0x$swap7"
    $time = "$Hour : $Minute : $Seconds"

    # Writting to host

    write-host " $day , $date $month $year , $time "
}

<#
.SYNOPSIS
 
Gets the Wi-Fi Profile's Last Connection date.
 
.DESCRIPTION
 
The Get-WLConnectionDate cmdlet Gives the Last connection date of Profile which connected over the Wi-Fi.
 
.EXAMPLE
 
PS> Get-WLConnectionDate -ProfileName "abcd"
 
The Profile Last Connection Date :
Sunday , 2 June 2019 , 21 : 53 : 16
#>


Function Get-WLConnectionDate {
          [cmdletbinding()]
    param(
        [parameter(mandatory=$true,
                   valuefrompipeline=$true)]
        [string]$ProfileName
    )

    write-host " "
    write-host " The Profile Last Connection Date : "
    write-host " "
$x = Get-ItemProperty "HKLM:\\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\*" | where -Property profilename -Like $ProfileName | Get-ItemPropertyValue -name DateLastConnected

#$x = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\{0814AAE5-6E7D-4847-AFA1-6E8461D26512}" | Get-ItemPropertyValue -name Datecreated

$Count = 0
$string = $null
$val = $null
while($Count -ine $x.count)
{
        $y = "{0:x}" -f $x[$Count]
        [System.Array]$val += $y
    $Count++
}

$Count = 0
$VarStor = $null
while($Count -ine $val.Count){
    
    if ($val[$Count].Length -eq '2'){
        [System.Array]$VarStor += $Val[$Count]
    }

    if ($val[$Count].Length -ne '2'){
        $Var = $val[$Count]
        [System.Array]$VarStor += "0$Var"
    }
    
    $Count++
}

$Count = 0
while ($Count -ne $VarStor.Count){
$string += $VarStor[$Count].ToString()
$Count++
}

    #swaping the values--->

    $swap1 = $string[2]+$string[3]+$string[0]+$string[1]
    $swap2 = $string[6]+$string[7]+$string[4]+$string[5]
    $swap3 = $string[10]+$string[11]+$string[8]+$string[9]
    $swap4 = $string[14]+$string[15]+$string[12]+$string[13]
    $swap5 = $string[18]+$string[19]+$string[16]+$string[17]
    $swap6 = $string[22]+$string[23]+$string[20]+$string[21]
    $swap7 = $string[26]+$string[27]+$string[24]+$string[25] 


    #Finding the Year--->

    [int]$year = "0x$swap1"

    #Finding the month

    [int]$mn = "0x$swap2"

    switch ($mn)
    {
        '1' {$month = "January"}
        '2' {$month = "February"}
        '3' {$month = "March"}
        '4' {$month = "April"}
        '5' {$month = "May"}
        '6' {$month = "June"}
        '7' {$month = "July"}
        '8' {$month = "August"}
        '9' {$month = "September"}
        '10' {$month = "October"}
        '11' {$month = "November"}
        '12' {$month = "December"}
        Default { write-host "The input is not valid" }
    }

    #Finding the Weekday--->

    switch ($swap3[3])
    {
        '0' {$day = "Sunday"}
        '1' {$day = "Monday"}
        '2' {$day = "Tuesday"}
        '3' {$day = "Wednesday"}
        '4' {$day = "Thursday"}
        '5' {$day = "Friday"}
        '6' {$day = "Saturday"}
        '7' {$day = "Sunday"}
        Default { write-host "The input is not valid" }
    }

    #Finding the Date--->

    [int]$Date = "0x$swap4"

    #finding the Time--->

    [int]$Hour = "0x$swap5"
    [int]$Minute = "0x$swap6"
    [int]$Seconds = "0x$swap7"
    $time = "$Hour : $Minute : $Seconds"

    # Writting to host

    write-host " $day , $date $month $year , $time "
}