not using NT\Authority

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

not using NT\Authority

Post by sekou2331 »

I don't really know where this question should be asked but i will start here since it is not really a GUI question even though I am using a GUI. So I have a GUI project that is very big that uses the line below and other lines that access remote computers. So my first question is there a way to start\run the whole script on the remote computer with different credentials or better yet how would I run the below line with different credentials.

Code: Select all

([WMICLASS]"\\$IpAddress\ROOT\CIMV2:win32_Product").Install($joinPath) | Select-Object -Property returnvalue
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: not using NT\Authority

Post by sekou2331 »

Just to let you know after reading a little I tried the below and it installed but after looking at the event viewer it was not installed by the user I wanted it to be installed by.

Code: Select all

function Test-Creds($item, $username, $password){
 $wmi = [string]::Format("\\{0}\ROOT\CIMV2:Win32_Product",$item)
  $product = [WMIClass]$wmi
     $install = $product.Install("C:\App.msi", "USER=$username PASSWORD=$password", $true)

     if($install.Returnvalue -ne "0"){ Write-host "not installed"}
	
     }


    Test-Creds -item IPAddress -username user -password password
  
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: not using NT\Authority

Post by jvierra »

To install with alternate credentials you would do this.

$class = Get-WmiObject -List Win32_Product -Credentials $creds -ComputerName $computer
$returnValue = $class.Install('c:\app.mis',$options,$true)


https://msdn.microsoft.com/en-us/librar ... s.85).aspx
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: not using NT\Authority

Post by sekou2331 »

So after researching I tried the below and it seems to work. So my question is what is the best method?

Code: Select all

$password = 'Password' | ConvertTo-SecureString -asPlainText -Force
    $username = "Domain\user"
    $credential = New-Object System.Management.Automation.PSCredential($username,$password) 

    (Get-WMIObject  -ComputerName 'Computername' -List -Credential $credential  | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install('C:\App.msi')

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: not using NT\Authority

Post by jvierra »

The first method does not exist and is just wrong. SO is yur last post:

Code: Select all

$password = 'Password' | ConvertTo-SecureString -asPlainText -Force
$username = "Domain\user"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)

$prod = Get-WMIObject -List Win32_Product -ComputerName 'Computername' -Credential $credential
$prod.Install('C:\App.msi')
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked