I am really trying to write a script to install MSI's. I know to use WIN32_Product to do installs with powershell. I understand how to write it in VBscript but cant seem to get it right in powershell. I found the script below but it is not working. I seem to not understand the syntex.
(Get-WmiObject Win32_product -ComputerName 10.0.0.0 -List | Where-Object -FilterScript{$_.Name -eq "Win32_Product"}).install ("C:installPathinstall.msi")
MSI install Script
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.
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.
MSI install Script
$cls=Get-WmiObject -list Win32_product -ComputerName 10.0.0.0
$cls.Install('C:installPathinstall.msi')
Alternate one-line form:
([wmiclass]'computernamerootCimV2:Win32_Product').Install($package)
jvierra2012-08-24 11:10:35
$cls.Install('C:installPathinstall.msi')
Alternate one-line form:
([wmiclass]'computernamerootCimV2:Win32_Product').Install($package)
jvierra2012-08-24 11:10:35
MSI install Script
This works but the uninstall works on all computers in the Comptr.txt while the the install part of the script doesnt. For some reason it just install on the computer i am running this script from. THe script is below. $ErrorActionPreference = "silentlycontinue"$Software=[wmiclass]'rootcimv2:Win32_Product' $list = get-Content -Path "C:Comptr.txt"# your hosts go here$name = 'Unitalled Program' # your application name goes here (as displayed by win32_product instance)$list | foreach { $hostname = $_ gwmi win32_product -filter "Name = '$name'" -namespace root/cimv2 -comp $_ | foreach { if ($_.uninstall().returnvalue -eq 0) {ForEach-Object {$Software.Install('c:tdinstallSoftware.msi') } } else { write-warning "Failed to unnstall $name from $($hostname)." } } }
MSI install Script
Your right it would but I do not have that type of access to AD but i have rights to the computers i control. So the below will only work with one computer and not a list of computers ? Just want it to read from the list in the script. $Software=[wmiclass]'-computername $_rootcimv2:Win32_Product'
MSI install Script
Thank you for taking the time with this and helping me understand. As for the -computername i thought you had to add before the $_ to tell powershell that it is the computername . In my script after the foreach object I was trying to make the program install so i thought it had to be the there as add variable. Also this "$software=[wmiclass]"$_rootcimv2:Win32_Product"" doesnt work when i try to use on a list of computer like the script below $product=[wmiclass]"$_rootcimv2:Win32_Product"Get-Content V:IP.txt | ForEach-Object{$product.Install('c:tdinstallProgram.msi') }
MSI install Script
I recommnd geting a book on scritping wih POwerShell and learning how to use it. You are just repeatedly guessing at what will work.
You cannot use scritping byjust guesig at it. It is necessary to learn the basics at some point or you will be wasting a lot of your time.
When we use teh $_ vraible it is only available inside of a pileline. You used a pipeline to do the initial code so I assumed you knew what a pipeline was. I see now you just copied some code and proceeded to to use. it.
The only place the $_ contains a vaue is inside the pipeline.
You cannot use scritping byjust guesig at it. It is necessary to learn the basics at some point or you will be wasting a lot of your time.
When we use teh $_ vraible it is only available inside of a pileline. You used a pipeline to do the initial code so I assumed you knew what a pipeline was. I see now you just copied some code and proceeded to to use. it.
The only place the $_ contains a vaue is inside the pipeline.
Code: Select all
Get-Content V:IP.txt |
ForEach-Object{
$product=[wmiclass]"$_rootcimv2:Win32_Product"
$product.Install('c:tdinstallProgram.msi')
}
MSI install Script
It wouldn't work that way in VBScript ewither. In fact it qouldn't work in any language.
If you are assigning a value in a loop then the variable being assigned has to be used inside the loop. It is not valid anywhere outside of the loop.
If you are assigning a value in a loop then the variable being assigned has to be used inside the loop. It is not valid anywhere outside of the loop.