if Copy-Item fail or secsuse export to log

This post has 11 Replies | 2 Followers

Top 100 Contributor
Posts 11
eizhak9 Posted: 05-08-2011 3:01 PM

how to get this simpel script to run

$remotePCName = Gc "C:\script\computers.txt"
$remoteRoot = “\\$remotePCName\f”
$Location = $remoteRoot
Copy-Item "c:\vmware” $Location -recurse -force
if Copy-Item fail<-------this is my problem
Write-Output "$remotePCName" out-file -append -filepath C:\logs\success.log
Write-Host "$remotePCName is successfully copyed the files "
} else {
Write-Output "$remotePCName" out-file -append -filepath C:\logs\failed.log
Write-Host "$remotePCName is failed copyed the files " -BackgroundColor red
}

 

Top 10 Contributor
Posts 258
Top Contributor

Try{

$remotePCName = Gc "C:\script\computers.txt" -erroraction silentlycontinue
$remoteRoot = “\\$remotePCName\f”
$Location = $remoteRoot
Copy-Item "c:\vmware” $Location -recurse -force -erroraction silentlycontinue
Write-Output "$remotePCName" | out-file -append -filepath C:\logs\success.log
Write-Host "$remotePCName is successfully copyed the files "}

Catch{


Write-Output "$remotePCName" | out-file -append -filepath C:\logs\failed.log
Write-Host "$remotePCName is failed copyed the files " -BackgroundColor red
}

Top 100 Contributor
Posts 11

is not working i uncheck the File and Printer Sharing in the firewall to not to let file and sharing be open ,after i check it not copy the file obscures ! and it say it do here what i get why ?

PS C:\Users\Eizhak\Desktop> Try{

$remotePCName = Gc "C:\script\computers.txt" -erroraction silentlycontinue
$remoteRoot = “\\$remotePCName\c$”
$Location = $remoteRoot
Copy-Item "c:\vmware” $Location -recurse -force -erroraction silentlycontinue
Write-Output "$remotePCName" | out-file -append -filepath C:\logs\success.log
Write-Host "$remotePCName is successfully copyed the files "}

Catch{


Write-Output "$remotePCName" | out-file -append -filepath C:\logs\failed.log
Write-Host "$remotePCName is failed copyed the files " -BackgroundColor red
}
sharon-pc is successfully copyed the files

Top 100 Contributor
Posts 11

i do this

$remotePCName = Gc "C:\script\computers.txt" -erroraction silentlycontinue
$remoteRoot = “\\$remotePCName\f”
$Location = $remoteRoot
{$copystatus = Copy-Item "c:\vmware” $Location -recurse -force -erroraction silentlycontinue |
Select-Object StatusCode
If ($copystatus.StatusCode -eq 0 )
{Write-Output "$remotePCName" | out-file -append -filepath C:\logs\success.log}
Else
{Write-Output "$remotePCName" | out-file -append -filepath C:\logs\failed.log}
}

but it dont give me the logs just copy how to set If ($copystatus.StatusCode - ?? )

how to get the "if" detect the -eq 0 as the error or the success of the opertion i try with -erroraction it not working to

Top 10 Contributor
Posts 258
Top Contributor

$folder = "c:\vmware"
$remotePCName = Gc "C:\scripts\computers.txt" -erroraction silentlycontinue
$remoteRoot = “\\$remotePCName\c$”
$copystatus = Copy-Item $folder $remoteRoot -recurse -force -erroraction silentlycontinue

If ("$remoteRoot\$($folder.split("\")[1])")
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\success.log"}
Else
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\failed.log"}

Top 100 Contributor
Posts 11

not working problem with the unc path

PS C:\Users\Eizhak\Desktop> $folder = "c:\vmware"
$remotePCName = Gc "C:\scripts\computers.txt" -erroraction silentlycontinue
$remoteRoot = “\\$remotePCName\c$”
$copystatus = Copy-Item $folder \\$remotePCName\f -recurse -force -erroraction silentlycontinue

If ("$remoteRoot\$($folder.split("\")[1])")
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\success.log"}
Else
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\failed.log"}
Copy-Item : The UNC path should be of the form \\server\share.
At line:4 char:24
+ $copystatus = Copy-Item <<<<  $folder \\$remotePCName\c$ -recurse -force -erroraction silentlycontinue
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand

 

________________________________________________________________________________________________________________________

Top 10 Contributor
Posts 258
Top Contributor

$folder = "c:\vmware"
$remotePCName = Gc "C:\scripts\computers.txt" -erroraction silentlycontinue
$remoteRoot = “\\$remotePCName\f”
Copy-Item $folder $remoteRoot -recurse -force -erroraction silentlycontinue

If ("$remoteRoot\$($folder.split("\")[1])")
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\success.log"}
Else
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\failed.log"}


Top 100 Contributor
Posts 11

this work bot not give fail log:

$folder = "c:\vmware"
$remotePCName = Gc "C:\script\computers.txt"
$remoteRoot = “\\$remotePCName\share1”
$Location = $remoteRoot
$copystatus = Copy-Item "$folder” “$remoteRoot” -recurse -force -erroraction silentlycontinue

If ("$remoteRoot\$($folder.split("\")[1])")
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\success.log"}
Else
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\failed.log"}

Top 10 Contributor
Posts 258
Top Contributor

It will only create the failed log if the vmware folder does not exist in the remote computer.

Top 100 Contributor
Posts 11

this grate but there is meager host in Organization that need this VMware folder contained a file that VMware view 4.5 need to work with and i need to copy to all new location this folder and that all ready don't have this files and i need to know if the script fail for any condition to copy this file to a log than i can mail all this ip or host to the manager please help me I am new at power-shell

Top 10 Contributor
Posts 258
Top Contributor

$folder = "c:\vmware"
$remotePCName = Gc "C:\script\computers.txt"
$remoteRoot = “\\$remotePCName\share1”
$Location = $remoteRoot
$copystatus = Copy-Item $folder $remoteRoot -recurse -force -erroraction silentlycontinue

If (!$error)
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\success.log"}
Else
{Write-Output $remotePCName | out-file -append -filepath "C:\logs\failed.log"}

Top 100 Contributor
Posts 11

tanks you this is working really great  Smile is withering filled and success under true conditionBig Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile Big Smile

Page 1 of 1 (12 items) | RSS
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.