1
votes

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
1
maybe i wrong,i think this your case. stackoverflow.com/questions/3917779/…den-gul23
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

1 Answers

-1
votes

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)