I am trying to get registry key values from a remote machine using Invoke-Command. but when I am executing, it is not fetching the value. the session is getting connected successfully.
below is code
$TOD_Data= @(Import-Csv -Path "C:\data.csv")
$Remote_Server_Name = $TOD_Data.name
$cred = Get-Credential
$Session = New-PSSession -ComputerName $Remote_Server_Name -Credential $cred
$regkey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$regparam = "LOGINventory Offline Agent 8"
try
{
if (Invoke-Command -Session $Session -ScriptBlock {Get-ItemProperty -Path $regkey -Name $regparam -ErrorAction Ignore})
{
Write-Host "Found"}
else
{
Write-Host "Registry Key Not Found.."
}
}catch{write-host "$Error.Exception.Message" -BackgroundColor Red -ForegroundColor White}
Please do let me know on this