简体   繁体   English

在日期 powershell 中设置特定日期

[英]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.我正在创建一个自动脚本来为 Azure 应用程序生成一个新的一年客户端密码,并希望将客户端密码的 EndDateTime 设置为始终为自结束日期起一年的第一个月以保持一致性。 Example, the client secret for an app ends on 8/15/2022.例如,应用程序的客户端密码在 2022 年 8 月 15 日结束。 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)当我运行以下脚本来创建新的客户端密码时,我希望结束日期为 2023 年 9 月 1 日(一年后和下个月的第一天)

$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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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