在PowerShell中使用Get-ChildItem时,如何提示输入路径?

| 我对PowerShell相当陌生。 我发现了一些指南,并将一些脚本混在一起,尽管我似乎无法设置提示来询问源/目的地。 脚本如下:
gci -path   | Get-Random -Count 4 | mi -Destination C:\\Temp
while(1) { sleep -sec 20; .\\Power.ps1 }
对于任何回应, 提前致谢!     
已邀请:
        使用
Read-Host
Get-ChildItem -Path (Read-Host -Prompt \'Get path\')
    
        这是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
    }
}
    

要回复问题请先登录注册