views:

1539

answers:

6

I'm using the CTP of powershell v2. I have a script written that needs to go out to various network shares in our dmz and copy some files. However, the issue I have is that evidently powershell's cmdlets such as copy-item, test-path, etc do not support alternate credentials...

Anyone have a suggestion on how best to accomplish my task..?

A: 

that evidently powershell's cmdlets such as copy-item, test-path, etc do not support alternate credentials...

It looks like they do here, copy-item certainly includes a -Credential parameter.

PS C:\> gcm -syn copy-item
Copy-Item [-Path] <String[]> [[-Destination] <String>] [-Container] [-Force] [-Filter <String>] [-I
nclude <String[]>] [-Exclude <String[]>] [-Recurse] [-PassThru] [-Credential <PSCredential>] [...]
Richard
I keep receiving a error message stating -credential is not supported
Jason
TechNet (http://technet.microsoft.com/en-us/library/dd315340.aspx) says "This parameter is not supported by any providers installed with Windows PowerShell." So they're too lazy to implement it and just expect anyone creating a new provider to do it. :(
Darrell Mozingo
A: 

You should be able to pass whatever credentials you want to the -Credential parameter. So something like:

$cred = Get-Credential

[Enter the credentials]

Copy-Item -Path $from -Destination $to -Credential $cred

EBGreen
I keep receiving a error message stating -credential is not supported
Jason
I suspect it is an issue with unc pathing then.
EBGreen
well, this is the error...Test-Path : Cannot retrieve the dynamic parameters for the cmdlet. The provider does not support the use of credentials. Please perform the operation again without specifying credentials.
Jason
and the UNC looks like this...\\ip\Logs
Jason
A: 

Here is a post where someone got it to work. It looks like it requires a registry change.

notandy
That guy is double hopping within the same domain. I need to be able to specify an account as I am accessing files on a different domain altogether...
Jason
+3  A: 

I would try to map a drive to the remote system (using 'net use' or WshNetwork.MapNetworkDrive, both methods support credentials) and then use copy-item.

Shay Levy
This is the best answer because the filesystem provider (and thus copy-item) does not support credentials.
halr9000
A: 

This question addresses a very related issue that may help using network shares in powershell.

eddiegroves
+1  A: 

Since PowerShell doesn't support "-Credential" usage via many of the cmdlets (very annoying), and mapping a network drive via WMI proved to be very unreliable in PS, I found pre-caching the user credentials via a net use command to work quite well:

# cache credentials for our network path
net use \\server\C$ $password /USER:$username

Any operation that uses \\server\C$ in the path seems to work using the *-item cmdlets.

You can also delete the share when you're done:

net use \\server\C$ /delete
wes