Solved

How do you run executables and their parameters inside of Microsoft Powershell?

Posted on 2010-09-09
3
809 Views
Last Modified: 2012-05-10
I am attempting to run the following block of code, and I am getting a black DOS window to appear and disappear. I translated a batch file over to Microsoft Powershell. I know that the code for making the bubble works below, but I am having trouble finding out why the code that I am running to make the same executables that were working withing the batch file not working inside of Powershell. My end goal with this project is to call the powershell code and run it once versus having a batch file call it. This file will be used on a great number of PCs, so all of them will have Powershell and Windows XP SP 3.

Set-ExecutionPolicy RemoteSigned


if(!Test-Path C:\program Files\Logs\*.*)
{
	New-Item C:\Program Files\Logs -type directory
}

Invoke-Item uninstall_flash_player.exe /clean /silent

Invoke-Item msiexec.exe /I"install_flash_player_10_active_x.msi" REBOOT=ReallySuppress ALLUSERS=1 /qb-! /l*v "C:\Program Files\Logs\Adobe Flash Player 10.1 (EN).log"

Invoke-Item copy "mms.cfg" "%windir%\system32\macromed\flash\mms.cfg" /Y

pause


[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
#System Tray Balloon Popup 
     #The popup mesage 
     $Message="Flash has been upgraded to 10.1 Successfully Contact the Service Desk if you have issues after the install." 
  
     # Valid Message types "Info" "Error" "Warning" "None" 
     $MessageType="Info" 
     
    # The number of seconds to display the message. 
     [int]$duration=60
    #load Windows Forms and drawing assemblies 
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null 
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null 
  
    #define an icon image pulled from PowerShell.exe 
    $icon=[system.drawing.icon]::ExtractAssociatedIcon((join-path $pshome powershell.exe)) 
    $notify = new-object system.windows.forms.notifyicon 
    $notify.icon = $icon 
    $notify.visible = $True 
  
    #define the tool tip icon based on the message type 
    switch ($messagetype) { 
     "Error" { $messageIcon=[system.windows.forms.tooltipicon]::Error} 
     "Info" {$messageIcon=[system.windows.forms.tooltipicon]::Info} 
     "Warning" {$messageIcon=[system.windows.forms.tooltipicon]::Warning} 
     Default {$messageIcon=[system.windows.forms.tooltipicon]::None} 
    } 
    $notify.showballoontip($duration,$Title,$message,$MessageIcon) 
 

Open in new window

0
Comment
Question by:thenthorn1010
3 Comments
 
LVL 7

Expert Comment

by:wittyslogan
ID: 33645174
can I just check?  Are you tyring to run this code in a powershell window and it won't work or you are calling it from a file and it won't work.

And what errors is it showing if any?
0
 
LVL 3

Accepted Solution

by:
gs121 earned 500 total points
ID: 33650331
Had to run a cmd utlilty in the past, this worked for me.
Place the entire cmd including variables into a single variable  ($d) and then execute a cmd.
in my example the exe was exchmbx, I had it in a foreach statement to do an array of users.
basicly I turn the entire statement into text and sent it to a command prompt.

$d = "exchmbx $b $userdn -move mmcexchange:$loc"
   #Write-Host $d  to see command line
   #execute command below
cmd /c $d
0
 

Author Comment

by:thenthorn1010
ID: 33651399
I am trying to run this from a command line script.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
A procedure for exporting installed hotfix details of remote computers using powershell
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now