Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

OPEN Running script in user context

  • Thread starter Thread starter VodKen
  • Start date Start date
  • Replies Replies 2
  • Views Views 11K

VodKen

New Member
Messages
1
Reaction score
1
Points
1
Hello everyone,
I'm looking for a way to run scripts not via the system user but rather for the logged in user. The background is that I want to read out the user's certificates which are about to expire. Is there a possibility here?
 
Hello everyone,
I'm looking for a way to run scripts not via the system user but rather for the logged in user. The background is that I want to read out the user's certificates which are about to expire. Is there a possibility here?
If it is a powershell script, you could actually input the username and password with parameter in your SCCM script, and the make the script declare a credential object with those parameters and do a PSSession to the machine itself with these credentials and voila, you are able to execute your powershell script inside that "wrapper"

Use this as an example.

Code:
Param(
    [Parameter(Mandatory=$True, Position = 0)]
    [String]$Username,
    
    [Parameter(Mandatory=$True, Position = 1)]
    [String]$Password
)

$CredentialPassword = ConvertTo-SecureString $Password -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($Username, $CredentialPassword)

$ComputerName = ([System.Net.Dns]::GetHostByName($env:computerName)).HostName

$CommandResult = Invoke-Command -ComputerName $ComputerName -ScriptBlock {
    $ObjectProperties = @{
        ComputerName = ([System.Net.Dns]::GetHostByName($env:computerName)).HostName
        Username = $env:USERNAME
        UserDomain = $env:USERDOMAIN
    }   
    $Result = New-Object -TypeName psobject -Property $ObjectProperties
    return $Result
} -Credential $Credential

return $CommandResult
 
Hello everyone,
I'm looking for a way to run scripts not via the system user but rather for the logged in user. The background is that I want to read out the user's certificates which are about to expire. Is there a possibility here?
This is a loaded question? Can you run a script in user mode? For sure, use Packages running in user context.

Can you run scripts using CM console? No.
 

Forum statistics

Threads
7,171
Messages
27,990
Members
18,297
Latest member
Kahnrym

Trending content

Back
Top