Pages

Wednesday, December 9, 2015

Powershell, Infile search and file copy between the servers in same domain

Find a keyword within multiple files in a folder.

$PATH = "D:\Veeva Activity\WE_00DA0000000Ci0mMAC_123\"
$FILES = Get-ChildItem -Path $path  # -Name user.csv*

Foreach ($FILE IN $FILES )

{
Get-Content $PATH$FILE -First 1   | Where-Object { $_ -like '*lm_Presentation_Version_vod*' }

$FILE

}

File copy between the servers in the same domain
$SourcePath = "\\Server1\Data Input Area"
$DestinationPath  = "\\Server2\Data Input Area"

$Folders = Get-ChildItem -Path $SourcePath  -Name Aver*
FOREACH ($Folder in $Folders)
{
#$DestinationPath + "\"+ $Folder
#Get-ChildItem -Path $SourcePath\$Folder | Where-Object{!($_.PSIsContainer)}
Copy -Path $SourcePath\$Folder\* -Destination $DestinationPath\$Folder | Where-Object{!($_.PSIsContainer)} # Exclude Folders
}

No comments:

Post a Comment