在 PowerShell 中使用 Get-ChildItem 时,如何获得询问路径的提示?

发布于 2024-11-16 16:31:36 字数 229 浏览 3 评论 0原文

我对 PowerShell 相当陌生。 我找到了一些指南并将一个小脚本混在一起,尽管我似乎无法设置提示来询问源/目的地。

脚本如下:

gci -path   | Get-Random -Count 4 | mi -Destination C:\Temp
while(1) { sleep -sec 20; .\Power.ps1 }

对于任何响应, 提前致谢!

I'm rather new to PowerShell.
I found a few guides and mashed a little script together, though i do not seem to be able to set a prompt to ask for the source/destination.

The script is as following:

gci -path   | Get-Random -Count 4 | mi -Destination C:\Temp
while(1) { sleep -sec 20; .\Power.ps1 }

For any response,
thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟─花易冷 2024-11-23 16:31:37

使用读取主机:

Get-ChildItem -Path (Read-Host -Prompt 'Get path')

Use Read-Host:

Get-ChildItem -Path (Read-Host -Prompt 'Get path')
初相遇 2024-11-23 16:31:37

这是一个例子,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
    }
}

Here's an example, 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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文