not using NT\Authority

Ask your Windows 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.
Locked
User avatar
sekou2331
Posts: 258
Joined: Wed Aug 15, 2012 6:07 am

not using NT\Authority

Post by sekou2331 » Thu Nov 30, 2017 5:14 am

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: 258
Joined: Wed Aug 15, 2012 6:07 am

Re: not using NT\Authority

Post by sekou2331 » Thu Nov 30, 2017 6:00 am

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
  

User avatar
jvierra
Posts: 12379
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: not using NT\Authority

Post by jvierra » Thu Nov 30, 2017 9:21 am

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: 258
Joined: Wed Aug 15, 2012 6:07 am

Re: not using NT\Authority

Post by sekou2331 » Thu Nov 30, 2017 10:47 am

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')


User avatar
jvierra
Posts: 12379
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: not using NT\Authority

Post by jvierra » Thu Nov 30, 2017 11:50 am

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')

Locked