Create Log File with Copy-Item


hi

i currently have following script , trying find easiest way write log file text file each item has been copied each line read '$source.name directory has been moved $destination directory $date'

i wish same items removed in second part

'item $source.name has been removed $source'

$source = "c:\foldera" $destination = "c:\folderb"
$date = get-date
$items = get-childitem -path $source -recurse | where-object {$_.lastwritetime -lt (get-date).adddays(-2) -and ($_.psiscontainer -eq $true) } | foreach ($item in $items) {copy-item -destination $destination -force -recurse } get-childitem -path $source -recurse | where-object {$_.lastwritetime -lt (get-date).adddays(-2) -and ($_.psiscontainer -eq $true)} | remove-item -recurse


any pointers great, running tests @ end

barrie

this require. 
$source = "c:\foldera" $destination = "c:\folderb" $date = get-date $items = get-childitem -path $source -recurse | where-object {$_.lastwritetime -lt (get-date).adddays(-2) -and ($_.psiscontainer -eq $true) } foreach($item in $items) { 	try 	{ 		$copieditems=copy-item "$source\$item" -destination $destination -force -recurse -passthru  		"$([datetime]::now)" + "`t$source\$item`t copied onto $destination"| out-file c:\copied.txt -append 	} 	catch 	{ 		"$source\$item"+": " + $_.exception.message | out-file c:\notcopied.txt -append 	} }
wise can remove operations.


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...