So I'm trying to build a powershell monitor which just copies certain file to another server. Both servers are connected to domain and I have admin rights on both of the servers.
# Arguments example: hostname $transfer_host = $args.get(0); $lockfile = "C:\temp\$transfer_host.lock" $Error.Clear(); if ( $lockfile -eq $null ) { Write-Host "Message: lockfile found. exiting." exit 1 } if ( $transfer_host -eq $null ) { Write-Host "Message: Can't find ""$transfer_host"" hostname . exiting." exit 1 } echo $null >> $lockfile $output=Measure-Command {Copy-Item -Credential ${CREDENTIAL} C:\temp\output.dat -Destination \\$transfer_host\c$\temp} | Select TotalMinutes rm $lockfile Write-Host $output exit 0;
But with this I get:
Output: ==============================================
@{TotalMinutes=0.00939928166666667}
Errors: ==============================================
The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying credentials.
At line:17 char:26
+ $output=Measure-Command {Copy-Item -Credential username C:\temp\output.dat.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [], PSNotSupportedException
+ FullyQualifiedErrorId : NotSupported
So is there a way around this somehow? If I don't put the credentials this way I just get "access denied" which means that this powershell script doesn't seem to inherit my credentials from template. And on top of that I'm trying to achieve this with the new agent feature.