Answer the question
In order to leave comments, you need to log in
How to solve the problem with displaying values from the registry through Invoke-Command?
Good afternoon. There is a script with which I try to display license keys from CryptoPro (FIND_CRYPTOPRO_KEY) and CryptoARM (FIND_CRYPTOARM_KEY) on remote PCs from the registry.
$compname = 'AST'
$cripto5 = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\08F19F05793DC7340B8C2621D83E5BE5\InstallProperties'
$cripto4 = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\7AB5E7046046FB044ACD63458B5F481C\InstallProperties'
$kriptoarm = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Digt\Trusted Desktop\License'
Write-Output FIND_CRYPTOARM:(Invoke-Command -ComputerName $compname -ScriptBlock { Test-Path -Path $using:kriptoarm })
Write-Output FIND_CRYPTOPRO4:(Invoke-Command -ComputerName $compname -ScriptBlock { Test-Path -Path $using:cripto4 })
Write-Output FIND_CRYPTOPRO5:(Invoke-Command -ComputerName $compname -ScriptBlock { Test-Path -Path $using:cripto5 })
Write-Output FIND_CRYPTOPRO_KEY
if (Invoke-Command -ComputerName $compname -ScriptBlock { Test-Path -Path $using:cripto5 }) {
Invoke-Command -ComputerName $compname -ScriptBlock { Get-ItemProperty -Path $using:cripto5 -Name ProductID } | Select-Object "ProductID"
}
elseif (Invoke-Command -ComputerName $compname -ScriptBlock { Test-Path -Path $using:cripto4 }) {
Invoke-Command -ComputerName $compname -ScriptBlock { Get-ItemProperty -Path $using:cripto4 -Name ProductID } | Select-Object "ProductID"
}
else {
Write-Output CryptoPro not found
}
Write-Output ([System.Environment]::NewLine)
Write-Output FIND_CRYPTOARM_KEY
if (Invoke-Command -ComputerName $compname -ScriptBlock { Test-Path -Path $using:kriptoarm }) {
Invoke-Command -ComputerName $compname -ScriptBlock { Get-ItemProperty -Path $using:kriptoarm -Name SerialNumber } | Select-Object "SerialNumber"
}
else {
Write-Output CryptoARM not found
}
Answer the question
In order to leave comments, you need to log in
It's easier to drive everything into one call once.
So it will work many times faster and you can run it simultaneously on several computers, only you need to include the name of the computer in the output
invoke-command -comp $comp {
# а здесь все красоты
# причём циклом
$source @(
@{ key name= '''; valuename=''},
@{ key name= '''; valuename=''}
)
foreach ($src in $source) {
get-itemproperty -path $src.keyname | select -expandproperty $src.valuename
}
}
Execute the script block by block - check that each block does what you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question