Forum Discussion

ezflow's avatar
ezflow
Copper Contributor
Oct 07, 2022

Get Current Month and Time

Hi,
We are automating user creation in the AD (on Prem). For the password field we want the following
to be capture in powershell in the following  formatt: Month@HourMinunte  or October@945 
I want to pass it as a variable and not hardcoded
 
$dstPassword = "October@945 " | ConvertTo-SecureString



  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    ezflow 

     

    $Months = @("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    $Timestamp = [datetime]::UtcNow;
    $dstPassword = "$($Months[$Timestamp.Month - 1])@$($Timestamp.ToString('hmm'))" | ConvertTo-SecureString -AsPlainText -Force;

     

    Cheers,

    Lain

Resources