Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Invoke-Expression? Sort? Building a script for MDT application replacement and can't quite get it.

$
0
0

Hi.

I did some searching through the forums. I've been working on this for 3 days. I'm somewhat of a noob to powershell.  

The script is to run as an MDT task and reads a file(List of old programs.txt) gathered during the initial scan of the workstation phase. It is going to compare a string in the "List of old Programs file"  and see if it exists in the "list of acceptable new programs file".  If it exists, run the commandline given in that file.

as an example,  in old programs  I have (for testing),

1
2
3
viewer
4
5

and in the new programs list, I have:

Start "viewer" /wait msiexec /I(guid) /qn  

I'd like it to find that "viewer" string in the old file and check through each line of the new file for a matching install and then execute that line.  It seems like it does the comparison and finds it, but I can't convince it to execute the command.

Here is what I've currently got after much mucking about:

$MasterInstallFile=get-content-pathC:\scripts\ListofAcceptableNewPrograms.txt
$OldProgramList =get-content-pathc:\scripts\ListofOldPrograms.txt

Foreach ($itemin$OldProgramList)
{
 if ($MasterInstallFile-match$item)
{
    $LogTime=Get-Date
    $CommandLine= (Select-String$MasterInstallFile-pattern$item)
    
Add-Content-pathC:\scripts\Commandlog.txt$LogTime$CommandLine
    
Invoke-Expression$CommandLine
}}

I'd appreciate it if anyone could tell me where I am going wrong.

Thank you.

 

Ps- Needs to run in PowershellV2 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles