mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-02-18 19:21:31 +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)
|
||||
310
client/PCM.fbp
Normal file
310
client/PCM.fbp
Normal file
@@ -0,0 +1,310 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<wxFormBuilder_Project>
|
||||
<FileVersion major="1" minor="15" />
|
||||
<object class="Project" expanded="1">
|
||||
<property name="class_decoration">; </property>
|
||||
<property name="code_generation">C++</property>
|
||||
<property name="disconnect_events">1</property>
|
||||
<property name="disconnect_mode">source_name</property>
|
||||
<property name="disconnect_php_events">0</property>
|
||||
<property name="disconnect_python_events">0</property>
|
||||
<property name="embedded_files_path">res</property>
|
||||
<property name="encoding">UTF-8</property>
|
||||
<property name="event_generation">connect</property>
|
||||
<property name="file"></property>
|
||||
<property name="first_id">1000</property>
|
||||
<property name="help_provider">none</property>
|
||||
<property name="indent_with_spaces"></property>
|
||||
<property name="internationalize">0</property>
|
||||
<property name="name">MyProject1</property>
|
||||
<property name="namespace"></property>
|
||||
<property name="path">.</property>
|
||||
<property name="precompiled_header"></property>
|
||||
<property name="relative_path">1</property>
|
||||
<property name="skip_lua_events">1</property>
|
||||
<property name="skip_php_events">1</property>
|
||||
<property name="skip_python_events">1</property>
|
||||
<property name="ui_table">UI</property>
|
||||
<property name="use_enum">0</property>
|
||||
<property name="use_microsoft_bom">0</property>
|
||||
<object class="Frame" expanded="1">
|
||||
<property name="aui_managed">0</property>
|
||||
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
|
||||
<property name="bg"></property>
|
||||
<property name="center">wxBOTH</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="event_handler">impl_virtual</property>
|
||||
<property name="extra_style"></property>
|
||||
<property name="fg"></property>
|
||||
<property name="font"></property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="name">MainFrame</property>
|
||||
<property name="pos"></property>
|
||||
<property name="size">749,396</property>
|
||||
<property name="style">wxDEFAULT_FRAME_STYLE</property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="title"></property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style">wxTAB_TRAVERSAL</property>
|
||||
<property name="xrc_skip_sizer">1</property>
|
||||
<object class="wxMenuBar" expanded="1">
|
||||
<property name="bg"></property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="fg"></property>
|
||||
<property name="font"></property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="label">MyMenuBar</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="name">m_menubar1</property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="pos"></property>
|
||||
<property name="size"></property>
|
||||
<property name="style"></property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<object class="wxMenu" expanded="1">
|
||||
<property name="label">Equipos</property>
|
||||
<property name="name">m_computers</property>
|
||||
<property name="permission">protected</property>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Añadir equipo</property>
|
||||
<property name="name">scomp_addc</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Borrar equipo</property>
|
||||
<property name="name">scomp_deletec</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="wxMenu" expanded="1">
|
||||
<property name="label">Grupos</property>
|
||||
<property name="name">m_groups</property>
|
||||
<property name="permission">protected</property>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Añadir Grupo</property>
|
||||
<property name="name">sgroup_addg</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Borrar grupo</property>
|
||||
<property name="name">sgroup_delg</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Ver equipos de un grupo</property>
|
||||
<property name="name">sgroup_seeg</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Vaciar grupo</property>
|
||||
<property name="name">sgroup_emptyg</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Cambiar nombre de un grupo</property>
|
||||
<property name="name">sgroup_reng</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Recetas asignadas a un grupo</property>
|
||||
<property name="name">sgroup_cooksg</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="wxMenu" expanded="1">
|
||||
<property name="label">Recetas</property>
|
||||
<property name="name">m_cooks</property>
|
||||
<property name="permission">protected</property>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Recetas de un grupo</property>
|
||||
<property name="name">scook_cooksg</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Añadir receta a un grupo</property>
|
||||
<property name="name">scook_addcookg</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Borrar receta de un grupo</property>
|
||||
<property name="name">scook_deletecookg</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Renombrar receta</property>
|
||||
<property name="name">scook_renamecook</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Detalles de implantación de una receta</property>
|
||||
<property name="name">scook_detailscook</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="wxMenu" expanded="1">
|
||||
<property name="label">Reportes</property>
|
||||
<property name="name">m_reports</property>
|
||||
<property name="permission">protected</property>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Reporte de equipos</property>
|
||||
<property name="name">srep_rcomp</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Reporte de grupos</property>
|
||||
<property name="name">srep_rgroup</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Reporte de recetas</property>
|
||||
<property name="name">srep_rcook</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</wxFormBuilder_Project>
|
||||
218
client/client.ps1
Normal file
218
client/client.ps1
Normal file
@@ -0,0 +1,218 @@
|
||||
# Build 2
|
||||
$root = $PSCommandPath | Split-Path -Parent
|
||||
. $root\config.ps1
|
||||
|
||||
$computerName = $env:COMPUTERNAME
|
||||
$UUID=(get-wmiobject Win32_ComputerSystemProduct).UUID
|
||||
|
||||
$exists = Invoke-RestMethod -Method Get -Uri "$server/get/computerexists?ComputerName=$computerName&UUID=$UUID"
|
||||
if ($exists.Result -eq 0){
|
||||
Write-Host "Computer outside database:" $computerName
|
||||
exit
|
||||
}
|
||||
|
||||
$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
|
||||
$revi = -join(".",(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' UBR).UBR)
|
||||
$SOVersion += $revi
|
||||
}
|
||||
|
||||
# Update Computer Data
|
||||
$CPUInfo = Get-WmiObject Win32_Processor
|
||||
$RAMInstalled = Get-WmiObject CIM_PhysicalMemory | Measure-Object -Property capacity -Sum | ForEach-Object {[math]::round(($_.sum / 1MB),2)}
|
||||
$paramInvoke = -join("$server/upd/computer?ComputerName=$computerName&UUID=",$UUID,"&SOVersion=",$SOVersion,"&SOCaption=",$SOData.Caption,"&SOBit=",$SOData.OsArchitecture.Substring(0,2),"&LastConnection=",$Timestamp,"&RAM=",$RAMInstalled,"&CPUName=",$CPUInfo.Name)
|
||||
Invoke-RestMethod -Method Get -Uri $paramInvoke | out-null
|
||||
# More info
|
||||
$lastUser = (Get-CimInstance -ClassName Win32_ComputerSystem -Property UserName -ComputerName .).UserName
|
||||
Invoke-RestMethod -Method Get -Uri "$server/upd/computer?ComputerName=$computerName&UUID=$UUID&LastUser=$lastUser" | out-null
|
||||
|
||||
|
||||
$cooks = Invoke-RestMethod -Method Get -Uri "$server/get/cook?ComputerName=$computerName&UUID=$UUID"
|
||||
|
||||
foreach ($CookName in $cooks){
|
||||
Set-Location $env:temp # For downloading/copying items, use system temp location
|
||||
$CookName = $CookName.CookName
|
||||
$cook = Invoke-RestMethod -Method Get -Uri "$server/load/cook?CookName=$CookName&ComputerName=$computerName&UUID=$UUID"
|
||||
Write-Host "Receta:" $cook.name
|
||||
$CookRevision = $cook.revision
|
||||
$err = 0
|
||||
$exit = 0
|
||||
$inif = $false
|
||||
$if = $true
|
||||
$filesCopied = New-Object System.Collections.ArrayList # For REPOTOLOCAL, has a list of files copied to delete when finish (Do not store forever in temp)
|
||||
foreach ($step in $cook.steps){
|
||||
if ($err -eq 1 -and $noerror -eq 1){$err = 0; $errvar = ""} #If "noerror" is active, do not count errors
|
||||
if ($err -eq 1 -or $exit -eq 1){break} # Halt if err ocurred (And noerror directive is not active)
|
||||
$step = $step.Split("|")
|
||||
$param = $step[1]
|
||||
Write-Host $step[0] "-" $step[1]
|
||||
if($inif -eq $true -and $if -eq $false){ # Only can see "ENDIF" if is in IF and is not true
|
||||
if ($step[0] -ne "ENDIF" -and $step[0] -ne "ELSE"){
|
||||
Write-Host $step[0] "Not executed, IF not meet"
|
||||
$step[0] = "" #Disable command
|
||||
$step[1] = ""
|
||||
}
|
||||
}
|
||||
|
||||
switch ($step[0].ToUpper()) { #Command
|
||||
"UNINSTALL" { # Remove program
|
||||
Get-Package -Name "$param*" -ErrorAction Continue #This will return error if program is not installed, do not see it.
|
||||
if ($? -eq $true){ #If its True, is that package exists
|
||||
Get-Package -Name "$param*" -ErrorVariable errvar | Uninstall-Package -ErrorVariable errvar
|
||||
if ($? -eq $false){ # If fail then put 1 (When fail, powershell returns False)
|
||||
$err = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
"SERV_DISABLE" { # Disable a service
|
||||
Set-Service $param -StartupType Disabled -Status Stopped -ErrorVariable errvar
|
||||
if ($? -eq $false){ #If its False, it was a problem
|
||||
$err = 1
|
||||
}
|
||||
}
|
||||
"SERV_ENABLE" { # Enable a service
|
||||
Set-Service $param -StartupType Automatic -Status Running -ErrorVariable errvar
|
||||
if ($? -eq $false){ #If its False, it was a problem
|
||||
$err = 1
|
||||
}
|
||||
}
|
||||
"KILL_PROCESS" {
|
||||
$p = Get-Process -Name "$param"
|
||||
if ($? -eq $true){ # Only do something if exists
|
||||
Stop-Process -InputObject $p -Force -ErrorVariable errvar -ErrorAction Continue
|
||||
#if ($p.HasExited -eq $false){
|
||||
# $err = 1
|
||||
#}
|
||||
}
|
||||
}
|
||||
"CMD" { # Run a cmd command. Note: Runs at high priv.
|
||||
cmd.exe /c "$param"
|
||||
if ($? -eq $false){ # Error in CMD
|
||||
$err = 1
|
||||
}
|
||||
}
|
||||
"PWCMD" { # Run a powershell command. Note: Runs as high priv.
|
||||
Invoke-Expression $param
|
||||
if ($? -eq $false){ # Error in CMD
|
||||
$err = 1
|
||||
}
|
||||
}
|
||||
"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
|
||||
if ($? -eq $false){ # Error in Copy
|
||||
$err = 1
|
||||
}
|
||||
$filesCopied.Add($param) > $null #Add to list
|
||||
}
|
||||
"REMOVE" { # Remove files / folders
|
||||
Remove-Item "$param" -Recurse -Force -ErrorAction Continue # They not see errors (Because error will be file not found)
|
||||
}
|
||||
"INSTALLMSI" { # Installs a .msi file (From $env:temp)
|
||||
Start-Process msiexec.exe -Wait -ArgumentList "/norestart /quiet /I $param" -ErrorVariable errvar
|
||||
if ($? -eq $false){ # Error in MSI
|
||||
$err = 1
|
||||
}
|
||||
}
|
||||
"REGFILE" { # Imports a .reg file
|
||||
reg import .\$param
|
||||
if ($? -eq $false){ # Error importing reg file
|
||||
$err = 1
|
||||
}
|
||||
}
|
||||
"MSG" { # Display a message
|
||||
msg * "$param"
|
||||
}
|
||||
{$_ -in "SLEEP","PAUSE"}{ # Pause exec some seconds
|
||||
[int]$secs = $param
|
||||
Start-Sleep -Seconds $secs
|
||||
}
|
||||
"NOERROR" { #All within NOERROR doesn't generate errors and stop scripts
|
||||
$noerror = 1
|
||||
}
|
||||
"ENDNOERROR" {
|
||||
$noerror = 0
|
||||
}
|
||||
"IFSOFTWAREINST" { # If with software
|
||||
$inif = $true #This controls IF start/stop
|
||||
Get-Package -Name "$param*" -ErrorAction SilentlyContinue #This will return error if program is not installed, do not see it.
|
||||
$if=$? # True -> Exists ; False -> Not exists
|
||||
}
|
||||
"IFSOFTWAREVER" { # If with software
|
||||
$inif = $true #This controls IF start/stop
|
||||
$parts = $param.Split(";")
|
||||
if ($parts[1] -ne ""){ #Exists uri and filename
|
||||
$p_name = $parts[0]
|
||||
$p_ver = $parts[1]
|
||||
Get-Package -Name "$p_name*" -MinimumVersion "$p_ver" -MaximumVersion "$p_ver" -ErrorAction SilentlyContinue #This will return error if program is not installed, do not see it.
|
||||
$if=$? # True -> Exists ; False -> Not exists
|
||||
}else{ #Doesn't sent right
|
||||
$err = 1
|
||||
$errvar = "Param not set right. Exiting..."
|
||||
}
|
||||
}
|
||||
"IFPATHEXISTS" { # If only if a path exists (File, Folder, Registry Key..)
|
||||
$inif = $true #This controls IF start/stop
|
||||
Test-Path $param -PathType Any -ErrorAction SilentlyContinue
|
||||
$if=$?
|
||||
}
|
||||
"IFPWCMD" { # If with powershell command
|
||||
$inif = $true #This controls IF start/stop
|
||||
Invoke-Expression $param #Executes powershell command
|
||||
$if=$? # True -> Exists ; False -> Not exists
|
||||
}
|
||||
"ELSE" { # Turn bool $if
|
||||
$if = !$if
|
||||
}
|
||||
"ENDIF"{ # End the if
|
||||
$inif = $false
|
||||
$if = $true
|
||||
}
|
||||
"DOWNLOAD" { #Download a file. This is a bit problematic one, will use ; to separate download and filename, and its forced to use it..
|
||||
$parts = $param.Split(";")
|
||||
if ($parts[1] -ne ""){ #Exists uri and filename
|
||||
$progressPreference = 'silentlyContinue'
|
||||
Invoke-WebRequest -Uri $parts[0] -OutFile $parts[1] -UseBasicParsing -ErrorVariable errvar
|
||||
$progressPreference = 'Continue'
|
||||
$filesCopied.Add($parts[1]) > $null #Add to list
|
||||
}else{ #Doesn't sent right
|
||||
$err = 1
|
||||
$errvar = "Param not set right. Exiting..."
|
||||
}
|
||||
}
|
||||
"EXIT"{ # Exits cook completly. If some param, exit will be with "error"
|
||||
if ($param){ #Exit with error message
|
||||
$noerror = 0
|
||||
$err = 1
|
||||
$errvar = $param
|
||||
$exit = 1
|
||||
}else{ #Exit as sucessful
|
||||
$err = 0
|
||||
$errvar = ""
|
||||
$exit = 1
|
||||
}
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
}
|
||||
# Send results
|
||||
if ($errvar){ #There is an error if this has something
|
||||
$errvar = $($errvar | Out-String)
|
||||
$errvar = [System.Convert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes($errvar))
|
||||
$err = 1
|
||||
}else{
|
||||
$errvar=""
|
||||
}
|
||||
if ($cook.runever -eq "1"){
|
||||
$err = -1 # This is for run but not for error, is by cook saw.
|
||||
}
|
||||
Invoke-RestMethod -Method Get -Uri "$server/set/cookstatus?ComputerName=$computerName&UUID=$UUID&CookName=$CookName&Revision=$CookRevision&Error=$err&ErrorDesc=$errvar" | out-null
|
||||
|
||||
#Delete files copied to temp for saving space
|
||||
foreach ($element in $filesCopied) {
|
||||
Remove-Item "$env:temp\$element" -ErrorAction SilentlyContinue -Recurse -Force
|
||||
}
|
||||
|
||||
}
|
||||
2
client/configexample.ps1
Normal file
2
client/configexample.ps1
Normal file
@@ -0,0 +1,2 @@
|
||||
$server = "http://miserver.dominio:3333" #Server that runs api service
|
||||
$resources = "\\MISERVER\REPOFOLDER" #Where files for copy are (Not cooks)
|
||||
317
client/control.ps1
Normal file
317
client/control.ps1
Normal file
@@ -0,0 +1,317 @@
|
||||
# Build 1
|
||||
$root = $PSCommandPath | Split-Path -Parent
|
||||
. $root\config.ps1
|
||||
|
||||
function seeGroups {
|
||||
$answer = Invoke-RestMethod -Method Get -Uri "$server/get/groups"
|
||||
foreach ($st in $answer){
|
||||
Write-Host "Grupo:" $st.Name
|
||||
}
|
||||
}
|
||||
function seeComputers {
|
||||
$answer = Invoke-RestMethod -Method Get -Uri "$server/get/computers"
|
||||
foreach ($st in $answer){
|
||||
Write-Host "Ordenador:" $st.Name
|
||||
}
|
||||
}
|
||||
|
||||
function menuReportes {
|
||||
|
||||
do
|
||||
{
|
||||
Write-Host "================ Menu reportes ================"
|
||||
|
||||
|
||||
Write-Host "1) Reporte de Software"
|
||||
Write-Host "Q) Salir"
|
||||
$input = Read-Host "Elegir una Opcion"
|
||||
switch ($input)
|
||||
{
|
||||
'1' {
|
||||
Clear-Host
|
||||
. "$PSScriptRoot\ADcomputerData.ps1"
|
||||
pause
|
||||
} 'q' {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
until ($input -eq 'q')
|
||||
|
||||
|
||||
}
|
||||
|
||||
function menuEquipos {
|
||||
|
||||
do
|
||||
{
|
||||
Write-Host "================ Menu equipos ================"
|
||||
|
||||
|
||||
Write-Host "1) Reporte de Equipos en pantalla"
|
||||
Write-Host "2) Añadir equipo"
|
||||
Write-Host "3) Borrar equipo"
|
||||
Write-Host "4) Añadir equipo a un grupo"
|
||||
Write-Host "5) Borrar equipo de un grupo"
|
||||
Write-Host "Q) Salir"
|
||||
$input = Read-Host "Elegir una Opcion"
|
||||
switch ($input)
|
||||
{
|
||||
'1' {
|
||||
Clear-Host
|
||||
seeComputers #Function
|
||||
pause
|
||||
} '2' {
|
||||
Clear-Host
|
||||
$newHost = Read-Host -Prompt "Nombre del equipo"
|
||||
if (Test-Connection -ComputerName $newHost -Quiet){
|
||||
Write-Output "$newHost Online"
|
||||
Write-Output "Añadiendo equipo"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/add/computer?ComputerName=$newHost"
|
||||
}else{
|
||||
Write-Output "$newHost Offline"
|
||||
}
|
||||
pause
|
||||
|
||||
} '3' {
|
||||
Clear-Host
|
||||
$hhost = Read-Host -Prompt "Nombre del equipo a eliminar"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/del/computer?ComputerName=$hhost"
|
||||
} '4' {
|
||||
Clear-Host
|
||||
$computer = Read-Host -Prompt "Nombre del equipo"
|
||||
# See all groups
|
||||
seeGroups #Function
|
||||
$newGroup = Read-Host -Prompt "Nombre del grupo a añadir"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/add/grpcomputer?ComputerName=$computer&GroupName=$newGroup"
|
||||
pause
|
||||
} '5' {
|
||||
Clear-Host
|
||||
$computer = Read-Host -Prompt "Nombre del equipo"
|
||||
# See all groups
|
||||
seeGroups #Function
|
||||
$newGroup = Read-Host -Prompt "Nombre del grupo a quitar"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/add/grpcomputer?ComputerName=$computer&GroupName=$newGroup"
|
||||
pause
|
||||
} 'q' {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
until ($input -eq 'q')
|
||||
|
||||
|
||||
}
|
||||
|
||||
function menuGrupos {
|
||||
|
||||
do
|
||||
{
|
||||
Write-Host "================ Menu grupos ================"
|
||||
|
||||
|
||||
Write-Host "1) Reporte de Grupos en pantalla"
|
||||
Write-Host "2) Ver equipos de un grupo"
|
||||
Write-Host "3) Añadir grupo"
|
||||
Write-Host "4) Borrar grupo"
|
||||
Write-Host "5) Vaciar equipos del grupo"
|
||||
Write-Host "6) Cambiar nombre del grupo"
|
||||
Write-Host "7) Ver recetas de un grupo"
|
||||
Write-Host "Q) Salir"
|
||||
$input = Read-Host "Elegir una Opción"
|
||||
switch ($input)
|
||||
{
|
||||
'1' {
|
||||
Clear-Host
|
||||
seeGroups #Function
|
||||
pause
|
||||
} '2' {
|
||||
Clear-Host
|
||||
seeGroups
|
||||
$GroupName = Read-Host -Prompt "Nombre del grupo a ver"
|
||||
if ($GroupName){
|
||||
$answer = Invoke-RestMethod -Method Get -Uri "$server/get/computersgrp?GroupName=$GroupName"
|
||||
foreach ($st in $answer){
|
||||
Write-Host "Ordenador:" $st.Name
|
||||
}
|
||||
}
|
||||
pause
|
||||
} '3' {
|
||||
Clear-Host
|
||||
$newGroup = Read-Host -Prompt "Nombre del grupo a añadir"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/add/group?GroupName=$newGroup"
|
||||
pause
|
||||
|
||||
} '4' {
|
||||
Clear-Host
|
||||
seeGroups #Function
|
||||
$grpName = Read-Host -Prompt "Nombre del grupo a eliminar"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/del/group?GroupName=$grpName"
|
||||
} '5' {
|
||||
Clear-Host
|
||||
seeGroups #Function
|
||||
$grpName = Read-Host -Prompt "Nombre del grupo a quitar los equipos"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/del/emptypcsgroup?GroupName=$grpName"
|
||||
} '6' {
|
||||
Clear-Host
|
||||
# See all groups
|
||||
seeGroups #Function
|
||||
$GroupName = Read-Host -Prompt "Nombre del grupo"
|
||||
$GroupNewName = Read-Host -Prompt "Nombre nuevo"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/upd/group?GroupName=$GroupName&GroupNewName=$GroupNewName"
|
||||
pause
|
||||
} '7' {
|
||||
Clear-Host
|
||||
# See all groups
|
||||
seeGroups #Function
|
||||
$GroupName = Read-Host -Prompt "Nombre del grupo para ver recetas"
|
||||
if ($GroupName){
|
||||
$answer = Invoke-RestMethod -Method Get -Uri "$server/get/cookgrp?GroupName=$GroupName"
|
||||
foreach ($st in $answer){
|
||||
Write-Host "Receta:" $st.CookName
|
||||
}
|
||||
}else{
|
||||
Write-Host "No hay grupo"
|
||||
}
|
||||
pause
|
||||
} 'q' {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
until ($input -eq 'q')
|
||||
|
||||
}
|
||||
|
||||
|
||||
function menuCooks {
|
||||
|
||||
do
|
||||
{
|
||||
Write-Host "================ Menu recetas (Cooks) ================"
|
||||
|
||||
|
||||
Write-Host "1) Grupos de una receta"
|
||||
Write-Host "2) Estado de una receta"
|
||||
Write-Host "3) Detalles de cada equipo de una receta"
|
||||
Write-Host "4) Añadir receta a un grupo"
|
||||
Write-Host "5) Borrar receta de un grupo"
|
||||
Write-Host "6) Renombrar receta"
|
||||
Write-Host "Q) Salir"
|
||||
$input = Read-Host "Elegir una Opción"
|
||||
switch -regex ($input)
|
||||
{
|
||||
'1' {
|
||||
Clear-Host
|
||||
$CookName = Read-Host -Prompt "Nombre de la receta"
|
||||
Write-Host "Grupos de la receta $CookName"
|
||||
$grpcook = Invoke-RestMethod -Method Get -Uri "$server/get/grpcook?CookName=$CookName"
|
||||
foreach ($st in $grpcook){
|
||||
Write-Host "Grupo:" $st.Name
|
||||
}
|
||||
pause
|
||||
} '2|3' {
|
||||
Clear-Host
|
||||
$CookName = Read-Host -Prompt "Nombre de la receta"
|
||||
|
||||
Write-Host "Grupos de la receta"
|
||||
$grpcook = Invoke-RestMethod -Method Get -Uri "$server/get/grpcook?CookName=$CookName"
|
||||
foreach ($st in $grpcook){
|
||||
Write-Host "Grupo:" $st.Name
|
||||
}
|
||||
|
||||
$cookrevision = Invoke-RestMethod -Method Get -Uri "$server/get/lastrevisioncook?CookName=$CookName"
|
||||
$answer = Invoke-RestMethod -Method Get -Uri "$server/get/statuscook?CookName=$CookName"
|
||||
|
||||
if ($_ -eq '3'){
|
||||
foreach ($st in $answer){
|
||||
Write-Host "Ordenador:" $st.Name ", revision" $st.Revision ", error" $st.Error
|
||||
}
|
||||
Write-Host "------Resumen y errores------"
|
||||
}
|
||||
$estadistica = @{}
|
||||
$estadistica.Total = 0
|
||||
$estadistica.Error = 0
|
||||
$estadistica.NotLast = 0
|
||||
foreach ($st in $answer){
|
||||
$estadistica.Total++
|
||||
if ($st.Error -eq '1'){
|
||||
Write-Host "Ordenador en error:" $st.Name
|
||||
$estadistica.Error++
|
||||
}
|
||||
if ($st.Revision -ne $cookrevision.Revision){
|
||||
Write-Host "Ordenador sin la última revisión de la receta:" $st.Name
|
||||
$estadistica.NotLast++
|
||||
}
|
||||
}
|
||||
Write-Host "Total implementado:" $estadistica.Total
|
||||
Write-Host "Errores:" $estadistica.Error
|
||||
Write-Host "Sin aplicar ultima revisión:" $estadistica.NotLast
|
||||
pause
|
||||
} '4' {
|
||||
Clear-Host
|
||||
|
||||
$CookName = Read-Host -Prompt "Nombre de la receta a añadir"
|
||||
seeGroups #Function
|
||||
$GroupName = Read-Host -Prompt "Nombre del grupo que quieres que lo tenga"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/set/cook?GroupName=$GroupName&CookName=$CookName"
|
||||
pause
|
||||
|
||||
} '5' {
|
||||
Clear-Host
|
||||
$CookName = Read-Host -Prompt "Nombre del receta a eliminar de un grupo"
|
||||
$grpcook = Invoke-RestMethod -Method Get -Uri "$server/get/grpcook?CookName=$CookName"
|
||||
foreach ($st in $grpcook){
|
||||
Write-Host "Grupo:" $st.Name
|
||||
}
|
||||
$GroupName = Read-Host -Prompt "Nombre del grupo"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/del/cookgrp?GroupName=$GroupName&CookName=$CookName"
|
||||
pause
|
||||
} '6' {
|
||||
Clear-Host
|
||||
$CookName = Read-Host -Prompt "Nombre del receta actual"
|
||||
$CookNewName = Read-Host -Prompt "Nuevo nombre"
|
||||
Invoke-RestMethod -Method Get -Uri "$server/upd/cookname?CookNewName=$CookNewName&CookName=$CookName"
|
||||
pause
|
||||
} 'q' {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
until ($input -eq 'q')
|
||||
|
||||
}
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
Write-Host "================ Menú principal ================"
|
||||
|
||||
|
||||
Write-Host "1) Reportes"
|
||||
Write-Host "2) Equipos"
|
||||
Write-Host "3) Grupos (Locales)"
|
||||
Write-Host "4) Recetas"
|
||||
Write-Host "Q) Salir"
|
||||
$input = Read-Host "Elegir una Opción"
|
||||
switch ($input)
|
||||
{
|
||||
'1' {
|
||||
Clear-Host
|
||||
menuReportes
|
||||
} '2' {
|
||||
Clear-Host
|
||||
menuEquipos
|
||||
} '3' {
|
||||
Clear-Host
|
||||
menuGrupos
|
||||
} '4' {
|
||||
Clear-Host
|
||||
menuCooks
|
||||
} 'q' {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
until ($input -eq 'q')
|
||||
Reference in New Issue
Block a user