none
Get-Content with Get-Item RRS feed

  • Question

  • How come this is not working? 

    Foreach ($Server in (get-content "C:\Computers.txt")) 

    {(Get-Item c:\windows\system32\macromed\flash\flash*.ocx | Select @{Name="Server";Expression={$Server}}, VersionInfo).VersionInfo.ProductVersion}

    I want it to output both server name and flash version. It displays the flash version just not the server. I have tried everything I can think of. Please help guys. Still learning. 
    Monday, July 25, 2016 3:02 PM

Answers

  • Create a custom object for output.

    Simple example:

    Get-Content .\pcList.txt | ForEach-Object {
    
        $props = @{
            ComputerName = $_
            OS = (Get-WmiObject Win32_OperatingSystem -ComputerName $_).Caption
    
        }
    
        New-Object PsObject -Property $props
    
    } | Export-Csv .\osVersions.csv -NoTypeInformation


    Monday, July 25, 2016 5:23 PM
  • You want something like this:


    $computerNames = Get-Content "ListOfComputerNames.txt"
    foreach ( $computerName in $computerNames ) {
      Get-ChildItem "\\$computerName\ADMIN$\System32\Macromed\Flash\flash*.ocx" | Select-Object `
        @{Name = "ComputerName"; Expression = {$computerName}},
        Name,
        @{Name = "Version"; Expression = {$_.VersionInfo.FileVersion}}
    }
    


    -- Bill Stewart [Bill_Stewart]

    Monday, July 25, 2016 5:26 PM
    Moderator

All replies

  • Won't work.  You will only get the version of the local computer.  Just listing the name of a server does not allow you to talk to it.

    On Windows 8 and later the flash version is maintained by Windows Update.   Just be sure WU is working correctly.


    \_(ツ)_/

    Monday, July 25, 2016 3:23 PM
  • For starters, you're never checking the remote machines. Each run through the loop you're only checking your local machine.

    Monday, July 25, 2016 3:25 PM
  • So this needs to be a invoke-command. Something like: 

    $version = Invoke-Command -ComputerName (Get-Content Computers.txt) -ScriptBlock {
    (Get-Item c:\windows\system32\macromed\flash\flash*.ocx | Select-Object -Property VersionInfo).VersionInfo.ProductVersion}
    $version

    Am I getting close. 

    Monday, July 25, 2016 3:57 PM
  • $flash=get-item \\$server\c$\windows\system32\macromed\flash\flash*.ocx
    $flash.VersionInfo.FileVersion

    \_(ツ)_/

    Monday, July 25, 2016 4:26 PM
  • thank you, but I still need the output to list server and version number. What you gave me is what I typed the second time just in a different way. 
    Monday, July 25, 2016 5:16 PM
  • Create a custom object for output.

    Simple example:

    Get-Content .\pcList.txt | ForEach-Object {
    
        $props = @{
            ComputerName = $_
            OS = (Get-WmiObject Win32_OperatingSystem -ComputerName $_).Caption
    
        }
    
        New-Object PsObject -Property $props
    
    } | Export-Csv .\osVersions.csv -NoTypeInformation


    Monday, July 25, 2016 5:23 PM
  • You want something like this:


    $computerNames = Get-Content "ListOfComputerNames.txt"
    foreach ( $computerName in $computerNames ) {
      Get-ChildItem "\\$computerName\ADMIN$\System32\Macromed\Flash\flash*.ocx" | Select-Object `
        @{Name = "ComputerName"; Expression = {$computerName}},
        Name,
        @{Name = "Version"; Expression = {$_.VersionInfo.FileVersion}}
    }
    


    -- Bill Stewart [Bill_Stewart]

    Monday, July 25, 2016 5:26 PM
    Moderator
  • Thanks man, this is what I was looking for and i learned a few things in the process. This is for nothing speacal I just couldn't figure it out. Thanks again. 

    Simple is always better


    I'm not here alone.

    Monday, July 25, 2016 5:41 PM
  • Thank you good Sir. this also help me out. 

    I'm not here alone.

    Monday, July 25, 2016 5:41 PM