-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask6.psm1
More file actions
32 lines (30 loc) · 1.16 KB
/
task6.psm1
File metadata and controls
32 lines (30 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<#
Функция добавления в указанный каталог текстового файла с заданным содержимым.
Имя файла, путь к каталогу (при отсутствии работать с текущим каталогом),
содержимое файла задать в режиме диалога.
#>
function Add-TextFile {
$FileName = Read-Host "File name"
$FolderPath = Read-Host "Folder path (default is current directory)"
if ($FolderPath -eq "") {
$FolderPath = "."
}
$FileContentList = @()
Write-Host "Enter the file content here (enter ':q' to exit):"
$Input = Read-Host
while ($Input -ne ":q") {
$FileContentList += $Input
$Input = Read-Host
}
$BreakLineChar = "`n"
if ([System.Environment]::OSVersion.Platform -eq "Win32NT") {
$BreakLineChar = "`r`n"
}
$FileContent = ""
foreach ($Line in $FileContentList) {
$FileContent += $Line + $BreakLineChar
}
$FileAbsolutePath = Join-Path (Resolve-Path $FolderPath).Path $FileName
Write-Output $FileContent > $FileAbsolutePath
}
Export-ModuleMember Add-TextFile