Forum Discussion
dinaru
Mar 28, 2021Copper Contributor
Folders and sub folders copy the text file if matches
Hi PowerShell Folks, Hope you're doing great. I have a requirement list of folders with devices IP name such 192.168.1.100, 192.168.1.101 and with each devices IP another folder created based on...
dinaru
Mar 28, 2021Copper Contributor
$MonthVal=(Get-Date).AddMonths(-1).ToString("MMM")
$DestFolder="C:\temp\Network_Logs\"
# Define the TOP-level folder
$TOP_FOLDER = "C:\temp\logs"
# Get all sub folders recursively
$Child_Folders = Get-ChildItem -Path $TOP_FOLDER -Recurse | Where-Object { $_.PSIsContainer -eq $true }
# Create a text file in each sub-folder and add the current date/time as value.
foreach ($foldername in $Child_Folders)
{
foreach ($Child_Folder in $Child_Folders)
{
if ($Child_Folders -eq $MonthVal)
{
Copy-Item -Path "$Child_Folders\*" -Destination "$DestFolder\" -recurse -Force -Verbose }
}
$DestFolder="C:\temp\Network_Logs\"
# Define the TOP-level folder
$TOP_FOLDER = "C:\temp\logs"
# Get all sub folders recursively
$Child_Folders = Get-ChildItem -Path $TOP_FOLDER -Recurse | Where-Object { $_.PSIsContainer -eq $true }
# Create a text file in each sub-folder and add the current date/time as value.
foreach ($foldername in $Child_Folders)
{
foreach ($Child_Folder in $Child_Folders)
{
if ($Child_Folders -eq $MonthVal)
{
Copy-Item -Path "$Child_Folders\*" -Destination "$DestFolder\" -recurse -Force -Verbose }
}