3

I need to connect to a remote server and do some file copies and moves, etc. The remote server requires authentication.

What do I need to enter in for PSCredential -ArgumentList, argument #1? Is it the path to a particular remote user (let's say "Administartor") like

\\SERVER2\Users\Administrator

Or is it simply the username like

Administrator

Or is it the path to the remote resource itself like

\\SERVER2\Data\Content

...

Authenticate the call

$Creds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist "\\Some\Path",$PW
 Copy-Item  $src $destination -Credential $Creds
4

No, this is not how PSCredential objects work. I think you're overthinking it.

A System.Management.Automation.PSCredential object has two properties: SecureString Password and String UserName.

$Creds = Get-Credential

or

$Creds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist "DOMAIN\joebob", $PW

where $PW is a SecureString object. One way to create a SecureString:

PS C:\> $Secure = ConvertTo-SecureString "Pass.1234!" -AsPlainText -Force

PSCredential documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/system.management.automation.pscredential_members(v=vs.85).aspx

Edit: The Copy-Item cmdlet, for instance, supports the -Credential argument. So Copy-Item C:\list.txt \\Server02\list.txt -Credential $Creds

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.