Link to home
Create AccountLog in
Avatar of Ashley
Ashley

asked on

Computer Name not Showing

So this script shows installed applications but it just becomes a jumble of information and doesnt show the computer name (from a list of servers in a text file). Can someone please tell me how to get that to show? This is a powershell script.

Thanks,

Ashley

InstalledApps.txt
Avatar of oBdA
oBdA

That's because of the last line and the Format-Table used there. The Format-* cmdlets are meant to format screen output, not further processing. They should usually be the last element of the pipeline.
The most convenient is usually an export as csv, so that you can easily process it further or view it in Excel or whatever:
$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, Publisher | Export-Csv -NoTypeInformation "C:\DGS Tools\Scripts\logs\installedapps.txt"

Open in new window

If you insist on the table view, you'll have to send the output through Out-String before passing it onto the the file:
$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, Publisher | ft -auto | Out-String -Width 1024 | Out-File "C:\DGS Tools\Scripts\logs\installedapps.txt"\installedapps.txt"

Open in new window

Avatar of Ashley

ASKER

I like the CSV output, but it still doesn't show the computer name. I attached the script I ran this time as InstalledAppsNew.txt and the output I received
installedapps.csv
InstalledAppsNew.txt
That is because you changed line 6 from " $computername = $pc" to "$computername = $pc.Computername".
Change that back, or remove the line completely and change the ForEach in line 4 to use $computer instead of $pc:
foreach ($computer in $computers) {

Open in new window

Avatar of Ashley

ASKER

Without the $pc.computername I get:

Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found.
"
At C:\DGS Tools\Scripts\InstalledApps.ps1:14 char:5
+     $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey(‘LocalMachine’,$comput ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IOException
 
You cannot call a method on a null-valued expression.
At C:\DGS Tools\Scripts\InstalledApps.ps1:18 char:5
+     $regkey=$reg.OpenSubKey($UninstallKey)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
You cannot call a method on a null-valued expression.
At C:\DGS Tools\Scripts\InstalledApps.ps1:22 char:5
+     $subkeys=$regkey.GetSubKeyNames()
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

No matter how I run it. I attached what I've run with changing out to $computer. It's the same output as above
InstalledAppsNew.txt
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Question answered.