Jump to content

Running PS1 Script with Parameters


Vivaed
 Share

Recommended Posts

On 9/21/2016 at 11:50 AM, BrewManNH said:

Try this:

ShellExecuteWait('"C:\WB Resources\APP_Prod\Add-AppDevPackage.ps1"')

If it still doesn't work, try it without the outer single quotes around the path and file name. You can't use Run or @ComSpec with a PS script, you need to use ShellExecute. You were also missing the space after /c as well but that wouldn't have helped anyways.

I beg to differ as well.  This is pulled out of script I wrote 1 1/2 years ago:

If @OSVersion == "WIN_7" Then
                If Not FileExists ( @MyDocumentsDir & "\WindowsPowerShell\Modules\PSWindowsUpdate\PSWindowsUpdate.psd1" ) Then
                    $PSUP = InetGet ( "https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/file/41459/43/PSWindowsUpdate.zip", $path & "\PSWindowsUpdate.zip", $INET_IGNORESSL, $INET_DOWNLOADWAIT )
                InetClose ( $PSUP )
                _Zip_UnzipAll ( $path & "\PSWindowsUpdate.zip", @MyDocumentsDir & "\WindowsPowerShell\Modules", 16 )
                Do
                    FileDelete ( $path & "\PSWindowsUpdate.zip" )
                Until Not FileExists ( $path & "\PSWindowsUpdate.zip" )
                RunWait ( @ComSpec & " /c " & 'powershell import-module PSWindowsUpdate', @DesktopDir, @SW_HIDE )
                EndIf

                Run ( @ComSpec & " /c " & 'powershell import-module PSWindowsUpdate', @DesktopDir, @SW_MAXIMIZE )
                Run ( @ComSpec & " /c " & 'powershell Invoke-WUInstall -verbose', @DesktopDir, @SW_MAXIMIZE )
                Else
                    If Not FileExists ( "C:\Program Files\WindowsPowerShell\Modules\PSWindowsUpdate\PSWindowsUpdate.psd1" ) Then
                        $PUP = InetGet ( "https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/file/41459/43/PSWindowsUpdate.zip", $path & "\PSWindowsUpdate.zip", $INET_IGNORESSL, $INET_DOWNLOADWAIT )
                    InetClose ( $PUP )
                    _Zip_UnzipAll ( $path & "\PSWindowsUpdate.zip", "C:\Program Files\WindowsPowerShell\Modules", 16 )
                    Do
                    FileDelete ( $path & "\PSWindowsUpdate.zip" )
                Until Not FileExists ( $path & "\PSWindowsUpdate.zip" )
                RunWait ( @ComSpec & " /c " & 'powershell import-module PSWindowsUpdate', @DesktopDir, @SW_HIDE )
                    EndIf
                EndIf


                Run ( @ComSpec & " /c " & 'powershell import-module PSWindowsUpdate', @DesktopDir, @SW_MAXIMIZE )
                Run ( @ComSpec & " /c " & 'powershell Invoke-WUInstall -verbose', @DesktopDir, @SW_MAXIMIZE )

 

Link to comment
Share on other sites

SMH:mad2:

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 8 months later...
$DeviceName = "Communications Port (COM2)"
$ComPort = "COM2"


function Change-ComPort {

    Param ($Name,$NewPort)

    #Queries WMI for Device
    $WMIQuery = 'Select * from Win32_PnPEntity where Description = "' + $Name + '"'
    $Device = Get-WmiObject -Query $WMIQuery

    #Execute only if device is present
    if ($Device) {
        
        #Get current device info
        $DeviceKey = "HKLM:\SYSTEM\CurrentControlSet\Enum\" + $Device.DeviceID
        $PortKey = "HKLM:\SYSTEM\CurrentControlSet\Enum\" + $Device.DeviceID + "\Device Parameters"
        $Port = get-itemproperty -path $PortKey -Name PortName
        $OldPort = [convert]::ToInt32(($Port.PortName).Replace("COM",""))
        
        #Set new port and update Friendly Name
        $FriendlyName = $Name + " (" + $NewPort + ")"
        New-ItemProperty -Path $PortKey -Name "PortName" -PropertyType String -Value $NewPort -Force
        New-ItemProperty -Path $DeviceKey -Name "FriendlyName" -PropertyType String -Value $FriendlyName -Force

        #Release Previous Com Port from ComDB
        $Byte = ($OldPort - ($OldPort % 8))/8
        $Bit = 8 - ($OldPort % 8)
        if ($Bit -eq 8) { 
            $Bit = 0 
            $Byte = $Byte - 1
        }
        $ComDB = get-itemproperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\COM Name Arbiter" -Name ComDB
        $ComBinaryArray = ([convert]::ToString($ComDB.ComDB[$Byte],2)).ToCharArray()
        while ($ComBinaryArray.Length -ne 8) {
            $ComBinaryArray = ,"0" + $ComBinaryArray
        }
        $ComBinaryArray[$Bit] = "0"
        $ComBinary = [string]::Join("",$ComBinaryArray)
        $ComDB.ComDB[$Byte] = [convert]::ToInt32($ComBinary,2)
        Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\COM Name Arbiter" -Name ComDB -Value ([byte[]]$ComDB.ComDB)
        
    }
}

Change-ComPort $DeviceName $ComPort

can i call that function     "Change-ComPort $DeviceName $ComPort"    and pass different  value  to it , within autoit, right now the file is saved as port.ps1 and the value hard coded in PowerShell as ($DeviceName = "Communications Port (COM2)" $ComPort = "COM2".

In the autoit world  port.ps1  can be an #include. please give me an idea if it's doable

Edited by antonioj84
error
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...