Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Passing arguments from PS command line

$
0
0

Hi,

How can I pass the current date as an argument form PS prompt to execute below PS coding, instead hardcoding the Current date in the file  ?

------------------------------------------------------------------------------------------------------------------------------------------------------

$today = Get-Date -Format yyyyMMdd
$servers = @{

"01"="der\der ";
"02"="alm\alm ";
"03"="dxb\dxb ";
"04"="jum\jum ";
"05"="jal\jal ";
"06"="shj\shj ";
"07"="ras\ras ";
"08"="adh\adh ";

}

Get-ChildItem -Path 'D:\Rep' |
Where-Object { $_.PSIsContainer -eq $true -and $_.name -match "^(\d{2})-$today$" } |
ForEach-Object {
    $server = $servers[$matches[1]]                                   if ($server) {
        Write-Host "Copying directory $($_.FullName) to \\  $server \ $today ..."

        New-Item -ItemType Directory -Path " \\  $server \ $today " -Force | Out-Null
        Copy-Item -Path "$($_.FullName)\*" -Destination "\\  $server \ $today " -Recurse -Force
    } else {
        Write-Host "Key $($matches[1]) was not found in the `$servers table."
    }
}

Thanks in advance      


Viewing all articles
Browse latest Browse all 15028

Trending Articles