Guide me: Powershell

Hi Guys,

Just to let you know I've never used powershell before and I'm trying to learn it.

I've been tasked with creating a script that:

1) imports data from a CSV file and gives it headers
2) pulls all rows of data in which Column B contains *java*
3) Creates a WMI Enum Class Called "LBE_JavaVer"
4) Creates properties in the Class which have the same names as the CSV Headers (which I defined in powershell)
5) Inserts selected data's values into the correct WMI Class property.

The first issue I'm having (before I even attempt the WMI stuff) is importing the CSV data.

The script will be run on 4000+ machines and I need to pull the file from Appdata\Local. The $env:LOCALAPPDATA variable isn't working for me. What should I use here?



  • Edited by Joncy92 16 hours 38 minutes ago
September 11th, 2015 10:26am

Hi,

You have your path enclosed in single quotes, which won't allow the variable to expand.

I highly recommend spending some time going over the very basics before you continue on:

https://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 10:33am

thanks
September 11th, 2015 10:35am

Okay.

Here's what I have so far:

$JavaArray = @()
$URLArray = @()
$PlugVerArray =  @()
$FileVerArray = @()
$AllowedArray = @()
$BlocklistArray = @()
$EPMArray = @()

Import-Csv 'C:\Users\JChristodoulou\AppData\Local\Microsoft\Internet Explorer\AuditMode\VersionAuditLog.CSV' -Header URL,Plugin,PlugVer,FileVer,Allowed,Blocklist,EPM |`
    ForEach-Object {
        $JavaArray += $_.Plugin
		$URLArray += $_.URL
		$PlugVerArray += $_.PlugVer
		$FileVerArray += $_.FileVer
		$AllowedArray += $_.Allowed
		$EPMArray += $_.Allowed
    }

$JavaString = "C:\Program Files (x86)\Java\jre1.8.0_51\bin\jp2iexp.dll"

if ($JavaArray -contains $JavaString)
    {
    $Where = [array]::IndexOf($JavaArray, $JavaString)
    Write-Host "Ver: " $PlugVerArray $JavaArray[$Where]
    }

; Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

The output of course writes every single item in the PlugVer column. How can I make the script select/display only the values in the same column as the Java ones?

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 11:07am

What is the purpose of the script?

For example, "I want to determine the version of java installed on a group of computers."

September 11th, 2015 11:09am

I want the script to pull the rows out of the CSV where column B contains *Java* and then insert the data into WMI. As in my first post:

1) imports data from a CSV file and gives it headers
2) pulls all rows of data in which Column B contains *java*
3) Creates a WMI Enum Class Called "LBE_JavaVer"
4) Creates properties in the Class which have the same names as the CSV Headers (which I defined in powershell)
5) Inserts selected data's values into the correct WMI Class property.

Thanks.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 11:23am

That tells what you want to do, but not why.

What is the purpose?

September 11th, 2015 11:40am

Here is a basic starter:

Import-Csv .\input.csv -Header URL,Plugin,PlugVer,FileVer,Allowed,Blocklist,EPM |
    Where { $_.Plugin -like '*java*' }


Example input.csv contents:
a1,something java something,a3,a4,a5,a6,a7
b1,something java something,b3,b4,b5,b6,b7
c1,something else something,c3,c4,c5,c6,c7
d1,something java something,d3,d4,d5,d6,d7

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 12:14pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics