Page 1 of 1
Multi-Form - credential passing
Posted: Tue Jan 01, 2019 11:00 pm
by lontru
Hi working on a tool
I want this functionality:
Main form get user credential : get-credential
Launch a child form with these credential.
So somehow do a runas on the childForm would be great but how?
Code: Select all
$buttonCallChildForm_Click={
#TODO: Place custom script here
if((Show-ChildForm_psf) -eq 'OK')
{
}
}
The child form is a tool for deleting device in SCCM so the user need access right to the configmgr module and the cmsite psdrive.
What solutions is possible to achieve above functionality
Re: Multi-Form - credential passing
Posted: Wed Jan 02, 2019 3:22 am
by jvierra
You cannot do this. You can only start a completely new process with new credentials.
Re: Multi-Form - credential passing
Posted: Wed Jan 02, 2019 11:50 pm
by lontru
Have sleep on this and come up with to ways
1. Call another exe with start-process -credential
a single form exe created from psf can you pass param to this exe or do you need to build it as a project?
2. Convert the project main to support param.
Main call it self with start-process -credential but with param to start up the right sub psf inside the main.
way 1 would be easy to do but then i have a lot of files to manage. way 2 keep it all in same project....simpler to manage
is above solutions possible?
Re: Multi-Form - credential passing
Posted: Thu Jan 03, 2019 11:58 am
by jvierra
Here is perhaps a better way to do this. See the attached project.
THis is the only way to pass objects to a new process. With Start-Process you can only pass strings.
Re: Multi-Form - credential passing
Posted: Fri Jan 04, 2019 2:57 am
by lontru
it work like a charm...
have work a little with your demo...is there a way open more then one sub psf form? right now it lock so you need to close a open subform before you can start a new subform?
Code: Select all
$buttonCallChildForm_Click={
$sb = ${function:Show-ChildForm_psf}
$obj = [pscustomobject]@{Text = 'Hello World!'}
$job = Start-Job -ScriptBlock $sb -Credential $cred -ArgumentList $obj
$job | Wait-Job | Remove-Job
}
$buttonGetCredential_Click={
$script:cred = Get-Credential -ErrorAction SilentlyContinue
$buttonGetCredential.Text = $cred.UserName
}
Re: Multi-Form - credential passing
Posted: Fri Jan 04, 2019 5:14 am
by jvierra
lontru wrote: ↑Fri Jan 04, 2019 2:57 am
have work a little with your demo...is there a way open more then one sub psf form
Comment the line:
$job | Wait-Job | Remove-Job
You can now open multiple forms. Run a timer to remove jobs that complete when the child form is closed.
Re: Multi-Form - credential passing
Posted: Tue Jan 08, 2019 2:20 am
by lontru
_How do i perform a cleanup routine when the childform is closing?
So i need to pass a unique id to the childform as a argument and pass that to remove-job when the child form is closing?
Or does all the jobs disappear when the mainform closeds?
Re: Multi-Form - credential passing
Posted: Tue Jan 08, 2019 5:14 am
by jvierra
You can give a job a name.
When the job is complete you can detect that it is complete and remove it.