February 17, 2016 at 10:24 am
I needed to move files (using powershell V2)
finely I found one liner to do the job,
to my understanding Move-Item use -LiteralPath parameter --- (Accept pipeline input? true (ByPropertyName))
but how it submitted to Move-Item if Get-ChildItem has no property name LiteralPath (only Fullname)
Get-ChildItem -Path C:\Application\Log\*\*.Log |
Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-90)
} | Move-Item -Destination {
"\\NASServer\Archives\{0}\" -f $_.Directory.Name
}
example taken from
--https://becomelotr.wordpress.com/2013/04/30/event-1-my-way/
February 18, 2016 at 2:15 am
-LiteralPath was added as a parameter in v3.0 so no help there for you in v2.0 of PowerShell.
However, does not the following work:
Get-ChildItem -Path C:\Application\Log\*\*.Log |
Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-90)
} | Move-Item -LiteralPath $_.Path -Destination {
"\\NASServer\Archives\{0}\" -f $_.Directory.Name
}
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
February 18, 2016 at 8:27 am
does not work with $_.Path ( replaced with $_.Fullname) and changed Move-item to Copy-item
but what confuse me that both scripts working and provide same result
Question: I don't provide full path to file explicitly in second case , how Copy-Item know what file to use?
Get-ChildItem -Path U:\PS |
Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-90)
} |Copy-Item -LiteralPath {$_.Fullname} -Destination {
"U:\PS\bamboo\" -f $_.Directory.Name
}
Get-ChildItem -Path U:\PS |
Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-90)
} |Copy-Item -Destination {"U:\PS\bamboo\" -f $_.Directory.Name}
February 18, 2016 at 9:45 am
Perhaps the default parameter for Copy-Item is different.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
March 8, 2016 at 2:19 am
Did you get it sorted?
If so please confirm your solution for others.
If not then feel free to ask for more assistance.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply