Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

HashTables , Arrays, powershell

Hi All,

I have these three commands that i am trying to script:

.\emcopy64.exe \\sreadvfile03\f$ \\sreadvfile02\g$ /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:sreadvfile03_fdrive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt


.\emcopy64.exe \\sreadvfile03\e$ \\sreadvfile02\f$ /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:sreadvfile03_edrive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt


.\emcopy64.exe \\sreadvfile03\z$ \\sreadvfile02\h$ /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:sreadvfile03_zdrive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt

Open in new window


so far my solution is:

$copy=@(@{source="\sreadvfile03\f$";destination="\\sreadvfile02\g$"}, @{source="\\sreadvfile03\e$";destination="\\sreadvfile02\f$"},@{source="\sreadvfile03\f$";destination="\\sreadvfile02\g$"}) 


foreach ($m in $copy){

{
	
.\emcopy64.exe $($m.source) $($m.destination) /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:$($m.source)_fdrive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt

}

Open in new window


will the above work?

Also how do i select the correct drive in $($m.source)_fdrive_$

also any other ways of doing as this as i am trying to master powershell?
Avatar of Kelly Garcia
Kelly Garcia
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I cant seem to access the $m, ive tried

$copy=@(@{source="\\sreadvfile03\f$";destination="\\sreadvfile02\g$"}, @{source="\\sreadvfile03\e$";destination="\\sreadvfile02\f$"},@{source="\sreadvfile03\f$";destination="\\sreadvfile02\g$"}) 


foreach ($m in $copy){



Write-host "Copying $copy[$m].source to $copy[$m].destination"
	



}

Open in new window

Avatar of aikimark
You have other concerns, such as the log name.  Try this
$copy=@(("f","g"),("e","f"),("z","h"))
$copy | %{".\emcopy64.exe \\sreadvfile03\$($_[0])$ \\sreadvfile02\$($_[1])$  /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:sreadvfile03_$($_[0])drive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt"}

Open in new window

Avatar of oBdA
oBdA

You can't have a ":" as part of the log file name (as it happens in your date formatting). And the date format should by y-M-d, so that the logs will be automatically sorted properly when sorted by name.
The easiest way to have data like that in a script is to put it in a here-string as csv.
$DateFormat = 'yyyy-MM-dd_HH-mm'
$Copy = @'
"Source",				"Destination"
"\\sreadvfile03\f$",	"\\sreadvfile02\g$"
"\\sreadvfile03\e$",	"\\sreadvfile02\f$"
"\\sreadvfile03\z$",	"\\sreadvfile02\h$"
'@ | ConvertFrom-Csv

$Copy | ForEach-Object {
	$Server, $Drive = $_.Source.Split('\', [StringSplitOptions]::RemoveEmptyEntries)
	$LogFile = "$($Server)_$($Drive[0])drive_$(Get-Date -Format $DateFormat).log"
	& .\emcopy64.exe $_.Source $_.Destination /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:$LogFile
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fantastic Thank you
I've put the script into a workflow for parallel processing:

workflow copyfiles {

$copy=@(@{source="\\sreadvfile01\c$\testemcopy";destination="\\W10000601\C$\testemcopy_1"}, @{source="\\sreadvfile02\c$\testemcopy";destination="\\W10000601\C$\testemcopy_1"},@{source="\\sreadvfile03\c$\testemcopy";destination="\\W10000601\C$\testemcopy_1"}) 

ForEach -Parallel ($m in $copy) {

$DateFormat = 'yyyy-MM-dd_HH-mm'

write-host  "Copying $($m['source']) to $($m['destination'])"

<#.\emcopy64.exe $($m['source']) $($m['destination']) /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:$($m['source'])_$($DateFormat).txt #>


}

}

Open in new window


however I get this error:

At line:5 char:1
+ write-host  "Copying $($m['source']) to $($m['destination'])"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cannot call the 'Write-Host' command. Other commands from this module have been packaged as workflow activities, but
this command was specifically excluded. This is likely because the command requires an interactive Windows PowerShell
session, or has behavior not suited for workflows. To run this command anyway, place it within an inline-script
(InlineScript { Write-Host }) where it will be invoked in isolation.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : CommandActivityExcluded
Also I get this error:


Cannot find the '.\emcopy64.exe' command. If this command is defined as a workflow, ensure it is defined before the
workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on
this system), place it in an InlineScript: 'InlineScript { .\emcopy64.exe }'
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : CommandNotFound

Open in new window