ITCooky Recipes

Lets cooky it yammy things!

Powershell script to update the 1C Enterprise client on several PCs over the network!

дата March 1, 2020

Powershell is also useful … if you believe in it … if you force it! There are a thousand PCs and an IT specialist (also a system administrator, infrastructure specialist, “the It gay”, loader, counter), and you have to update 1C 8.3 the day before yesterday!
1C itself is also a wonderful thing, the database is linked to a specific version of the client that searches and runs on the user’s PC! And the versions of this client are updated several times per year and it works only with a specific version of the database, it is not a junk like SAP GUI with minor updates only every 5 years – 1C is a live system, you always need to correct some Bugs and kick it with pissed rags to make it work!

But, returning to Powershell, for it to work on computers, they must be in the AD domain, and the permissions to run Powershell Remote must be set in some way through AD GP!

The Powershell script cannot be started by double clicking or through the icon (if you don’t believe it, try it). First, run ISE as an administrator, and you must be an AD administrator yourself; In any case, you will have to play with the rights, but I was lucky and the administrators who ran away from this jobe position, before me, already has solved the rights problem! There are no commands to verify if Powershell can be run on a remote PC, but you can start a remote session of Powershell on ISE (you must wait a minute, it not respond immediately) and try to execute something, if it works it works!

We will update in three stages.
1. Interrogate PCs available on the network for the presence of 1C and its version
2. Send them a command to install a new version of 1C
3. Once again, we interrogate and find out if a new version of 1C has appeared on the PC

Powershell script to get the software version on a remote PC
I need a file with hosts, I take it out of AD from computer groups. First we delete old hosts.txt and then load the OU lists and make a new file.

rm $PSScriptRoot\hosts.txt
Get-ADComputer -Filter * -SearchBase “OU=DESKTOPS,OU=NIZHNEWARTOVSK,OU=Russia,OU=All,DC=com,DC=tesla,DC=local” | select -exp Name | ForEach-Object { Add-Content $PSScriptRoot\hosts.txt "$_"}
Get-ADComputer -Filter * -SearchBase “OU=NOTEBOOKS,OU=NIZHNEWARTOVSK,OU=Russia,OU=All,DC=com,DC=tesla,DC=local” | select -exp Name | ForEach-Object { Add-Content $PSScriptRoot\hosts.txt "$_"}

We are now interrogating these hosts, whether they are accessible through the network, if not, we write what is not in the result_down.txt file. We are looking for the name of the software manufacturer. It can be in English (1C-Soft, for some reason), in Russian (1C-Soft, clearly), and possibly in some other.

At the same time we are looking for the version we need to install 8.3.16.1148, just in case it is already installed!



rm $PSScriptRoot\hosts_to_add.txt
rm $PSScriptRoot\hosts_down.txt
rm $PSScriptRoot\allready_installed.txt
Get-Content $PSScriptRoot\hosts.txt | ForEach-Object {
if(!(Test-Connection -Cn $_ -BufferSize 16 -Count 1 -ea 0 -quiet))
{ 
Add-Content $PSScriptRoot\hosts_down.txt "$_"
} else {
$1cversion = Get-WmiObject -Class Win32_Product -ComputerName $_ | where{$_.Vendor -like "1C-Soft" -or $_.Vendor -like "1С-Софт"} | select -exp Version
if($1cversion -like "8.3.16.1148"){ 
Write-Host "$_ - Allready installed 8.3.16.1148"  -ForegroundColor Cyan
Add-Content $PSScriptRoot\allready_installed.txt "$_"
} else { 
Write-Host "$_ - Not present 8.3.16.1148"  -ForegroundColor Cyan
Add-Content $PSScriptRoot\hosts_to_add.txt "$_"
Get-Service remoteregistry -ComputerName "$_" | start-service
}
}
}

By the way, this survey, depending on the horrible state of PCs, will take an 8-hour business day for approximately 1000 PCs (old-new)! Well, you should do it during business hours when the PC is online!

Powershell script to install software on multiple computers across the network
Now it turns out that you can’t just log into remote PCs using Powershell and run a silent installation there (for 1C with argument / quiet) from the distribution kit on a network share. You can only run from local folders, so first copy the installation files to the remote PC and then run them.



Get-Content $PSScriptRoot\hosts_to_add.txt | ForEach-Object {
Get-Service remoteregistry -ComputerName "$_" | start-service
Write-Host "$_ - Copying files to host wait"  -ForegroundColor Red
Copy-item -Path "\\RUNVFS1002937446777\soft\1C83\8_3_16_1148" -Destination "\\$_\c$\windows\temp\" -Recurse -force
Write-Host "$_ - Starting quiet installation porcess"  -ForegroundColor Cyan
$InstallString = "C:\windows\temp\8_3_16_1148\setup.exe /quiet"
([WMICLASS]"\\$_\ROOT\CIMV2:Win32_Process").Create($InstallString)

This also takes a working day for 100 pcs, for the old ones much longer than for the new ones, sometimes the process stops for half an hour just like that!

Powershell script to verify the software version on several computers in a network
Here, on the one hand, I do it silly, we are only looking for a version in all the output of the installed programs, we believe it is unique!
And, on the other hand, this is the safest way to find it: if you do it intelligently, first look for the 1C manufacturer, then you don’t always find a new version, even if the installation is successful!



rm $PSScriptRoot\result_installed.txt
rm $PSScriptRoot\result_not_installed.txt
Get-Content $PSScriptRoot\hosts_to_add.txt | ForEach-Object {
if(!(Test-Connection -Cn $_ -BufferSize 16 -Count 1 -ea 0 -quiet))
  { 
Write-Host "$_ is down"  -ForegroundColor Red
  } else {
$1cversion = Get-WmiObject -Class Win32_Product -ComputerName $_ | where{$_.Version -like "8.3.16.1148"} | select -exp Version
if($1cversion -like "8.3.16.1148"){ 
Add-Content $PSScriptRoot\result_installed.txt "$_"
Write-Host "Yes for $_"  -ForegroundColor Cyan
} else {
Add-Content $PSScriptRoot\result_not_installed.txt "$_"
Write-Host "No for $_"  -ForegroundColor Red}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *