Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 215 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
copy-item With Alternate Credentials

#1
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..?
Reply

#2
> 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.

<pre>
PS C:\> gcm -syn copy-item
Copy-Item [-Path] <String[]> [[-Destination] <String>] [-Container] [-Force] [-Filter <String>] [-I
nclude <String[]>] [-Exclude <String[]>] [-Recurse] [-PassThru] <u><b>[-Credential <PSCredential>]</b></u> [...]
</pre>
Reply

#3
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
Reply

#4
[Here][1] is a post where someone got it to work. It looks like it requires a registry change.


[1]:

[To see links please register here]

Reply

#5
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.
Reply

#6
This [question][1] addresses a very related issue that may help [using network shares in powershell][2].


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#7
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
Reply

#8
This is an old question but I'm just updating it for future finders.

**PowerShell v3 now supports using the -Credential parameter for filesystem operations.**

Hope this helps others searching for the same solution.
Reply

#9
I know that [PowerShell 3 supports this out of the box][1] now, but for the record, if you're stuck on PowerShell 2, you basically have to either use the legacy `net use` command (as suggested by several others), or [the Impersonation module that I wrote][2] awhile back specifically to address this.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#10
Bringing this back from the dead again. I got around a similar credentials problem by wrapping the .ps1 in a batch file and doing the Win7, Shift + r.Click RunAs. If you wanted to, you can also use PsExec thus:

psexec.exe /accepteula /h /u user /p pwd cmd /c "echo. | powershell.exe -File script.ps1"

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through