Latest version we had of PCM

This commit is contained in:
kprkpr committed 2026-10-08 11:17:04 +02:00
1 parent e8e0b269cf
commit 2bf1f3312f
7 files changed
+188 -57

No files matched your search

+56 -10
View File
@@ -1,4 +1,4 @@
# Build 21. Using API 2
# Build 25. Using API 2
param([Int32]$startup=0)
$host.UI.RawUI.WindowTitle = "Powerful Computer Manager - Do Not Close"
@@ -7,6 +7,9 @@ Write-Host "Starting Powerful Computer Manager..."
$srcdir = $PSCommandPath | Split-Path -Parent
$server = (Get-Content "$srcdir\configpcm.ini" | select -Skip 1 | ConvertFrom-StringData).server
$resources = (Get-Content "$srcdir\configpcm.ini" | select -Skip 1 | ConvertFrom-StringData).resources
if ($resources -match '\\$'){ # Si acaba así, quitar ese caracter.
$resources = $resources -replace ".$"
}
$64bit = [Environment]::Is64BitOperatingSystem
$computerName = [System.Net.Dns]::GetHostName()
@@ -42,7 +45,7 @@ if ($exists.Result -eq "ERROR"){
if ($exists.EXITCODE -eq '3'){
Write-Host "Computer outside database:" $computerName
}else{
Write-Host "Computer and UUID of $computerName doesn't match"
Write-Host "Computer and UUID of $computerName doesn't match. UUID: " $UUID
}
exit
}
@@ -51,7 +54,7 @@ $Timestamp = [int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds
# Hardware Data
$SOData = Get-CimInstance Win32_OperatingSystem
$SOVersion = $SOData.Version
if ($SOVersion -match "^10.0."){ #If its Windows 10, add revision number for knowing hotfix installed
if ($SOVersion -match "^10.0."){ #If its Windows 10/11, add revision number for knowing hotfix installed
$revi = -join(".",(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' UBR).UBR)
$SOVersion += $revi
}
@@ -77,9 +80,40 @@ $diskResults = @()
$DisksData = ConvertTo-Json -Depth 4 $DiskResults
$DisksData = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($DisksData)) #I can't enter to database all without encode
$lastUser = (Get-CimInstance -ClassName Win32_ComputerSystem -Property UserName -ComputerName .).UserName
$ISRegistry = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$InstalledSoftware = @()
foreach($obj in $ISRegistry){
$ThisS= "" | Select-Object Name,Version
if ($obj.GetValue('DisplayName') -eq $null){
$ThisS.Name = $obj.PSChildName;
}else{
$ThisS.Name = $obj.GetValue('DisplayName')
$ThisS.Version = $obj.GetValue('DisplayVersion')
}
$InstalledSoftware += $ThisS
}
$InstalledSoftware = ConvertTo-Json -Depth 4 $InstalledSoftware
$InstalledSoftwareData = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($InstalledSoftware)) #I can't enter to database all without encode
# Send it
$paramInvoke = -join("$server/upd/computer?ComputerName=$computerName&UUID=",$UUID,"&SOVersion=",$SOVersion,"&SOCaption=",$SOData.Caption,"&SOBit=",$SOData.OsArchitecture.Substring(0,2),"&LastConnection=",$Timestamp,"&RAM=",$RAMInstalled,"&RAMFree=",$RAMFree,"&CPUName=",$CPUName,"&LastUser=",$lastUser,"&HDD=",$DisksData)
Invoke-RestMethod -Method Post -Uri $paramInvoke | out-null
$JSON = @{
'UUID'=$UUID;
'SOVersion'=$SOVersion;
'SOCaption'=$SOData.Caption;
'SOBit'=$SOData.OsArchitecture.Substring(0,2);
'LastConnection'=$Timestamp;
'RAM'=$RAMInstalled;
'RAMFree'=$RAMFree;
'CPUName'=$CPUName;
'LastUser'=$lastUser;
'HDD'=$DisksData;
'InstalledSoftware'=$InstalledSoftwareData
}
Invoke-RestMethod -Uri "$server/upd/computer?ComputerName=$computerName&UUID=$UUID" -Method POST -Body ($JSON|ConvertTo-Json) -ContentType "application/json" | out-null
# Load Cooks of computer
@@ -92,10 +126,14 @@ foreach ($CookName in $cooks){
Write-Host "Receta:" $cook.name
$CookRevision = $cook.revision
$atstartup = $cook.atstartup
if ($atstartup -eq 1 -and $startup -ne 1){ # If script has to tun at startup of computer, and there is not this moment..
if ($atstartup -eq 1 -and $startup -eq 0){ # If script has to tun at startup of computer, and there is not this moment..
Write-Host "Se salta ya que no esta arrancando/apagandose el equipo..."
continue # Go for next
}
if ($atstartup -eq 0 -and $startup -eq 1){ # If script hasn't to run at startup of computer, and there is starting up..
Write-Host "Se salta ya que se esta arrancando/apagandose el equipo..."
continue # Go for next
}
if ($cook.only64bit -eq 1 -and $64bit -eq $False) { # If script is only for 64 bit and system is 32 bit..
Write-Host "Se salta ya que es esta receta es solo para 64 bits..."
continue # Go for next
@@ -191,13 +229,18 @@ foreach ($CookName in $cooks){
}
}
"REPOTOLOCAL" { # Copy file from repo location to local ($env:temp) for use in cmd or other things
Copy-Item "$resources\$param" $env:temp -ErrorVariable errvar -Recurse -Force
Write-Host "$resources\$param"
$topath=$env:temp
if ($param -match '\\$'){
$topath+='\\'+($param -replace '.$')
}
Copy-Item "$resources\$param" $topath -ErrorVariable errvar -Recurse -Force -Verbose
if ($? -eq $false){ # Error in Copy
$err = 1
}
$filesCopied.Add($param) > $null #Add to list
}
"COPY" { # Copy file from repo location to some folder
"COPY" { # Copy file from folder to other folder
$parts = $param.Split(";")
if ($parts[1] -ne ""){ #Exists orig and dest
$orig=$parts[0]
@@ -229,6 +272,9 @@ foreach ($CookName in $cooks){
"MSG" { # Display a message
msg * "$param"
}
{$_ -in "REM","COMMENT"} { # Comentario sin más, mostrado en Powershell sin más
Write-Host "$param"
}
{$_ -in "SLEEP","PAUSE"}{ # Pause exec some seconds
[int]$secs = $param
Start-Sleep -Seconds $secs
@@ -277,11 +323,11 @@ foreach ($CookName in $cooks){
Invoke-Expression $param #Executes powershell command
$if=$? # True -> Exists ; False -> Not exists
}
"IF64BIT" { # If 64 bit computer
{$_ -in "IF64BIT","IF64BITS"} { # If 64 bit computer
$inif = $True
$if = $64bit # Its true if 64 bit computer
}
"IF32BIT" { # If 32 bit computer
{$_ -in "IF32BIT","IF32BITS"} { # If 32 bit computer
$inif = $True
$if = !$64bit # Its true if 32 bit computer, flipped boolean
}