invoke-command -session $session -scriptblock {
Function Get-InstalledSoftware {...
}
$uninstallCmd = Get-InstalledSoftware | where-object {$_.name -like "*notepad++*"}`
}
Name : Notepad++ (64-bit x64)
Version : 7.8.8
ComputerName : DESKTOP-K1RH4M9
InstallDate :
UninstallCommand : C:\Program Files\Notepad++\uninstall.exe
RegPath : HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Notepad++
PSComputerName : 192.168.0.24
RunspaceId : 8c303d60-de06-4ccb-b710-089894bed654
------------------------------------------------------
invoke-command -session $session -scriptblock {
Function Get-InstalledSoftware {...
}
$uninstallCmd = Get-InstalledSoftware | where-object {$_.name -like "*notepad++*"}`
Start-Process -Wait -FilePath $uninstallCmd.UninstallCommand -ArgumentList "/S" -PassThru
}
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName PSComputerName
------ ----- ----- ------ -- -- ----------- --------------
3 0.68 1.71 0.05 9880 0 uninstall 192.168.0.24
------------------------------------
Function Get-InstalledSoftware {
Param(
[Alias('Computer','ComputerName','HostName')]
[Parameter(
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$true,
Position=1
)]
[string]$Name = $env:COMPUTERNAME
)
Begin{
$lmKeys = "Software\Microsoft\Windows\CurrentVersion\Uninstall","SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$lmReg = [Microsoft.Win32.RegistryHive]::LocalMachine
$cuKeys = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
$cuReg = [Microsoft.Win32.RegistryHive]::CurrentUser
}
Process{
if (!(Test-Connection -ComputerName $Name -count 1 -quiet)) {
Write-Error -Message "Unable to contact $Name. Please verify its network connectivity and try again." -Category ObjectNotFound -TargetObject $Computer
Break
}
$masterKeys = @()
$remoteCURegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($cuReg,$Name)
$remoteLMRegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($lmReg,$Name)
foreach ($key in $lmKeys) {
$regKey = $remoteLMRegKey.OpenSubkey($key)
foreach ($subName in $regKey.GetSubkeyNames()) {
foreach($sub in $regKey.OpenSubkey($subName)) {
$masterKeys += (New-Object PSObject -Property @{
"ComputerName" = $Name
"Name" = $sub.GetValue("displayname")
"SystemComponent" = $sub.GetValue("systemcomponent")
"ParentKeyName" = $sub.GetValue("parentkeyname")
"Version" = $sub.GetValue("DisplayVersion")
"UninstallCommand" = $sub.GetValue("UninstallString")
"InstallDate" = $sub.GetValue("InstallDate")
"RegPath" = $sub.ToString()
})
}
}
}
foreach ($key in $cuKeys) {
$regKey = $remoteCURegKey.OpenSubkey($key)
if ($regKey -ne $null) {
foreach ($subName in $regKey.getsubkeynames()) {
foreach ($sub in $regKey.opensubkey($subName)) {
$masterKeys += (New-Object PSObject -Property @{
"ComputerName" = $Name
"Name" = $sub.GetValue("displayname")
"SystemComponent" = $sub.GetValue("systemcomponent")
"ParentKeyName" = $sub.GetValue("parentkeyname")
"Version" = $sub.GetValue("DisplayVersion")
"UninstallCommand" = $sub.GetValue("UninstallString")
"InstallDate" = $sub.GetValue("InstallDate")
"RegPath" = $sub.ToString()
})
}
}
}
}
$woFilter = {$null -ne $_.name -AND $_.SystemComponent -ne "1" -AND $null -eq $_.ParentKeyName}
$props = 'Name','Version','ComputerName','Installdate','UninstallCommand','RegPath'
$masterKeys = ($masterKeys | Where-Object $woFilter | Select-Object $props | Sort-Object Name)
$masterKeys
}
End{}
}
No comments:
Post a Comment