누군가가 내게 도움이되기를 바랍니다. 현재 날짜와 파일이 만들어진 날짜를 비교하는 데 문제가 있습니다. 각 날짜의 출력은 내 코드와 함께 아래에 있습니다.생성 날짜와 현재 날짜를 비교하는 데 문제가 없습니다
만든 날짜 출력 :
21/05/2012 오후 10시 27분 25초
현재 날짜 출력 :
2013년 8월 5일 12:00 00 AM
이 날짜를 비교할 수 있습니까?
$host = Read-Host 'Host: '
$username = Read-Host 'Username: '
$password = Read-Host 'Password: '
Connect-VIServer -Server $host -User $username -Password $password
$snapshotDate = Get-Snapshot -VM CONVCORPSPOINT | Select-Object Created | Format-Table -HideTableHeaders
$currentDate = Get-Date | Select-Object Date | Format-Table -HideTableHeaders
$snapshotDate
$currentDate
if ($snapshotDate -lt $currentDate) {
Write-Host 'The snapshot date is earlier than the current date'
}
else {
Write-Host 'The snapshot date is not earlier than the current date'
}
감사 :
또는 명시 적으로 짧은 먹은 문자열에 대해 비교하여
. 필자는 표준 powershell 문과 함께 작동하는 방법을 볼 수 있지만 get-snapshot에서 반환 된 날짜가 VMware의 PowerCLI에만 관련되어 있으며 날짜를 문자열로 변환하는 것이 작동하지 않는다는 것을 언급하지 않았습니다.). 나는 이것을 답으로 표시 할 것이다. – cvandal