2

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

2 Answers 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} } 
2
  • 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... Commented Nov 24, 2016 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 Commented Nov 24, 2016 at 13:54
0

You are probably a victim of the infamous double hop issue. You are using a session for the remote server. But that session won't cache your credentials by default unless you pass it actively. So in the next step, when the script is accessing another machine, your credentials is missing.

But I can't tell, how changing from piped commands to a foreach loop, would affect this.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.