mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-02-25 14:33:44 +01:00
First commit, only with CLI tools
This commit is contained in:
76
client/ADcomputerData.ps1
Normal file
76
client/ADcomputerData.ps1
Normal file
@@ -0,0 +1,76 @@
|
||||
$root = $PSCommandPath | Split-Path -Parent
|
||||
. $root\config.ps1
|
||||
|
||||
$table = (Invoke-RestMethod -Method Get -Uri "$server/get/computers") # Get all computers
|
||||
$DNSPrefix = (get-DnsClientGlobalSetting).SuffixSearchList[0] # Get DNS Prefix, needed to search computers in some environments
|
||||
|
||||
|
||||
$array = @()
|
||||
|
||||
function getPrograms($computername) {
|
||||
|
||||
|
||||
#Define the variable to hold the location of Currently Installed Programs
|
||||
|
||||
$UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
|
||||
|
||||
#Create an instance of the Registry Object and open the HKLM base key
|
||||
|
||||
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername)
|
||||
|
||||
#Drill down into the Uninstall key using the OpenSubKey Method
|
||||
|
||||
$regkey=$reg.OpenSubKey($UninstallKey)
|
||||
|
||||
#Retrieve an array of string that contain all the subkey names
|
||||
|
||||
$subkeys=$regkey.GetSubKeyNames()
|
||||
|
||||
#Open each Subkey and use GetValue Method to return the required values for each
|
||||
|
||||
$allprogs = @()
|
||||
|
||||
foreach($key in $subkeys){
|
||||
|
||||
$thisKey=$UninstallKey+"\\"+$key
|
||||
|
||||
$thisSubKey=$reg.OpenSubKey($thisKey)
|
||||
|
||||
$obj = New-Object PSObject
|
||||
|
||||
$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
|
||||
|
||||
$obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
|
||||
|
||||
$obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
|
||||
|
||||
$obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
|
||||
|
||||
$obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
|
||||
|
||||
|
||||
$allprogs += $obj
|
||||
|
||||
}
|
||||
|
||||
return $allprogs
|
||||
}
|
||||
|
||||
|
||||
foreach ($comp in $table){
|
||||
$name = -join($comp.Name,".",$DNSPrefix);
|
||||
if (Test-Connection -ComputerName $name -Quiet){
|
||||
Write-Output $name
|
||||
$array += getPrograms($name)
|
||||
}else{
|
||||
Write-Output "$name Offline"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, Publisher | ft -auto
|
||||
|
||||
$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion | export-csv "$PSScriptRoot\..\Reports\software.csv" -NoTypeInformation -Delimiter ";" -Encoding ASCII
|
||||
Write-Host "Guardado en ..\Reports\software.csv"
|
||||
#$content = [System.IO.File]::ReadAllText("$PSScriptRoot\Reports\software.csv").Replace("A","")
|
||||
#[System.IO.File]::WriteAllText("$PSScriptRoot\Reports\software.csv", $content)
|
||||
Reference in New Issue
Block a user