Как получить запрос на запрос пути при использовании Get-ChildItem в PowerShell?
Я довольно новичок в PowerShell. Я нашел несколько руководств и скомкал небольшой сценарий вместе, хотя я, кажется, не могу установить приглашение, чтобы спросить источник/назначение.
Сценарий выглядит следующим образом:
gci -path | Get-Random -Count 4 | mi -Destination C:Temp
while(1) { sleep -sec 20; .Power.ps1 }
Для любого ответа, заранее спасибо!
2 ответа:
Вот пример, FWIW:
$source,$target = $null,$null while ($source -eq $null){ $source = read-host "Enter source file name" if (-not(test-path $source)){ Write-host "Invalid file path, re-enter." $source = $null } elseif ((get-item $source).psiscontainer){ Write-host "Source must be a file, re-enter." $source = $null } } while ($target -eq $null){ $target = read-host "Enter source directory name" if (-not(test-path $target)){ Write-host "Invalid directory path, re-enter." $target = $null } elseif (-not (get-item $target).psiscontainer){ Write-host "Target must be a directory, re-enter." $target = $null } }