Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, August 22, 2018 6:53 PM
I'm trying to get a simple yes/no answer from a list of servers I've put on a text file. I need to know if they are running a specific version of .NET. The results I keep getting are from the local box I'm running the script from rather than the remote servers I'm trying to connect to. Anyone know how to fix this? Here's what I have so far:
#
#
#
$ErrorActionPreference = "SilentlyContinue"
$computers = Get-Content -Path D:\Scripts\Windows\serverlist.txt
foreach ($computer in $computers){
$val = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name "Release"
if ($val.Release) {
if ($val.Release -eq 379893 ) {
Write-Host "$computer=yes"
} else {
Write-Host "$computer=no"
}
} else {
Write-Host "$computer=NotInstalled"
}
}
All replies (1)
Wednesday, August 22, 2018 7:03 PM âś…Answered | 1 vote
Here comes the Power of PowerShell remoting.
Whatever works locally, works remotely(with few exceptions)
$Output = Invoke-Command -ComputerName $Computers -Scriptblock {
$val = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name "Release"
if ($val.Release) {
if ($val.Release -eq 379893 ) {
$hash = @{status = "yes" }
} else {
$hash = @{status = "yes" }
}
} else {
$hash = @{status = "notinstalled" }
}
New-Object -typename psobject -property $hash
}
$Output
I suggest you to read this doc about remoting.
Regards kvprasoon