how to get this simpel script to run
$remotePCName = Gc "C:\script\computers.txt"$remoteRoot = “\\$remotePCName\f”$Location = $remoteRootCopy-Item "c:\vmware” $Location -recurse -forceif Copy-Item fail<-------this is my problem Write-Output "$remotePCName" out-file -append -filepath C:\logs\success.logWrite-Host "$remotePCName is successfully copyed the files "} else {Write-Output "$remotePCName" out-file -append -filepath C:\logs\failed.logWrite-Host "$remotePCName is failed copyed the files " -BackgroundColor red}
Try{ $remotePCName = Gc "C:\script\computers.txt" -erroraction silentlycontinue$remoteRoot = “\\$remotePCName\f”$Location = $remoteRootCopy-Item "c:\vmware” $Location -recurse -force -erroraction silentlycontinueWrite-Output "$remotePCName" | out-file -append -filepath C:\logs\success.logWrite-Host "$remotePCName is successfully copyed the files "} Catch{ Write-Output "$remotePCName" | out-file -append -filepath C:\logs\failed.logWrite-Host "$remotePCName is failed copyed the files " -BackgroundColor red}
Try{
$remotePCName = Gc "C:\script\computers.txt" -erroraction silentlycontinue$remoteRoot = “\\$remotePCName\f”$Location = $remoteRootCopy-Item "c:\vmware” $Location -recurse -force -erroraction silentlycontinueWrite-Output "$remotePCName" | out-file -append -filepath C:\logs\success.logWrite-Host "$remotePCName is successfully copyed the files "}
Catch{
Write-Output "$remotePCName" | out-file -append -filepath C:\logs\failed.logWrite-Host "$remotePCName is failed copyed the files " -BackgroundColor red}
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 = $remoteRootCopy-Item "c:\vmware” $Location -recurse -force -erroraction silentlycontinueWrite-Output "$remotePCName" | out-file -append -filepath C:\logs\success.logWrite-Host "$remotePCName is successfully copyed the files "}Catch{Write-Output "$remotePCName" | out-file -append -filepath C:\logs\failed.logWrite-Host "$remotePCName is failed copyed the files " -BackgroundColor red}sharon-pc is successfully copyed the files
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 StatusCodeIf ($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
$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"}
$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"}
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 silentlycontinueIf ("$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 ________________________________________________________________________________________________________________________
$folder = "c:\vmware"$remotePCName = Gc "C:\scripts\computers.txt" -erroraction silentlycontinue$remoteRoot = “\\$remotePCName\f”Copy-Item $folder $remoteRoot -recurse -force -erroraction silentlycontinueIf ("$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"}
$folder = "c:\vmware"$remotePCName = Gc "C:\scripts\computers.txt" -erroraction silentlycontinue$remoteRoot = “\\$remotePCName\f”Copy-Item $folder $remoteRoot -recurse -force -erroraction silentlycontinue
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 silentlycontinueIf ("$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"}
It will only create the failed log if the vmware folder does not exist in the remote computer.
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
$folder = "c:\vmware"$remotePCName = Gc "C:\script\computers.txt"$remoteRoot = “\\$remotePCName\share1”$Location = $remoteRoot$copystatus = Copy-Item $folder $remoteRoot -recurse -force -erroraction silentlycontinueIf (!$error){Write-Output $remotePCName | out-file -append -filepath "C:\logs\success.log"}Else{Write-Output $remotePCName | out-file -append -filepath "C:\logs\failed.log"}
tanks you this is working really great is withering filled and success under true condition