简体   繁体   中英

Setting a specific day in the date powershell

I am creating an automated script to generate a new one year client secret for Azure apps and want to set the EndDateTime for the client secret to always be the first of the month one year from the end date for consistency. Example, the client secret for an app ends on 8/15/2022. When I run the following script to create a new client secret, I'd like the end date to be 9/1/2023 ( one year later and the first day of the following month)

$pwCred=@{
"EndDateTime"=(Get-Date).AddDays(365) #  <-- want this to be day 1 of the next month 1 year from the enddatetime
"displayName"="Test Auto Cert2" 
}

$Secret = Add-MgApplicationPassword -ApplicationId XYZ-XYZ-XYZ-XYZ -PasswordCredential $pwCred

Just an example ...

$GivenDate = Get-Date -Day 11 -Month 12 -Year 2022
$FirstOfNextMonth = $GivenDate.AddDays(- $GivenDate.Day + 1 ).AddMonths(1)
$FirstOfNextMonthNextYear = $FirstOfNextMonth.AddYears(1)

$GivenDate
$FirstOfNextMonth
$FirstOfNextMonthNextYear

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM