我正在尝试编写一个脚本,如果许可证在到期后30天内,该脚本会提醒我。这将监视100个许可证,并在其中写入带有许可证名称和到期日期的输出。我目前有下面的脚本,但我不怎么匹配$ DateExp2和$ licenseofstring1的输出,并且仅列出$ dateExpo2的输出都在$ date的30天内
$date = get-date -date $(get-date).adddays(30) -format "yyyyMMdd"
Get-ChildItem -Path "C:\PA-LICENSES" -File -Recurse -exclude _AllResults |
ForEach-Object {$expirydate } {
$expiryDate = $_ | Select-String -pattern "Expires: " | Select-String -pattern "Never" -notMatch
$expiryFeature = $_| Select-String -pattern "Feature" | Select-String -pattern "PA-VM" -notMatch | Select-String -pattern "Decryption Port Mirror" -notMatch
foreach ($expiry in $expiryDate) {
$split=$expiry -split "Expires: "
$dateofstring1=$split.split(':')[-1]
$DateExp1=[datetime]"$dateofstring1"
$DateExp2=($DateExp1).ToString('yyyyMMdd')
}
foreach ($license in $expiryFeature) {
$split1=$license -split "Feature: "
$licenseofstring1=$split1.split(':')[-1]
}