English 中文(简体)
A. 强权书上的 Wei行为
原标题:Weird behaviour in Powershell script
  • 时间:2010-09-08 13:30:19
  •  标签:
  • powershell

我检查了一个使用“清点-工作中心”的项目的一份工作副本,随后删除使用“清理-工作中心”的名录(这些职能的代码在结束)。

问题 我正面临:

  1. Instead of echoing "Checking out from svn://somePath1 to C:/somePath2" it echoes "Checking out from svn://somePath1 C:/somePath2 to"
  2. 在清理工作中心,它在试图执行<代码>Pushd时留下了以下错误。

    <Push-Location : Cannot convert  System.Object[]  to the type  System.String  
    required by parameter  LiteralPath . Specified method is not supported.
        + Pushd <<<<  $directory
        + CategoryInfo : InvalidArgument: (:) [Push-Location], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.PushLocationCommand>
  3. 最后,我看到了“<代码>”的错误:“指示的辛醇/代码”在执行<代码>时不正确。

我使用的职能如下。 我检查了交给这些职务的论点,这些论点是正确的。

#Checks out a copy from svnPath into appFilePath
Function Checkout-WorkingCopy($svnPath, $appFilePath) {

    Echo "Checking out from $svnPath to $appFilePath"

    svn checkout $svnPath $appFilePath --quiet

    Echo "Checkout Done"
}

#Deletes the working copy previously checked out
Function Cleanup-WorkingCopy($directory, $appFilePath) {

    Pushd $directory
    Cmd /C "Rmdir /S /Q $appFilePath"
}
最佳回答

看起来,像美元直接值一样,正在通过一系列价值观。 当你需要像检查所传递的价值那样做ug。 仅使用PowerShell s Remove-Item tridlet, 而不是 out碎:

Function Cleanup-WorkingCopy($directory, $appFilePath) { 
    $directory | Foreach {"$($_.GetType().Fullname): $_" }
    Pushd $directory 
    Remove-Item $appFilePath -Recurse -Force
}

实际上,按照这种办法,你不需要总费用,可以把整个职能改为:

Remove-Item $appFilePath -Recurse -Force
问题回答

暂无回答




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

热门标签