首页 > 解决方案 > 将文件共享路径作为参数读取时出错

问题描述

执行以下脚本时收到以下错误。

测试路径:找不到接受参数“input.dat”的位置参数。

.\FL.ps1 \\flamingdev\analytics\source\INBOUND   \\flamingdev\analytics\source\OUTBOUND

[CmdletBinding()]
param (
  [string] $SrcFolder,
  [string] $FileListPath
)

$SrcFolder
$FileListPath

IF (Test-Path "$FileListPath"\input.dat) {
Remove-Item "$FileListPath"\input.dat
}

Get-ChildItem -File -Path "$SrcFolder"\Extract* | Select-Object - ExpandProperty Name | Add-Content -Path "$FileListPath"\input.dat

标签: powershell

解决方案


您需要在双引号中使用“所有路径”。像这样:

IF (Test-Path "$FileListPath\input.dat") {
Remove-Item "$FileListPath\input.dat"
}
 Get-ChildItem -File -Path "$SrcFolder\Extract*" | Select-Object -ExpandProperty Name | Add-Content -Path "$FileListPath\input.dat"

推荐阅读