I have this block in my deployment script which I am running on the build machine. It should move files on staging machine from Installs folder to application folder.
Before this block, there are several more actions successfuly executed with Invoke-Session

write-host "Deploying" -foregroundcolor red -backgroundcolor yellow
invoke-command -session $s {
    Get-ChildItem -Path "C:\Install\pre_master" | Copy-Item -Destination "C:\inetpub\wwwroot\pre_master" -force -Recurse 

If I create a session manually in PS and paste this block, it works ok.

If I run the script, this step spams me with millions (for every file Im trying to move I suppose?)

The input object cannot be bound to any parameters for the command either because the command does not take pipeline in put or the input and its properties do not match any of the parameters that take pipeline input. + CategoryInfo : InvalidArgument: (0201-KS.xml:PSObject) [Copy-Item], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.CopyItemCommand

So my question is : Why this same block of code works in PS when executed manually. but doesnt work in script?

Both machines have powershell 2.0


I'm still don't know why, but you cannot use the pipeline when you run some cmdlets by using Remote session. You can first store the result of a cmdlet in a variable and then write a foreach loop to pipe the result of the cmdlet to another cmdlet.

For example, you can first store the result of a cmdlet in a variable and then writing a foreach loop to copy the files:

invoke-command -session $s {
    $files = Get-ChildItem -Path "C:\Install\pre_master"; Foreach($file in $files) { Copy-Item -Path $file -Destination "C:\inetpub\wwwroot\pre_master" -force Recurse} 
  • I have another script for different application that runs the same copy-item like in my provided sample, and it works.. The webserver is different though, I'm starting to think this might have corrupted windows/powershell... – evictednoise Nov 24 '16 at 13:49
  • And well, as I mentioned in question, if I execute the same invoker-command in PS manually, it works. Just doesnt work in a script – evictednoise Nov 24 '16 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.