术语“<ScriptPath>\Move”未被识别为 cmdlet 的名称
The term '<ScriptPath>\Move' is not recognized as the name of a cmdlet
我创建了一个脚本,可以将文件和文件夹从一个文件夹移动到另一个文件夹。我已经在 PowerShell ISE 中设计了它,如果我从那里 运行 它可以完美地工作。
然而,当我 运行 从任务计划程序或命令提示符使用
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass "C:\MilkImports\FileScripts\Move No Holdings Milk Files.ps1"
我收到以下错误
C:\PSScripts\Move : The term 'C:\PSScripts\Move' is not recognized as the name of a cmdlet, function, script file, or operable program.
在我的脚本中唯一引用 Move 是在我使用 Move-Item 时。
我的脚本如下
$SQLServer = "xxx"
$SQLDatabase = "xxx"
$SQLUser = "xxx"
$SQLPassword = "xxx"
$SQLConnection = New-Object System.Data.SqlClient.SqlConnection
$SQLCommand = New-Object System.Data.SqlClient.SqlCommand
$SQLDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$dtPIDs = New-Object System.Data.DataTable
$SQLQuery = "SELECT DISTINCT(PID) FROM table1 t1
INNER JOIN table2 t2 ON t1.CID = t2.CID
WHERE CHARINDEX('UK', areaCode) > 0"
$SQLConnection.ConnectionString = "Server=$SQLServer;Database=$SQLDatabase;Integrated Security=false;User ID=$SQLUser;Password=$SQLPassword;"
$SQLCommand.Connection = $SQLConnection
$SQLCommand.CommandText = $SQLQuery
$SQLDataAdapter.SelectCommand = $SQLCommand
$SQLDataAdapter.Fill($dtPIDs)
foreach($Row in $dtPIDs)
{
$PID = $Row["PID"]
$SourceFolder = Join-Path -Path "C:\Imports\NoHolding" -ChildPath $PID
$DestinationFolder = Join-Path -Path "C:\Imports\Input" -ChildPath $PID
if ((Test-Path $SourceFolder) -eq 1)
{
if ((Test-Path $DestinationFolder) -eq 0)
{
mkdir $DestinationFolder
}
$SourceFiles = Get-ChildItem -Path $SourceFolder -Filter "*.dat"
foreach ($SourceFile in $SourceFiles)
{
$DestinationFile = Join-Path -Path $DestinationFolder -ChildPath $SourceFile.Name
Move-Item -Path $SourceFile.FullName -Destination $DestinationFile
}
}
}
$SourceFiles = Get-ChildItem -Path "C:\Imports\NoHolding" -Filter "*.dat"
foreach ($SourceFile in $SourceFiles)
{
$DestinationFile = Join-Path -Path "C:\Imports\Input" -ChildPath $SourceFile.Name
Move-Item -Path $SourceFile.FullName -Destination $DestinationFile
}
使用-File
参数:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\PSScripts\Move No Holdings Milk Files.ps1"
我创建了一个脚本,可以将文件和文件夹从一个文件夹移动到另一个文件夹。我已经在 PowerShell ISE 中设计了它,如果我从那里 运行 它可以完美地工作。
然而,当我 运行 从任务计划程序或命令提示符使用
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass "C:\MilkImports\FileScripts\Move No Holdings Milk Files.ps1"
我收到以下错误
C:\PSScripts\Move : The term 'C:\PSScripts\Move' is not recognized as the name of a cmdlet, function, script file, or operable program.
在我的脚本中唯一引用 Move 是在我使用 Move-Item 时。
我的脚本如下
$SQLServer = "xxx"
$SQLDatabase = "xxx"
$SQLUser = "xxx"
$SQLPassword = "xxx"
$SQLConnection = New-Object System.Data.SqlClient.SqlConnection
$SQLCommand = New-Object System.Data.SqlClient.SqlCommand
$SQLDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$dtPIDs = New-Object System.Data.DataTable
$SQLQuery = "SELECT DISTINCT(PID) FROM table1 t1
INNER JOIN table2 t2 ON t1.CID = t2.CID
WHERE CHARINDEX('UK', areaCode) > 0"
$SQLConnection.ConnectionString = "Server=$SQLServer;Database=$SQLDatabase;Integrated Security=false;User ID=$SQLUser;Password=$SQLPassword;"
$SQLCommand.Connection = $SQLConnection
$SQLCommand.CommandText = $SQLQuery
$SQLDataAdapter.SelectCommand = $SQLCommand
$SQLDataAdapter.Fill($dtPIDs)
foreach($Row in $dtPIDs)
{
$PID = $Row["PID"]
$SourceFolder = Join-Path -Path "C:\Imports\NoHolding" -ChildPath $PID
$DestinationFolder = Join-Path -Path "C:\Imports\Input" -ChildPath $PID
if ((Test-Path $SourceFolder) -eq 1)
{
if ((Test-Path $DestinationFolder) -eq 0)
{
mkdir $DestinationFolder
}
$SourceFiles = Get-ChildItem -Path $SourceFolder -Filter "*.dat"
foreach ($SourceFile in $SourceFiles)
{
$DestinationFile = Join-Path -Path $DestinationFolder -ChildPath $SourceFile.Name
Move-Item -Path $SourceFile.FullName -Destination $DestinationFile
}
}
}
$SourceFiles = Get-ChildItem -Path "C:\Imports\NoHolding" -Filter "*.dat"
foreach ($SourceFile in $SourceFiles)
{
$DestinationFile = Join-Path -Path "C:\Imports\Input" -ChildPath $SourceFile.Name
Move-Item -Path $SourceFile.FullName -Destination $DestinationFile
}
使用-File
参数:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\PSScripts\Move No Holdings Milk Files.ps1"