Need a PowerShell script to find folders which does not have files modified yesterday
Loop through a text file which contains folder Locations
foreach ($line in Get-Content "C:Backupsample.txt") {
Get-ChildItem $line | Where {
$_.LastWriteTime -gt (Get-Date).AddDays(-1)
} | select Directoryname, Name, LastWriteTime, @{Name="Size (GB)"; Expression={[Math]::Round($_.Length/1MB, 1)}}
}
This way I am only able to get the files that were modified yesterday.
What I want is to list out the folders which does and does not have files modified yesterday.
If a folder contains files that were modified yesterday (modified date as yesterday), then list those File Names, Folder Name and their sizes(GB).
And also Write-Host
as backup successful.
The same should go with folders which does not contain files with the modified date as yesterday.
Write-Host
backup not complete.
powershell compare backup
add a comment |
Loop through a text file which contains folder Locations
foreach ($line in Get-Content "C:Backupsample.txt") {
Get-ChildItem $line | Where {
$_.LastWriteTime -gt (Get-Date).AddDays(-1)
} | select Directoryname, Name, LastWriteTime, @{Name="Size (GB)"; Expression={[Math]::Round($_.Length/1MB, 1)}}
}
This way I am only able to get the files that were modified yesterday.
What I want is to list out the folders which does and does not have files modified yesterday.
If a folder contains files that were modified yesterday (modified date as yesterday), then list those File Names, Folder Name and their sizes(GB).
And also Write-Host
as backup successful.
The same should go with folders which does not contain files with the modified date as yesterday.
Write-Host
backup not complete.
powershell compare backup
just invert thewhere
condition:-lt
or-le
instead of-gt
– T-Me
Jan 2 at 11:00
Do you consider the backup incomplete if none of the directories has any files modified yesterday, or if at least one of them has no files modified yesterday?
– Ansgar Wiechers
Jan 2 at 11:58
To match a distinct date when comparing dates you'll have to strip off the time component by appending.Date
. To check that none of the files is from that date, you could either abort if only one matches or count the matches and only trigger if count is zero. ALSO what should your calculated property return for Length if only folders should be output?
– LotPings
Jan 2 at 12:03
@AnsgarWiechers I want the status of each folder to be verified by checking the file modified date. If it has a file modified date as yesterday, that means backup successful. If not, not complete.
– Ahmed
Jan 2 at 12:08
@LotPings Folder names to be mentioned only if Backup is not complete. Output should have 2 headers. In-Complete Backups and Complete backups. Under in-complete backups should only show the folder name. and under complete backup should show file name, directory name, size(GB).
– Ahmed
Jan 2 at 12:16
add a comment |
Loop through a text file which contains folder Locations
foreach ($line in Get-Content "C:Backupsample.txt") {
Get-ChildItem $line | Where {
$_.LastWriteTime -gt (Get-Date).AddDays(-1)
} | select Directoryname, Name, LastWriteTime, @{Name="Size (GB)"; Expression={[Math]::Round($_.Length/1MB, 1)}}
}
This way I am only able to get the files that were modified yesterday.
What I want is to list out the folders which does and does not have files modified yesterday.
If a folder contains files that were modified yesterday (modified date as yesterday), then list those File Names, Folder Name and their sizes(GB).
And also Write-Host
as backup successful.
The same should go with folders which does not contain files with the modified date as yesterday.
Write-Host
backup not complete.
powershell compare backup
Loop through a text file which contains folder Locations
foreach ($line in Get-Content "C:Backupsample.txt") {
Get-ChildItem $line | Where {
$_.LastWriteTime -gt (Get-Date).AddDays(-1)
} | select Directoryname, Name, LastWriteTime, @{Name="Size (GB)"; Expression={[Math]::Round($_.Length/1MB, 1)}}
}
This way I am only able to get the files that were modified yesterday.
What I want is to list out the folders which does and does not have files modified yesterday.
If a folder contains files that were modified yesterday (modified date as yesterday), then list those File Names, Folder Name and their sizes(GB).
And also Write-Host
as backup successful.
The same should go with folders which does not contain files with the modified date as yesterday.
Write-Host
backup not complete.
powershell compare backup
powershell compare backup
edited Jan 2 at 12:18
LotPings
19.5k61533
19.5k61533
asked Jan 2 at 10:49
AhmedAhmed
64
64
just invert thewhere
condition:-lt
or-le
instead of-gt
– T-Me
Jan 2 at 11:00
Do you consider the backup incomplete if none of the directories has any files modified yesterday, or if at least one of them has no files modified yesterday?
– Ansgar Wiechers
Jan 2 at 11:58
To match a distinct date when comparing dates you'll have to strip off the time component by appending.Date
. To check that none of the files is from that date, you could either abort if only one matches or count the matches and only trigger if count is zero. ALSO what should your calculated property return for Length if only folders should be output?
– LotPings
Jan 2 at 12:03
@AnsgarWiechers I want the status of each folder to be verified by checking the file modified date. If it has a file modified date as yesterday, that means backup successful. If not, not complete.
– Ahmed
Jan 2 at 12:08
@LotPings Folder names to be mentioned only if Backup is not complete. Output should have 2 headers. In-Complete Backups and Complete backups. Under in-complete backups should only show the folder name. and under complete backup should show file name, directory name, size(GB).
– Ahmed
Jan 2 at 12:16
add a comment |
just invert thewhere
condition:-lt
or-le
instead of-gt
– T-Me
Jan 2 at 11:00
Do you consider the backup incomplete if none of the directories has any files modified yesterday, or if at least one of them has no files modified yesterday?
– Ansgar Wiechers
Jan 2 at 11:58
To match a distinct date when comparing dates you'll have to strip off the time component by appending.Date
. To check that none of the files is from that date, you could either abort if only one matches or count the matches and only trigger if count is zero. ALSO what should your calculated property return for Length if only folders should be output?
– LotPings
Jan 2 at 12:03
@AnsgarWiechers I want the status of each folder to be verified by checking the file modified date. If it has a file modified date as yesterday, that means backup successful. If not, not complete.
– Ahmed
Jan 2 at 12:08
@LotPings Folder names to be mentioned only if Backup is not complete. Output should have 2 headers. In-Complete Backups and Complete backups. Under in-complete backups should only show the folder name. and under complete backup should show file name, directory name, size(GB).
– Ahmed
Jan 2 at 12:16
just invert the
where
condition: -lt
or -le
instead of -gt
– T-Me
Jan 2 at 11:00
just invert the
where
condition: -lt
or -le
instead of -gt
– T-Me
Jan 2 at 11:00
Do you consider the backup incomplete if none of the directories has any files modified yesterday, or if at least one of them has no files modified yesterday?
– Ansgar Wiechers
Jan 2 at 11:58
Do you consider the backup incomplete if none of the directories has any files modified yesterday, or if at least one of them has no files modified yesterday?
– Ansgar Wiechers
Jan 2 at 11:58
To match a distinct date when comparing dates you'll have to strip off the time component by appending
.Date
. To check that none of the files is from that date, you could either abort if only one matches or count the matches and only trigger if count is zero. ALSO what should your calculated property return for Length if only folders should be output?– LotPings
Jan 2 at 12:03
To match a distinct date when comparing dates you'll have to strip off the time component by appending
.Date
. To check that none of the files is from that date, you could either abort if only one matches or count the matches and only trigger if count is zero. ALSO what should your calculated property return for Length if only folders should be output?– LotPings
Jan 2 at 12:03
@AnsgarWiechers I want the status of each folder to be verified by checking the file modified date. If it has a file modified date as yesterday, that means backup successful. If not, not complete.
– Ahmed
Jan 2 at 12:08
@AnsgarWiechers I want the status of each folder to be verified by checking the file modified date. If it has a file modified date as yesterday, that means backup successful. If not, not complete.
– Ahmed
Jan 2 at 12:08
@LotPings Folder names to be mentioned only if Backup is not complete. Output should have 2 headers. In-Complete Backups and Complete backups. Under in-complete backups should only show the folder name. and under complete backup should show file name, directory name, size(GB).
– Ahmed
Jan 2 at 12:16
@LotPings Folder names to be mentioned only if Backup is not complete. Output should have 2 headers. In-Complete Backups and Complete backups. Under in-complete backups should only show the folder name. and under complete backup should show file name, directory name, size(GB).
– Ahmed
Jan 2 at 12:16
add a comment |
1 Answer
1
active
oldest
votes
I'm going to assume that you consider the backup incomplete if at least one folder does not contain a file modified in the past 24 hours.
$refdate = (Get-Date).AddDays(-1)
$complete = $true
$results = foreach ($line in Get-Content "C:Backupsample.txt") {
$result = Get-ChildItem $line |
Where-Object { $_.LastWriteTime -gt $refdate } |
Select-Object Directoryname, Name, LastWriteTime,
@{n="Size (GB)";e={[Math]::Round($_.Length/1MB, 1)}}
if ($result) {
$result
} else {
$complete = $false
}
}
if ($complete) {
Write-Host 'Backup complete'
} else {
Write-Host 'Backup incomplete'
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54004974%2fneed-a-powershell-script-to-find-folders-which-does-not-have-files-modified-yest%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm going to assume that you consider the backup incomplete if at least one folder does not contain a file modified in the past 24 hours.
$refdate = (Get-Date).AddDays(-1)
$complete = $true
$results = foreach ($line in Get-Content "C:Backupsample.txt") {
$result = Get-ChildItem $line |
Where-Object { $_.LastWriteTime -gt $refdate } |
Select-Object Directoryname, Name, LastWriteTime,
@{n="Size (GB)";e={[Math]::Round($_.Length/1MB, 1)}}
if ($result) {
$result
} else {
$complete = $false
}
}
if ($complete) {
Write-Host 'Backup complete'
} else {
Write-Host 'Backup incomplete'
}
add a comment |
I'm going to assume that you consider the backup incomplete if at least one folder does not contain a file modified in the past 24 hours.
$refdate = (Get-Date).AddDays(-1)
$complete = $true
$results = foreach ($line in Get-Content "C:Backupsample.txt") {
$result = Get-ChildItem $line |
Where-Object { $_.LastWriteTime -gt $refdate } |
Select-Object Directoryname, Name, LastWriteTime,
@{n="Size (GB)";e={[Math]::Round($_.Length/1MB, 1)}}
if ($result) {
$result
} else {
$complete = $false
}
}
if ($complete) {
Write-Host 'Backup complete'
} else {
Write-Host 'Backup incomplete'
}
add a comment |
I'm going to assume that you consider the backup incomplete if at least one folder does not contain a file modified in the past 24 hours.
$refdate = (Get-Date).AddDays(-1)
$complete = $true
$results = foreach ($line in Get-Content "C:Backupsample.txt") {
$result = Get-ChildItem $line |
Where-Object { $_.LastWriteTime -gt $refdate } |
Select-Object Directoryname, Name, LastWriteTime,
@{n="Size (GB)";e={[Math]::Round($_.Length/1MB, 1)}}
if ($result) {
$result
} else {
$complete = $false
}
}
if ($complete) {
Write-Host 'Backup complete'
} else {
Write-Host 'Backup incomplete'
}
I'm going to assume that you consider the backup incomplete if at least one folder does not contain a file modified in the past 24 hours.
$refdate = (Get-Date).AddDays(-1)
$complete = $true
$results = foreach ($line in Get-Content "C:Backupsample.txt") {
$result = Get-ChildItem $line |
Where-Object { $_.LastWriteTime -gt $refdate } |
Select-Object Directoryname, Name, LastWriteTime,
@{n="Size (GB)";e={[Math]::Round($_.Length/1MB, 1)}}
if ($result) {
$result
} else {
$complete = $false
}
}
if ($complete) {
Write-Host 'Backup complete'
} else {
Write-Host 'Backup incomplete'
}
answered Jan 2 at 21:10
Ansgar WiechersAnsgar Wiechers
145k13132190
145k13132190
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54004974%2fneed-a-powershell-script-to-find-folders-which-does-not-have-files-modified-yest%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
just invert the
where
condition:-lt
or-le
instead of-gt
– T-Me
Jan 2 at 11:00
Do you consider the backup incomplete if none of the directories has any files modified yesterday, or if at least one of them has no files modified yesterday?
– Ansgar Wiechers
Jan 2 at 11:58
To match a distinct date when comparing dates you'll have to strip off the time component by appending
.Date
. To check that none of the files is from that date, you could either abort if only one matches or count the matches and only trigger if count is zero. ALSO what should your calculated property return for Length if only folders should be output?– LotPings
Jan 2 at 12:03
@AnsgarWiechers I want the status of each folder to be verified by checking the file modified date. If it has a file modified date as yesterday, that means backup successful. If not, not complete.
– Ahmed
Jan 2 at 12:08
@LotPings Folder names to be mentioned only if Backup is not complete. Output should have 2 headers. In-Complete Backups and Complete backups. Under in-complete backups should only show the folder name. and under complete backup should show file name, directory name, size(GB).
– Ahmed
Jan 2 at 12:16