Get Current Month and Time

Copper Contributor

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



2 Replies

@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

@ezflow you could also try 

 $UTCDate = "{0:MMMM@HHmm}"-f (get-date).ToUniversalTime()