How to execute a command in Powershell Script

rated by 0 users
This post has 2 Replies | 3 Followers

Not Ranked
Posts 1
Rinku garg Posted: 09-16-2011 2:29 AM

Hello Sir

I am writing a powershell script . In this i want to execute the following command .

C:\USMT>scanstate.exe C:\myStore /i:migapp.xml /i:miguser.xml /v:13 /l:mylogs.log

here migapp.xml and miguser.xml files are inside the c:\USMT\

 Note:above this comand is working properly but in script neither  working nor throwing error 

here i am placing my all original code

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text ="User State Migration Tool"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter"){$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape"){$objForm.Close()}})
$ScanButton = New-Object System.Windows.Forms.Button
$ScanButton.Location = New-Object System.Drawing.Size(75,120)
$ScanButton.Size = New-Object System.Drawing.Size(75,23)
$ScanButton.Text = "Scan State"
$ScanButton.Add_Click({& c:\usmt\scanstate.exe c:\mystore\ /i:miguser.xml" /i:migapp.xml /v:5;$objForm.Close()})
$CancelButton= New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Welcome to PowerShell"
$objForm.Topmost = $True
[void] $objForm.ShowDialog()
Top 25 Contributor
Posts 350
Top Contributor

I am having a hard time following what you are doing.

In general, you can run this command (scanstate) by typing it the same as for CMD.EXE, ie.

scanstate.exe C:\myStore /i:migapp.xml /i:miguser.xml /v:13 /l:mylogs.log

If this is not working there may be reasons - but let's see the error message you get out.




Top 10 Contributor
Posts 658
Idera Employee

For one you are missing a beginning quote in this line right after the & and the ending quote may be in the wrong place:

$ScanButton.Add_Click({& "c:\usmt\scanstate.exe c:\mystore\ /i:miguser.xml /i:migapp.xml /v:5";$objForm.Close()})



Page 1 of 1 (3 items) | RSS
Copyright 2012 All rights reserved.