Start-Process, mklink and encrypted/stored credentials, oh my












0















I am working on a way to create a Symlink as a standard user, to address the situation outlined here.
I have created a password file and an AES key as shown here.
And I have this code, which without the credential stuff, but run from an elevated ISE, works as intended, creating a symlink in the root of C that points to the created folder in root of C.
But, when run unelevated it doesn't create the symlink, nor does it throw an error of any kind. It acts the same as if there was no credentials in use.



$passwordFile = "\MacSupportPx Toolsx_PS DevSymLink_password.txt"
$keyFile = "\MacSupportPx Toolsx_PS DevSymLink_AES.key"
$user = 'Px_Install'
$key = Get-Content $keyFile
$credential = New-Object -typeName:System.Management.Automation.PSCredential -argumentList:@($user, (Get-Content $passwordFile | ConvertTo-SecureString -key:$key))

if (-not (Test-Path 'C:_Real')) {
New-Item 'C:_Real' -itemType:directory > $null
}
if (-not (Test-Path 'C:_Realreal.txt')) {
New-Item 'C:_Realreal.txt' -itemType:file > $null
}
try {
Start-Process -filePath:cmd.exe -windowStyle:hidden -argumentList:('/c', 'mklink', '/d', 'C:C4RLink', "`"C:_Real`"") -credential:$credential -errorAction:stop
} catch {
Write-Host "Error"
}


So, three questions I guess.



1: Is there any way to test the validity of the created credential? I used $credential.GetType and it returns



OverloadDefinitions
-------------------
type GetType()


Which may or may not be correct, not sure.



2: Is there something wrong with my use of Start-Process?



3: Is there a way to actually trap meaningful errors or is cmd.exe so primitive I am stuck checking to see if the link exists post Start-Process and throwing my own error?
I tried



$results = Start-Process -filePath:cmd.exe -windowStyle:hidden -argumentList:('/c', 'mklink', '/d', 'C:C4RLink', "`"C:_Real`"") -credential:$credential -errorAction:stop -passThru
Write-Host "$results"


and it produces System.Diagnostics.Process (cmd) which isn't so helpful.



Speaking of Windows 7, I just tested it in Windows 7/PS2.0, and it DOES throw an error, but in Windows 10 it doesn't. Gawd Micros0ft, can't you get your shit together, EVER? but, maybe a thread to follow. Also going to try getting credentials another way, to eliminate that variable.



FWIW, I tried NOT wrapping the argument list in an array, in fact I started with that. But it didn't work so I tried the array on a lark.



EDIT: So, trying it in Windows 7 does produce an error, which is Parameter set cannot be resolved using the specified named parameters. I also realized I needed -verb:Runas in there. Added that, and switched my credentials to use Get-Credential for now. But still getting parameter set issues. Sigh.



Edit2: Seems to not like -verb or -windowsStyle in Windows 7/PS2.0. The latter is no big deal I guess, but -verb is pretty much required to get this to work methinks.



Edit3: nope, seems not to like -verb in Windows 10 either. But I have it reporting exceptions now, so thats a form of progress.



EDIT4: getting closer. I now have this



Start-Process powershell -credential (Get-Credential 'Px_Install') -argumentList "-noprofile -command &{Start-Process -filePath cmd.exe -argumentList '/c', 'mklink', '/d', 'C:C4RLink', 'C:_Real' -verb runas}"


And it works, but it raises a UAC dialog, which pretty much makes it useless.










share|improve this question

























  • You can create symlinks with New-Item FYI.

    – TheIncorrigible1
    Nov 21 '18 at 21:06











  • @TheIncorrigible You can if you are in a newer version of PowerShell. I have to support back to PS2.0 (sad trombone). Plus, My understanding is you still have elevation issues, which I would assume need to be solved the same way.

    – Gordon
    Nov 21 '18 at 21:09
















0















I am working on a way to create a Symlink as a standard user, to address the situation outlined here.
I have created a password file and an AES key as shown here.
And I have this code, which without the credential stuff, but run from an elevated ISE, works as intended, creating a symlink in the root of C that points to the created folder in root of C.
But, when run unelevated it doesn't create the symlink, nor does it throw an error of any kind. It acts the same as if there was no credentials in use.



$passwordFile = "\MacSupportPx Toolsx_PS DevSymLink_password.txt"
$keyFile = "\MacSupportPx Toolsx_PS DevSymLink_AES.key"
$user = 'Px_Install'
$key = Get-Content $keyFile
$credential = New-Object -typeName:System.Management.Automation.PSCredential -argumentList:@($user, (Get-Content $passwordFile | ConvertTo-SecureString -key:$key))

if (-not (Test-Path 'C:_Real')) {
New-Item 'C:_Real' -itemType:directory > $null
}
if (-not (Test-Path 'C:_Realreal.txt')) {
New-Item 'C:_Realreal.txt' -itemType:file > $null
}
try {
Start-Process -filePath:cmd.exe -windowStyle:hidden -argumentList:('/c', 'mklink', '/d', 'C:C4RLink', "`"C:_Real`"") -credential:$credential -errorAction:stop
} catch {
Write-Host "Error"
}


So, three questions I guess.



1: Is there any way to test the validity of the created credential? I used $credential.GetType and it returns



OverloadDefinitions
-------------------
type GetType()


Which may or may not be correct, not sure.



2: Is there something wrong with my use of Start-Process?



3: Is there a way to actually trap meaningful errors or is cmd.exe so primitive I am stuck checking to see if the link exists post Start-Process and throwing my own error?
I tried



$results = Start-Process -filePath:cmd.exe -windowStyle:hidden -argumentList:('/c', 'mklink', '/d', 'C:C4RLink', "`"C:_Real`"") -credential:$credential -errorAction:stop -passThru
Write-Host "$results"


and it produces System.Diagnostics.Process (cmd) which isn't so helpful.



Speaking of Windows 7, I just tested it in Windows 7/PS2.0, and it DOES throw an error, but in Windows 10 it doesn't. Gawd Micros0ft, can't you get your shit together, EVER? but, maybe a thread to follow. Also going to try getting credentials another way, to eliminate that variable.



FWIW, I tried NOT wrapping the argument list in an array, in fact I started with that. But it didn't work so I tried the array on a lark.



EDIT: So, trying it in Windows 7 does produce an error, which is Parameter set cannot be resolved using the specified named parameters. I also realized I needed -verb:Runas in there. Added that, and switched my credentials to use Get-Credential for now. But still getting parameter set issues. Sigh.



Edit2: Seems to not like -verb or -windowsStyle in Windows 7/PS2.0. The latter is no big deal I guess, but -verb is pretty much required to get this to work methinks.



Edit3: nope, seems not to like -verb in Windows 10 either. But I have it reporting exceptions now, so thats a form of progress.



EDIT4: getting closer. I now have this



Start-Process powershell -credential (Get-Credential 'Px_Install') -argumentList "-noprofile -command &{Start-Process -filePath cmd.exe -argumentList '/c', 'mklink', '/d', 'C:C4RLink', 'C:_Real' -verb runas}"


And it works, but it raises a UAC dialog, which pretty much makes it useless.










share|improve this question

























  • You can create symlinks with New-Item FYI.

    – TheIncorrigible1
    Nov 21 '18 at 21:06











  • @TheIncorrigible You can if you are in a newer version of PowerShell. I have to support back to PS2.0 (sad trombone). Plus, My understanding is you still have elevation issues, which I would assume need to be solved the same way.

    – Gordon
    Nov 21 '18 at 21:09














0












0








0








I am working on a way to create a Symlink as a standard user, to address the situation outlined here.
I have created a password file and an AES key as shown here.
And I have this code, which without the credential stuff, but run from an elevated ISE, works as intended, creating a symlink in the root of C that points to the created folder in root of C.
But, when run unelevated it doesn't create the symlink, nor does it throw an error of any kind. It acts the same as if there was no credentials in use.



$passwordFile = "\MacSupportPx Toolsx_PS DevSymLink_password.txt"
$keyFile = "\MacSupportPx Toolsx_PS DevSymLink_AES.key"
$user = 'Px_Install'
$key = Get-Content $keyFile
$credential = New-Object -typeName:System.Management.Automation.PSCredential -argumentList:@($user, (Get-Content $passwordFile | ConvertTo-SecureString -key:$key))

if (-not (Test-Path 'C:_Real')) {
New-Item 'C:_Real' -itemType:directory > $null
}
if (-not (Test-Path 'C:_Realreal.txt')) {
New-Item 'C:_Realreal.txt' -itemType:file > $null
}
try {
Start-Process -filePath:cmd.exe -windowStyle:hidden -argumentList:('/c', 'mklink', '/d', 'C:C4RLink', "`"C:_Real`"") -credential:$credential -errorAction:stop
} catch {
Write-Host "Error"
}


So, three questions I guess.



1: Is there any way to test the validity of the created credential? I used $credential.GetType and it returns



OverloadDefinitions
-------------------
type GetType()


Which may or may not be correct, not sure.



2: Is there something wrong with my use of Start-Process?



3: Is there a way to actually trap meaningful errors or is cmd.exe so primitive I am stuck checking to see if the link exists post Start-Process and throwing my own error?
I tried



$results = Start-Process -filePath:cmd.exe -windowStyle:hidden -argumentList:('/c', 'mklink', '/d', 'C:C4RLink', "`"C:_Real`"") -credential:$credential -errorAction:stop -passThru
Write-Host "$results"


and it produces System.Diagnostics.Process (cmd) which isn't so helpful.



Speaking of Windows 7, I just tested it in Windows 7/PS2.0, and it DOES throw an error, but in Windows 10 it doesn't. Gawd Micros0ft, can't you get your shit together, EVER? but, maybe a thread to follow. Also going to try getting credentials another way, to eliminate that variable.



FWIW, I tried NOT wrapping the argument list in an array, in fact I started with that. But it didn't work so I tried the array on a lark.



EDIT: So, trying it in Windows 7 does produce an error, which is Parameter set cannot be resolved using the specified named parameters. I also realized I needed -verb:Runas in there. Added that, and switched my credentials to use Get-Credential for now. But still getting parameter set issues. Sigh.



Edit2: Seems to not like -verb or -windowsStyle in Windows 7/PS2.0. The latter is no big deal I guess, but -verb is pretty much required to get this to work methinks.



Edit3: nope, seems not to like -verb in Windows 10 either. But I have it reporting exceptions now, so thats a form of progress.



EDIT4: getting closer. I now have this



Start-Process powershell -credential (Get-Credential 'Px_Install') -argumentList "-noprofile -command &{Start-Process -filePath cmd.exe -argumentList '/c', 'mklink', '/d', 'C:C4RLink', 'C:_Real' -verb runas}"


And it works, but it raises a UAC dialog, which pretty much makes it useless.










share|improve this question
















I am working on a way to create a Symlink as a standard user, to address the situation outlined here.
I have created a password file and an AES key as shown here.
And I have this code, which without the credential stuff, but run from an elevated ISE, works as intended, creating a symlink in the root of C that points to the created folder in root of C.
But, when run unelevated it doesn't create the symlink, nor does it throw an error of any kind. It acts the same as if there was no credentials in use.



$passwordFile = "\MacSupportPx Toolsx_PS DevSymLink_password.txt"
$keyFile = "\MacSupportPx Toolsx_PS DevSymLink_AES.key"
$user = 'Px_Install'
$key = Get-Content $keyFile
$credential = New-Object -typeName:System.Management.Automation.PSCredential -argumentList:@($user, (Get-Content $passwordFile | ConvertTo-SecureString -key:$key))

if (-not (Test-Path 'C:_Real')) {
New-Item 'C:_Real' -itemType:directory > $null
}
if (-not (Test-Path 'C:_Realreal.txt')) {
New-Item 'C:_Realreal.txt' -itemType:file > $null
}
try {
Start-Process -filePath:cmd.exe -windowStyle:hidden -argumentList:('/c', 'mklink', '/d', 'C:C4RLink', "`"C:_Real`"") -credential:$credential -errorAction:stop
} catch {
Write-Host "Error"
}


So, three questions I guess.



1: Is there any way to test the validity of the created credential? I used $credential.GetType and it returns



OverloadDefinitions
-------------------
type GetType()


Which may or may not be correct, not sure.



2: Is there something wrong with my use of Start-Process?



3: Is there a way to actually trap meaningful errors or is cmd.exe so primitive I am stuck checking to see if the link exists post Start-Process and throwing my own error?
I tried



$results = Start-Process -filePath:cmd.exe -windowStyle:hidden -argumentList:('/c', 'mklink', '/d', 'C:C4RLink', "`"C:_Real`"") -credential:$credential -errorAction:stop -passThru
Write-Host "$results"


and it produces System.Diagnostics.Process (cmd) which isn't so helpful.



Speaking of Windows 7, I just tested it in Windows 7/PS2.0, and it DOES throw an error, but in Windows 10 it doesn't. Gawd Micros0ft, can't you get your shit together, EVER? but, maybe a thread to follow. Also going to try getting credentials another way, to eliminate that variable.



FWIW, I tried NOT wrapping the argument list in an array, in fact I started with that. But it didn't work so I tried the array on a lark.



EDIT: So, trying it in Windows 7 does produce an error, which is Parameter set cannot be resolved using the specified named parameters. I also realized I needed -verb:Runas in there. Added that, and switched my credentials to use Get-Credential for now. But still getting parameter set issues. Sigh.



Edit2: Seems to not like -verb or -windowsStyle in Windows 7/PS2.0. The latter is no big deal I guess, but -verb is pretty much required to get this to work methinks.



Edit3: nope, seems not to like -verb in Windows 10 either. But I have it reporting exceptions now, so thats a form of progress.



EDIT4: getting closer. I now have this



Start-Process powershell -credential (Get-Credential 'Px_Install') -argumentList "-noprofile -command &{Start-Process -filePath cmd.exe -argumentList '/c', 'mklink', '/d', 'C:C4RLink', 'C:_Real' -verb runas}"


And it works, but it raises a UAC dialog, which pretty much makes it useless.







powershell symlink credentials






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 22:03







Gordon

















asked Nov 21 '18 at 20:49









GordonGordon

1,645929




1,645929













  • You can create symlinks with New-Item FYI.

    – TheIncorrigible1
    Nov 21 '18 at 21:06











  • @TheIncorrigible You can if you are in a newer version of PowerShell. I have to support back to PS2.0 (sad trombone). Plus, My understanding is you still have elevation issues, which I would assume need to be solved the same way.

    – Gordon
    Nov 21 '18 at 21:09



















  • You can create symlinks with New-Item FYI.

    – TheIncorrigible1
    Nov 21 '18 at 21:06











  • @TheIncorrigible You can if you are in a newer version of PowerShell. I have to support back to PS2.0 (sad trombone). Plus, My understanding is you still have elevation issues, which I would assume need to be solved the same way.

    – Gordon
    Nov 21 '18 at 21:09

















You can create symlinks with New-Item FYI.

– TheIncorrigible1
Nov 21 '18 at 21:06





You can create symlinks with New-Item FYI.

– TheIncorrigible1
Nov 21 '18 at 21:06













@TheIncorrigible You can if you are in a newer version of PowerShell. I have to support back to PS2.0 (sad trombone). Plus, My understanding is you still have elevation issues, which I would assume need to be solved the same way.

– Gordon
Nov 21 '18 at 21:09





@TheIncorrigible You can if you are in a newer version of PowerShell. I have to support back to PS2.0 (sad trombone). Plus, My understanding is you still have elevation issues, which I would assume need to be solved the same way.

– Gordon
Nov 21 '18 at 21:09












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420261%2fstart-process-mklink-and-encrypted-stored-credentials-oh-my%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420261%2fstart-process-mklink-and-encrypted-stored-credentials-oh-my%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$