November 2018
Intermediate to advanced
566 pages
17h 15m
English
The logic is simple. We will use a begin block to show the date, and have the file creation part in the process block. The process block will have a looping construct to create the files.
Open a new PowerShell script file and enter the following:
function New-File { param (
# The path to the file (or the name)
[Parameter(Mandatory=$true, Position=0)]
[string[]]
$Path
)
begin {
Write-Host "$(Get-Date)"
}
process {
foreach ($Item in $Path) {
New-Item -Path $Item -ItemType File
}
}
end {}
}
Now, call the function as specified in the requirement:
PS> New-File 'test1.txt', 'test2.txt', 'test3.txt'
Read now
Unlock full access