how do i out put from AD or txt - powershell

I am trying to run this programme against a a list of remote pc/servers either by AD out TXT and display them in either csv or html if any one can offer some help or advise I would be greatly appreciative.
My only limitation is all my machines run powershell v2 only
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Format-Table –AutoSize

You want to take the output of that command and put it in a file? PowerShell has a lot of tools to do this. However, you need to remove the Format-Table command first.
See, Format-Table is all about making your command output look really good in a PowerShell window, so it's got a lot of hard returns and columns and things defined in it which make sense to the console, but look like garbage when you export it.
For data like this, I think Comma Separated Value is probably the way to go.
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path \\server\share\$($env:ComputerName)_Programs.csv
This example will export a CSV, omitting the import-helper info PowerShell normally adds, using the -NoTypeInformation switch. I figured it'd be useful to know the name of the computer which made the file, so that's just what it will do. Edit -Path to point to a server with a share and away you go. You'll end up with files like this:
ComputerA_Programs.Csv
ComputerB_Programs.Csv
ComputerC_Programs.Csv

If you want to pull from all Ad computers
ForEach ($COMPUTER in (Get-ADComputer -Filter * | Select-Object -ExpandProperty Name))
{if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else{Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path "\\server\share$\$Computer_Programs.csv" -NoTypeInformation}}
for if you have list of computers in text
Foreach ($computer in ($computers= Get-Content "c:\Computers.txt" ))
{if(!(Test-Connection -cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else{
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path "\\server\share$\$Computer_Programs.csv" -NoTypeInformation
}}

Related

How to get a program's installation path using Powershell

I've tried to use Get-ChildItem to get installed program property information and it does provide some of the information I require but the Installed Location/path is usually blank. Given a program's name/displayname, is there a way reliable way to get the installation path of a Windows Server program (remote to other servers) using Powershell?
Thanks in advance.
Using Registry:
Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
% { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation
Using WMI:
Get-WmiObject -Class Win32_Product -Filter 'Name like "%Microsoft Office%"' |
Select Caption,InstallLocation
For Remoting, Through registry it's totally different story, with WMI just add the -ComputerName Parameter (and make sure you have permissions)
These 2 cmdlets:
Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | % { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation | Sort-Object Displayname -Descending
Get-ChildItem HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | % { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation | Sort-Object Displayname -Descending
These show different programs and their locations

Powershell split items into text file into multiple variables

I am trying to run a software script against my servers, to see exactly what software is installed and what version. I have the list of the servers stored in a text file "SystemList.txt" that is formatted like you see below.
SERVER001
SERVER002
SERVER003
SERVER004
I need to pull the server names out of the file and use them in my csv that I need to look like this:
Here is the code:
$computers = Get-Content -path
D:\Users\stephen.lyons.sa\Documents\SystemList\SystemList.txt
Foreach($computer in $computers)
{
$computer
$env:COMPUTERNAME
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*
|Select-Object Displayname, DisplayVersion, Publisher, InstallDate | Out-
file \\txusocts002\d$\APSO\Steve\Test\$env:COMPUTERNAME.csv
}
Perhaps I am missing something, but would this meet your CSV file need?
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object -Property DisplayName,DisplayVersion,Publisher,InstallDate |
Export-Csv -Path my.csv

Outputing contents to CSV with Powershell

I use this site alot while learning Powershell. Its been a great help so far!
Here is my issue:
I am trying to write a script that will take workstation names, pull the workstation description from WMI and output both the workstation name and description found into a new .csv file.
Here is what I have so far:
Get-Content -Path "workstation_names.csv" | Select-Object Workstations |
Foreach-Object { Get-WmiObject -Class Win32_OperatingSystem -ComputerName $workstations | Select Workstations, Description | Export-CSV -Path "results.csv" -NoTypeInformation }
The workstation_names.csv has a column named "Workstations" and under it each cell has a single workstation name in it. Currently my script will create an output file that will have two columns in it. One called "Workstations" and the other called "Description". The Workstation column is empty, and the Description column only has the results for the first workstation description in it (even though I have 10 workstation names listed in the workstation_names.csv file).
I am sitting here scratching my head with my n00bish knowledge of Powershell. I know I PROBABLY need to so something with the array that is created from the first .csv file but I am not sure how to code what I need. Any help??
Probably something like this should do the trick:
$inFile = "workstation_names.csv"
$results = #()
Import-CSV -path $inFile -header Workstations |
% {$results += Get-WmiObject -Class Win32_OperatingSystem `
-ComputerName $_.Workstations | Select PSComputerName, Description}
$results | Export-Csv -Path "results.csv" -NoTypeInformation
So to elaborate on this, you aren't really importing the CSV, you are importing the raw text file, which is confusing, since I don't really understand how anything works for you in that case. Here the script will create an array to store the results, import file as CSV, loop through the valuables and output results to the CSV.
4c74356b41's script will fail for several reasons
It's -header not -headers
there is a typo %_ instead of $_
select Workstations won't work as that's no property of gwmi
This only slightly reworked script should do.
$inFile = "workstation_names.csv"
$results = #()
Import-CSV -path $inFile -header Workstations |
% {$results += Get-WmiObject -Class Win32_OperatingSystem `
-ComputerName $_.Workstations | Select PSComputerName, Description}
$results | Export-Csv -Path "results.csv" -NoTypeInformation
To see which properties are available see the following output
GWmi -Class Win32_OperatingSystem -ComputerName localhost|gm|out-gridview

Using Powershell to build a list of computer model numbers in our Domain?

As the title states, I am trying to determine every computer model used in our domain. I am new to the company, and have been placed in charge of producing a new encryption solution for all end point devices. By knowing the computer models in our domain, I will be able to determine which machines have a TPM 1.2 chip, and which ones don't (almost 15k devices). I do not need anything to look pretty, but I'm open for ideas. I more or less want a list (text or csv for sorting purposes) so I can quantify models and research.
Here's what I have so far:
Get-ADComputer -Filter {Name -like 'ML*'} | select -expand name |
ForEach {
If (Test-Connection $_ -count 1 -quiet)
{Get-WmiObject -Class Win32_ComputerSystem -ComputerName $_} Select-Object -Property model | Export-Csv "c:\scripts\Models.csv"}
Else { Add-Content -value $_ c:\scripts\not.responding.txt}
I know there are problems with this. Right now I'm having trouble querying AD and passing the computer name variable only. Because of this, the ping test fails, and everything exports to the failed text file. The failed text file indicates that the variable includes a lot more than just the computer name. If I can pull the variable correctly, I'm not sure if the rest would work, but I think it should. Any help would be greatly appreciated.
$ComputerNames = Get-ADComputer -Filter {Name -like 'ML*'} | select -expand name
foreach ($computername in $ComputerNames){
If (Test-Connection $computername -count 1 -quiet){
Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computername | Select-Object -Property model | Export-Csv "c:\scripts\Models.csv"
}
else{
Add-Content -value $computername c:\scripts\not.responding.txt
}
}
there you go.

How to remove extra lines from Get-WMIObject output powershell

I am running the following query to get the video driver version number
Get-WmiObject Win32_videoController | where {$_.Name -like "Nvidia*"} | Format-table -HideTableHeaders DriverVersion
It returns the data I want plus about 4 extra lines. One before the output and 3 after. It doesn't look like it's going to show up properly in the post.
PS F:\>
Get-WmiObject Win32_videoController | where {$_.Name -like "Nvidia*"} | Format-table -HideTableHeaders DriverVersion
9.18.13.3250
PS F:\>
If you want to determine the driver version, forget about Format-Table. Simply do this:
Get-WmiObject Win32_VideoController -Filter "Name LIKE 'Nvidia%'" |
Select-Object -Expand DriverVersion
Note: You can also use the aliases gwmi for Get-WmiObject and select for Select-Object. Beware, though, that aliases may not be present during script execution depending on your environment. They're basically a means to reduce the amount of typing required in an interactive console.
Not sure exactly if this is what you want but give this a try.
This will only display the "Unique" driver versions. This will get rid of the dupe entrys
Get-WmiObject Win32_videoController | Where {$_.Name -like "Nvidia*"} | Select-Object DriverVersion -Unique | Format-Table -HideTableHeaders