when the application is from .msi or .msu it's easy to uninstall them from a remote computer using WMI, but WMI only works on Microsoft based applications (.msi, .msu). I can't find a way to uninstall an exe based app remotely without using invoke, I try to not use it because this will be used by many people and on many computers, it's disabled, I can enable it for me but not for everyone (I'm an intern :D)
this is the code that I have for .exe but it's not remote
cmd.exe /c "$($app.meta.Attributes["UninstallString"]) /S"
while this is a remote msi, msu uninstall line
$Application = Get-WmiObject Win32_Product -ComputerName $ComputerName | Where-Object {$_.Name -eq $Name} #choose the object, this will be the app that we will delete
if ($Application) {
$Application.Uninstall()
any suggestion will be appreciated
Related
I want to uninstall an application through powershell scripting which is not a Microsoft product
I have tried with the below code but then it says "you cannot call a method on a null valued expression". This was because it couldn't point to that respective software.
$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "*Software_Name*" }
$app.Uninstall()
And when I tried with Get-RemoteProgram command, it is listing out only the Microsoft softwares.
How to uninstall other softwares?
A possible solution is to find the GUID of the application in the registry in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall and uninstall it using MsiExec:
Start-Process -FilePath MsiExec -ArgumentList '/quiet /uninstall {109A5A16-E09E-4B82-A784-D1780F1190D6}' -Wait
The above example uninstalls the Windows Firewall Configuration Provider.
I already have code written to connect to another computer in my house and pull music files from the C drive. However, I am trying to find out how to keep this code, but modify it in a way that I can use it to run code on the second computer, then save it to a text file.
foreach ($server in Get-Content .\serverList.txt){
psexec \\$server -u username-p password cmd /c dir c:\*.mp3 /s > c:\Powershell\$server.txt
}
You could write a book on PowerShell Remoting (several people have) but it's reasonably straightforward.
On both computers run Enable-PSRemoting to configure all the settings. Then on the originating computer (the one making the remote call) run Set-Item WSMan:\localhost\Client\TrustedHosts -Value '*' (if you are security conscious replace the * with the IP of the remote PC).
Then you can run the all-powerful Invoke-Command to do all sorts of awesome stuff remotely. Unless you're on a domain or there's an identical user on the remote PC you'll need to provide credentials which means either prompting for them or saving them, but if I go into too much detail we'll both be here all day. Pretty easy to find the answers on Google.
$cred = Get-Credential
foreach ($server in Get-Content .\serverList.txt) {
Invoke-Command $server -Credential $cred -ScriptBlock { Get-ChildItem C:\*.mp3 -Recurse } | Out-File C:\Powershell\$server.txt
}
I want to build a script that will Install remotely HP OM agent. Is there any good way to Install it, without having the install files on the remote computer?
this script will install remotely the HP agents for list of servers. I thought to copy the files from my computer to each server and after that to install it. I'm sure there is a better way to do it.
To install the agent I need to run the command :
cscript "\c:\pathToTheAgentFile" -i -a -minprecheck
Using Invoke-Command with the ScriptBlock parameter should accomplish this task so long as a silent install method is used.
$ComputersList = #("computer","names","here","replace","me")
$PathToShare = "\\path\to\install_replace_me.exe"
$CommonLocalComputerPath = "C:\replace_me.exe"
$SilentInstallArgs = "/example","/replace"
$AdministratorCreds = [System.Management.Automation.PSCredential]::Empty
$ComputersList | ForEach-Object {
Invoke-Command -ComputerName $_ -ScriptBlock { Copy-Item $Using:PathToShare -Destination $Using:CommonLocalComputerPath -Credential $Using:AdministratorCreds;
Start-Process $Using:CommonLocalComputerPath -ArgumentList $Using:SilentInstallArgs -Credential $Using:AdministratorCreds} -Credential $AdministratorCreds
}
The above script will prompt for administrative credentials, authenticate to a remote share that holds the installer from the remote computer, copy the installer to the remote computer, and then start the installer on the remote computer. You will have to verify the installs manually as it will not return any data except in the event of a terminating error. The script will have to be modified to point to the correct locations for your environment.
It seems I can not find clearly written somewhere that when using WMI accelerator in a PowerShell script, you can not pass on authentication.
A little background ...
I am writing PowerShell scripts for SCCM 2012 and found, for instance, the following quite using :
PS R:\> ([wmi]((gwmi -namespace root\sms\site_AAA -class SMS_Application -filter
"LocalizedDisplayName LIKE '%Winzip_Tartempion%'")
.__PATH)).SDMPackageXML
When executed locally (on the SCCM primary server, it works fine and swiftly.
However, the following ends up in error when executed from my desktop computer running W7 :
PS R:\> ([wmi]((gwmi -namespace root\sms\site_AAA -credential $cred
-ComputerName CEMTECH
-class SMS_Application -filter "LocalizedDisplayName LIKE
'%Winzip_Tartempion%'")
.__PATH)).SDMPackageXML
For the time being, using a PSSession is out of the question.
With the current infrastructure I have to deal with, using SCCM commandlet is out of the question.
My only question here is : can you confirm that we can not pass any authentication with a WMI accelerator ? At that point, I am searching for that answer mainly for my curiosity. I found a way to manage with my current constraints. It is just that I find the accelerators so "elegant".
Now why do I need it ? I need to access "lazy properties" without using SCCM cmdlets, from a desktop computer to which the user is logged on with an account which will not be the same as the name authorized to connect/access the SCCM primary server.
What I still did not find is how to use "*.__PATH" with the Get-WMIObject cmdlet.
The WMI-accelerator [wmi] doesn't support alternate credentials.
Why do you need it? You could just run:
$obj = Get-WmiObject -namespace root\sms\site_P41 -credential $cred -ComputerName qs07352 -class SMS_Application -filter "LocalizedDisplayName LIKE '%Winzip_Tartempion%'"
$obj.Get()
$obj.SDMPackageXML
I am currently writing a script that has involves a number of uninstalls of programs installed on a WES 7 device. One of the applications I need to uninstall (VMware Horizon View Client) asks for a restart. When this is part of the script, it seems to accept the default button (YES) and proceeds to reboot the device. The script therefore fails.
I would really appreciate your help in how to prevent this reboot from taking place.
FYI: This script is sent down via a management tool and is run in an elevated manner on the target.
This is my script:
set-executionpolicy unrestricted
#############################################################
# Un-install unwanted applications
#############################################################
$application = Get-WMIObject Win32_Product -filter "Name='ThinPrint Client Windows 8.6'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='2X Client'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='Adobe Reader X (10.1.4)'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='VMware Horizon View Client'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='VERDE VDI User Tools'"
$application.Uninstall()
$application = Get-WMIObject Win32_Product -filter "Name='vWorkspace Connector for Windows'"
$application.Uninstall()
#############################################################
# Remove Internet Explorer Access
#############################################################
dism /online /norestart /Disable-Feature /FeatureName:Internet-Explorer-Optional-x86
#############################################################
# Remove IE Browser LNK from Taskbar
#############################################################
del "C:\Users\User\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Launch Internet Explorer Browser.lnk"
#############################################################
# Make Citrix Receiver the shell
#############################################################
Push-Location
CD 'HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon'
New-Itemproperty -path .\ -name Shell -Type String -Value 'c:\program files\Citrix\Receiver\receiver.exe'
Pop-Location
set-executionpolicy restricted
# End of Script
I would very much appreciate some help in how to prevent the reboot half way through the script.
I strongly suggest NOT using Win32_Product. Every time Win32_Product is called it does a software consistency check of each installation. Not only does this make things very slow, it may also trigger a software repair if it finds something wrong.
http://gregramsey.net/2012/02/20/win32_product-is-evil/
Instead go into the registry and just call the uninstall string.
http://support.microsoft.com/kb/247501
You can use msiexec's norestart flag to try to prevent reboots.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa372024(v=vs.85).aspx