labtechconsulting / labtech-powershell-module Goto Github PK
View Code? Open in Web Editor NEWThis is an attempt to create a comprehensive LT PoSH module.
Home Page: http://labtechconsulting.com
License: MIT License
This is an attempt to create a comprehensive LT PoSH module.
Home Page: http://labtechconsulting.com
License: MIT License
In the Install-LTService function, you do a check to see if .NET 3.5 is installed and attempt to install it. In the error handling for that .NET 3.5 installation, you do the following. (Currently lines 491-495)
Else{
Write-Output "ERROR: .NET 3.5 install failed."
Write-Output $Result
Exit
}
The problem is, if I'm manually running the Install-LTService function and not using a script, having it output the error code and then immediately exit will flash too fast to understand what's happening before it closes the window. I think having a pause or a break would be more effective.
I think I read that "exit" behaves differently on different versions of PowerShell. I don't recall exactly what OS or PoSh version I found this bug on, sorry.
For those with piped server address lists in the registry from the labtech template the reinstall and possibly other functions will fail as they can't use the pipe delimited string. something like this should work but I couldn't get it working
line 542 [string]$Server = (Get-LTServiceInfo).'Server Address' -split "|",0,"SimpleMatch" | select -First 1 ,
That split code works when using the get-ltserviceinfo cmdlet directly, just not from the reinstall cmdlet
There are new keys with 11
HKEY_CLASSES_ROOT\Installer\Products\D1003A85576B76D45A1AF09A0FC87FAC
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\D1003A85576B76D45A1AF09A0FC87FAC
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\D1003A85576B76D45A1AF09A0FC87FAC\InstallProperties
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall{58A3001D-B675-4D67-A5A1-0FA9F08CF7CA}
If the server password contains special characters (such as a '/') it can break passing those passwords to the executable/MSI.
A fix for this is to add single quotes around the PasswordArg on line 1215 so it looks like this:
$PasswordArg = "SERVERPASS=`'$ServerPassword`'"
Can we get this put in, so the server password can have special characters in it?
LabTech-Powershell-Module/LabTech.psm1
Lines 90 to 102 in 69988bc
It appears that PSVersion 7.1.1 isn't able to load or find the type/namespace for ICertificatePolicy
. PSVersion 5.1.1 operates as it's been just fine. The error outputs are as follows.
PS C:\Users\(new-object Net.WebClient).DownloadString('https://bit.ly/LTPoSh') | iex;
Add-Type:
Line |
91 | Add-Type -Debug:$False @"
| ~~~~~~~~~~~~~~~~~~~~~~~~~
| (3,44): error CS0246: The type or namespace name 'ICertificatePolicy' could not be found (are you missing a using directive or an assembly reference?)
public class TrustAllCertsPolicy : ICertificatePolicy {
^
Add-Type:
Line |
91 | Add-Type -Debug:$False @"
| ~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot add type. Compilation errors occurred.
New-Object:
Line |
103 | … vicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find type [TrustAllCertsPolicy]: verify that the assembly containing this type is loaded.
LabTech-Powershell-Module/LabTech.psm1
Line 1784 in 8618eec
The date conversion here results in an error on none US systems, IE in the UK where the date format is dd/mm/yyyy:
Get-LTError : ERROR: There was an error reading the log. Cannot convert value "15/11/2018 08:30:59" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."
For the "To Do" bucket. The module needs a way to work when a proxy configuration is required. Although the user would have trouble getting LT-POSH to download in the first place if there was a proxy. But assuming that the module was pre-downloaded. Perhaps a function could be included to set the proxy policy for the current powershell session (needed to pull the MSI, etc.)
But also, if the module was used to install an agent the proxy settings will need to be passed to the Automate Agent configuration (since it won't have learned the location specific information from the MSI). That would mean injecting the Proxy, ProxyUser, and ProxyPass registry values AFTER the installer completes but before Agent registration would be able to succeed.
To start, I found this code that may allow a proxy configuration to be set for the powershell session. Setting the registry values would still need to be worked out.
function Create-Proxy($proxyHost,$proxyPort,$proxyUsername,$proxyPassword)
{
#$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
$proxyUrl = $proxyHost+":"+$proxyPort;
Write-Host "proxy url [$proxyUrl]";
$proxy = New-Object System.Net.WebProxy($proxyUrl, $true);
$passwd = ConvertTo-SecureString $proxyPassword -AsPlainText -Force; ## Website credentials
$proxy.Credentials = New-Object System.Management.Automation.PSCredential ($proxyUsername, $passwd);
return $proxy;
}
$wc=new-object net.webclient;
$wc.UseDefaultCredentials = $true
$wc.Proxy = Create-Proxy "<proxy-host>" "<proxy-port>" "<proxy-username>" "<proxy-clear-pass>"
$wc.DownloadString('https://SERVERNAME/SOMETHING.ps1');
The issue:
The command Reset-LTService -ID -Mac
is not supposed to remove the location ID. But it does.
To reproduce:
C:\Windows\LTSvc>"%windir%\System32\WindowsPowerShell\v1.0\powershell.exe" -noprofile -command "& {(new-object Net.WebCl
ient).DownloadString('http://bit.ly/ltposh') | iex; Reset-LTService -ID -Mac}"
OLD ID: 5374 LocationID: 291 MAC: 00059A3C7A00
Waiting for Services to Stop.........
Services Stopped successfully.
.Removing ID
.Removing LocationID <-- NOOOO!!!!!!!!!!
.Removing MAC
Waiting for Services to Start..
Services Started successfully.
...
The fix: Line 1922
If (!($ID -and $LocationID -and $MAC)){
should be
If (!($ID -and $Location -and $MAC)){
:)
Documentation does not show the use of an Installer Token.
Hi there,
We recently powered off our LT server, and now the script is failing. As far as I can tell, there's logic to fallback to Amazon AWS, but it doesn't work. Either that or it just compares the download sizes.
Is it supposed to fall back to AWS?
Because of the way the script works, I can't just point it to an uninstaller file - it wants to traverse the directory on it's own, instead of letting me put in a full path to a uninstall.exe - I tried putting one on MS devops, but it won't work, because it hardcodes the location of the file from the domain it grabs or that is specified.
You probably should build up the Arguments using a string array and pass them to Start-Process so it can properly escape them.
$Arguments = @()
$Arguments += "/i"
$Arguments += $InstallerFilePath
$Arguments += "/qn"
if($ServerPassword)
{
$Arguments += $ServerPassword
}
Start-Process -Wait msiexec -ArgumentList $Arguments
LabTech-Powershell-Module/LabTech.psm1
Line 1292 in 69988bc
When you try to run the "(new-object Net.WebClient).DownloadString('https://bit.ly/LTPoSh') | iex;" command on a Surface Pro X (64-bit custom ARM CPU), it tries to switch to 64-bit PowerShell and creates an endless loop of spawned Powershell.exe processes.
Output looks like:
PS C:\windows\system32> (new-object Net.WebClient).DownloadString('https://bit.ly/LTPoSh') | iex;
WARNING: 32-bit PowerShell session detected on 64-bit OS. Attempting to launch 64-Bit session to process commands.
WARNING: 32-bit PowerShell session detected on 64-bit OS. Attempting to launch 64-Bit session to process commands.
WARNING: 32-bit PowerShell session detected on 64-bit OS. Attempting to launch 64-Bit session to process commands.
WARNING: 32-bit PowerShell session detected on 64-bit OS. Attempting to launch 64-Bit session to process commands.
https://oofhours.com/2020/02/04/powershell-on-windows-10-arm64/ this site indicates that 64-bit tests should exclude the ARM processor architecture to avoid these issues.
I started out writing a small script to reinstall agents using PSRemote. I ran into an issue where Agent_Uninstall.exe hangs on some (maybe most) Windows 7 machines, but not all. I've been working with this on and off for a few weeks. Script is fairly basic, but during my researching I came across this module. The module is great, but I noticed the same issue is present. If I kill Agent_Uninstall.exe the clean up portion of the Uninstall-LTService function does a good job of forcefully removing the software though.
After more tinkering on one of the affected Windows 7 machines I upgraded WMF 2.0 to WMF 5.1 and that resolved the issue of Agent_Uninstall.exe hanging. This isn't really an issue with the module, but something you may want to consider working around in a future update. I'm sure I'm not the first person to consider using this module to install / reinstall agents using PSRemote.
Reinstall module from this is not allowing me to reinstall the LT agent
Error:
Could not create SSL/TLS secure channel
Function that I ran:
(new-object Net.WebClient).DownloadString('http://bit.ly/LTPoSh') | iex; Reinstall-LTService -Server xxxxxxxx == -LocationID xxxxx
Receive Stack Overflow Exception in powershell (version 4 and 5)
ReInstall-LTservice command completes the Uninstall, then starts the Install, but it calls a different URL than the Install-LTService command - it looks to be the old deprecated probe URL and thus fails to download the installer.
DEBUG: Starting Reinstall-ltservice at line 1593
DEBUG: Starting Get-LTServiceInfo at line 212
DEBUG: Exiting Get-LTServiceInfo at line 255
Reinstalling LabTech with the following information, -Server https://{sanitized},https://{sanitized} -LocationID 1DEBUG: Starting Uninstall-LTService at line 684
DEBUG: Line 780: Testing Server Response and Version: https://{sanitized}/LabTech/Agent.aspx
DEBUG: Line 783: Raw Response: ||||||200.278
DEBUG: Line 805: Downloading RemoteAgent.msi from https://{sanitized}/LabTech/Service/LabTechRemoteAgent.msi
DEBUG: Line 842: Downloading Agent_Uninstall.exe from https://{sanitized}/LabTech/Service/LabUninstall.exe
DEBUG: Line 869: Server https://{sanitized} has been selected.
Starting Uninstall.
DEBUG: Starting Stop-LTService at line 409
DEBUG: Line 3093: Sending service command 'Kill VNC' (141) to 'LTService'
DEBUG: Line 3093: Sending service command 'Kill Trays' (142) to 'LTService'
Waiting for Services to Stop.....
Services Stopped successfully.
DEBUG: Exiting Stop-LTService at line 463
DEBUG: Line 888: Terminating Process LTSVC
DEBUG: Line 896: Executing Command "regsvr32.exe /u C:\Windows\LTsvc\wodVPN.dll /s"
DEBUG: Line 906: Executing Command "msiexec.exe /x "C:\Windows\Temp\RemoteAgent.msi" /qn"
DEBUG: Line 918: Executing Command "C:\Windows\Temp\Agent_Uninstall.exe"
DEBUG: Line 957: Found Registry Key: Registry::HKEY_CURRENT_USER\SOFTWARE\LabTech\Service
DEBUG: Line 957: Found Registry Key: Registry::HKEY_CURRENT_USER\SOFTWARE\LabTech\LabVNC
LabTech has been successfully uninstalled.
DEBUG: Exiting Uninstall-LTService at line 996
DEBUG: Starting Install-LTService at line 1142
DEBUG: Line 1250: Testing Server Response and Version: https://{sanitized}/LabTech/Agent.aspx
DEBUG: Line 1252: Raw Response: ||||||200.278
DEBUG: Line 1288: Downloading Agent_Install.msi from https://{sanitized}/LabTech/Deployment.aspx?Probe=1&installType=msi&MSILocations=1
WARNING: WARNING: Line 1308: Error encountered downloading from https://{sanitized}.
DEBUG: Line 1250: Testing Server Response and Version: https://{sanitized}/LabTech/Agent.aspx
DEBUG: Line 1252: Raw Response: ||||||200.278
DEBUG: Line 1288: Downloading Agent_Install.msi from https://{sanitized}/LabTech/Deployment.aspx?Probe=1&installType=msi&MSILocations=1
WARNING: WARNING: Line 1308: Error encountered downloading from https://{sanitized}.
Install-LTService : ERROR: Line 1474: No valid server was reached to use for the install.
DEBUG: Exiting Install-LTService at line 1476
DEBUG: Exiting Reinstall-ltservice at line 1697
Install-LTService output:
Install-LTService -server https://{sanitized} -Password '{sanitized}' -SkipDotNet
DEBUG: Starting Install-LTService at line 1142
DEBUG: Line 1250: Testing Server Response and Version: https://{sanitized}/LabTech/Agent.aspx
DEBUG: Line 1252: Raw Response: ||||||200.278
DEBUG: Line 1288: Downloading Agent_Install.msi from https://{sanitized}/LabTech/Service/LabTechRemoteAgent.msi
DEBUG: Starting Test-LTPorts at line 2487
DEBUG: Exiting Test-LTPorts at line 2566
Starting Install.
Waiting for agent to register..........
DEBUG: Starting Get-LTProxy at line 3652
DEBUG: Line 3143: Decoding Server Password.
DEBUG: Line 3226: Attempting Decode for '{sanitized}' with Key 'Thank you for using LabTech.'
DEBUG: Line 3146: Decoding Agent Password.
DEBUG: Line 3226: Attempting Decode for '{sanitized}' with Key '{sanitized}'
DEBUG: Line 3226: Attempting Decode for '{sanitized}' with Key 'Thank you for using LabTech.'
DEBUG: Line 3226: Attempting Decode for '{sanitized}' with Key ''
DEBUG: Line 3266: Failed to Decode string: '{sanitized}'
DEBUG: Line 3266: Failed to Decode string: '{sanitized}'
DEBUG: Line 3266: Failed to Decode string: '{sanitized}'
DEBUG: Line 3668: Setting ProxyServerURL to
DEBUG: Line 3676: Setting ProxyUsername to
DEBUG: Line 3683: Setting ProxyPassword to
DEBUG: Exiting Get-LTProxy at line 3697
LabTech has been installed successfully. Agent ID: 3299 LocationID: 1
DEBUG: Exiting Install-LTService at line 1476
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.