1

How to create a credential of my current user in PowerShell (without prompt)?

I invoke a remote script with a service account credential (on SCCM server), I would like to send it my current credential because this remote script needs my local credential to write on my local hard drive (during mastering). Both computers are in same domain, but my service account is not allowed to write on my local hard drive.

Edit :

1) I can't use the $Password way because I don't know who is logged (and password)

2) I already have a PSSession. My PSSession is with a service account But my remote script need my local credential I need 2 credentials

Invoke-Command -Session $RemoteServerSession -ScriptBlock $ScriptBlock -ArgumentList $LocalWorkstationSession

Because in my remote script I do want to do

$DriveOnWorkstation = New-PSDrive -Credential $LocalWorkstationSession -Name MyDrive -Root $UNCWorkstationFolderPath -PSProvider FileSystem
Goood
  • 21
  • 1
  • 5
  • 1
    maybe i wrong,i think this your case. https://stackoverflow.com/questions/3917779/get-current-users-credentials-object-in-powershell-without-prompting – den-gul23 Nov 30 '17 at 14:02
  • Thank's ! It's my case "construct a PSCredential object from the current Powershell user" "Powershell can't get to them. Its an intentional feature of the security subsystem" So, impossible to do it. – Goood Dec 01 '17 at 07:29

1 Answers1

-1

show the current script.

also, you can use

PS> $s = New-PSSession -ComputerName localhost
PS> Invoke-Command -Session $s -Script { param($processId) Get-Process -Id $processId } -Args $pid

or

$Password = ConvertTo-SecureString "password" -AsPlainText -Force

$Credential = New-Object System.Management.Automation.PSCredential (“Login”, $Password)
  • You answered my question in comment of my question. How to vote, and say that you solved my question by this comment ? – Goood Dec 01 '17 at 10:00
  • This is not an answer to the question. Powershell does not give what it is wanted in the question. You might store secure string before script execution for once, and then use that string on PSCredential object. – metzelder Dec 09 '19 at 12:37