none
Powershell says it can't find the file even though it is I am executing it from the directory it reside in RRS feed

  • Question

  • Hello Scripting guys

        When I change to the directory that the Powershell script resides in I type the filename:

    PS C:\> cd iprereq
    PS C:\iprereq> dir

        Directory: C:\iprereq

            .\instPreReq.ps1

        The problem is that I get an error stating:

    PS C:\iprereq> .\instPreReq.ps1

    InstallPreReqFiles : This command cannot be run due to the error: The system cannot find the file specified.
    At C:\iprereq\instPreReq.ps1:95 char:14
    +        $rc = InstallPreReqFiles
    +              ~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
        + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,InstallPreReqFiles

    PS C:\iprereq>

        Below is the contents of the file:

    param([string] $ipreReq = "c:\ipreReq\")

     
    function InstallPreReqFiles()
    {

        $ReturnCode = 0

        Write-Host ""
        Write-Host "====================================================================="
        Write-Host "Installing Prerequisites required for SharePoint 2013"
        Write-Host ""
        Write-Host "This uses the supported installing offline method"
        Write-Host ""
        Write-Host "If you have not installed the necessary Roles/Features"
        Write-Host "this will occur at this time."
        Write-Host "====================================================================="
        
        
            Try
            {

                 Start-Process "$ipreReq\PrerequisiteInstaller.exe" -ArgumentList "`
                                                                                                 /SQLNCli:`"$ipreReq\PrerequisiteInstallerFiles\sqlncli.msi`" `
                                                                                                 /IDFX:`"$ipreReq\PrerequisiteInstallerFiles\Windows6.1-KB974405-x64.msu`" `
                                                                                                 /IDFX11:`"$ipreReq\PrerequisiteInstallerFiles\MicrosoftIdentityExtensions-64.msi`" `
                                                                                                 /Sync:`"$ipreReq\PrerequisiteInstallerFiles\Synchronization.msi`" `
                                                                                                 #/AppFabric:`"$ipreReq#\PrerequisiteInstallerFiles\WindowsServerAppFabricSetup_x64.exe`" `
                                                                                                 /KB2671763:`"$ipreReq\PrerequisiteInstallerFiles\AppFabric1.1-RTM-KB2671763-x64-ENU.exe`" `                                                                                            
                                                                                                 /MSIPCClient:`"$ipreReq\PrerequisiteInstallerFiles\setup_msipc_x64.msi`" `
                                                                                                 /WCFDataServices:`"$ipreReq\PrerequisiteInstallerFiles\WcfDataServices.exe`""
            }
            Catch
            {
                $ReturnCode = -1
                Write-Error $_
                break
            }    
     
        return $ReturnCode
    }
     
    function CheckProvidedSharePoint2013Path()
    {


        $ReturnCode = 0

        Try
        {
            # Check if destination path exists
            If (Test-Path $ipreReq)
            {
               # Remove trailing slash if it is present
               $script:SharePoint2013Path = $ipreReq.TrimEnd('\')
        $ReturnCode = 0
            }
            Else {

        $ReturnCode = -1
               Write-Host ""
        Write-Warning "Your specified download path does not exist. Please verify your download path then run this script again."
               Write-Host ""
            }


        }
        Catch
        {
             $ReturnCode = -1
             Write-Warning "An error has occurred when checking your specified download path"
             Write-Error $_
             break
        }    
       
        return $ReturnCode

    }


     
    function InstallPreReqs()
    {

        $rc = 0
       
        $rc = CheckProvidedSharePoint2013Path 

        
        # Install the Pre-Reqs
        if($rc -ne -1)
        {
           $rc = InstallPreReqFiles
        }

        if($rc -ne -1)
        {

            Write-Host ""
            Write-Host "Script execution is now complete!"
            Write-Host ""
        }


    }


        Below is the actual script:

    Friday, January 2, 2015 11:28 PM

Answers

  • Ok but what syntax in my script is causing the error?

    It is too hard to tell because it is convoluted and the messages you are posting do not help. Much of your construct produces odd output and you original message indicates you are mmissing one or mmore closures.

    I am not trying to decode your script.  I am just showing you a script that is not likely to produce ambiguous errors.

    Your error can be caused by any one of the quoting issues in the script.  I have posted a mmethod of quoting that is robust.


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, January 5, 2015 12:00 AM
    • Marked as answer by Shabeaut Monday, January 5, 2015 12:50 AM
    Sunday, January 4, 2015 11:59 PM

All replies

  • You do not need 100+ lines to do this.  It only requires this which is also easier to debug:

    param(
        [string]$ipreReq='c:\ipreReq'
    )
    
    If (Test-Path $ipreReq){ 
        $script:SharePoint2013Path = $ipreReq.TrimEnd('\') #'
    }else{
        Write-Warning 'Your specified download path does not exist. Please verify your download path then run this script again.'
        return $false
    }
    
    Write-Host "Installing Prerequisites required for SharePoint 2013" 
    Write-Host "This uses the supported installing offline method"
    Write-Host "If you have not installed the necessary Roles/Features"
    Write-Host "this will occur at this time."
    Try{ 
        $arguments=@(
            ('/SQLNCli:"{0}"' -f "$ipreReq\PrerequisiteInstallerFiles\sqlncli.msi"),
            ('/IDFX:{0}' -f "$ipreReq\PrerequisiteInstallerFiles\Windows6.1-KB974405-x64.msu"),
            ('/IDFX11:' -f "$ipreReq\PrerequisiteInstallerFiles\MicrosoftIdentityExtensions-64.msi"),
            ('/Sync:{0}' -f "$ipreReq\PrerequisiteInstallerFiles\Synchronization.msi"),
            ('/KB2671763:{0}' -f "$ipreReq\PrerequisiteInstallerFiles\AppFabric1.1-RTM-KB2671763-x64-ENU.exe")
            ('/MSIPCClient:{0}' -f "$ipreReq\PrerequisiteInstallerFiles\setup_msipc_x64.msi"),
            ('/WCFDataServices:{0}' -f "$ipreReq\PrerequisiteInstallerFiles\WcfDataServices.exe")
        )
        Start-Process "$ipreReq\PrerequisiteInstaller.exe" -ArgumentList $arguments -ErrorAction Stop
    } 
    Catch{ 
        Write-Error $_
        return $false
    }
    
    Write-Host "Script execution is now complete!"


    ¯\_(ツ)_/¯



    • Edited by jrv Saturday, January 3, 2015 12:21 AM
    Saturday, January 3, 2015 12:20 AM
  • This would be an even more robust method:

    param( [string]$ipreReq='c:\ipreReq' ) $InstallerFiles=Join-Path $ipreReq 'PrerequisiteInstallerFiles' If (Test-Path $InstallerFiles){ Write-Host "Using path $InstallerFiles" -fore green }else{ Write-Warning 'Your specified download path does not exist. Please verify your download path then run this script again.' return $false } Write-Host @' Installing Prerequisites required for SharePoint 2013 This uses the supported installing offline method If you have not installed the necessary Roles/Features this will occur at this time. '@ Try{
    $arguments=@(
            ('/SQLNCli:"{0}"'          -f "$InstallerFiles\sqlncli.msi"),
            ('/IDFX:"{0}'              -f "$InstallerFiles\Windows6.1-KB974405-x64.msu"),
            ('/IDFX11:"{0}"'           -f "$InstallerFiles\MicrosoftIdentityExtensions-64.msi"),
            ('/Sync:"{0}"'             -f "$InstallerFiles\Synchronization.msi"),
            ('/KB2671763:"{0}"'        -f "$InstallerFiles\AppFabric1.1-RTM-KB2671763-x64-ENU.exe"),
            ('/MSIPCClient:"{0}"'      -f "$InstallerFiles\setup_msipc_x64.msi"),
            ('/WCFDataServices:"{0}"'  -f "$InstallerFiles\WcfDataServices.exe")
       )
    Start-Process "$ipreReq\PrerequisiteInstaller.exe" -ArgumentList $arguments -ErrorAction Stop } Catch{ Write-Error $_ return $false } Write-Host "Script execution is now complete!"



    ¯\_(ツ)_/¯





    • Edited by jrv Monday, January 5, 2015 12:10 AM
    Saturday, January 3, 2015 12:31 AM
  • Hello jrv

        Let me take a step back.  Below is the error message:

        InstallPreReqFiles : This command cannot be run due to the error: The system cannot find the file specified.
    At C:\iprereq\instPreReq.ps1:95 char:14

        Based on the code I sent you and the code you sent back to me,
    my question is why is the error saying that the system cannot find the file?

        Thank you
        Shabeaut

    Sunday, January 4, 2015 7:10 PM
  • You cannot get that error from running my version of the script.  Run my version and post any error as a complete error message,.


    ¯\_(ツ)_/¯

    Sunday, January 4, 2015 7:14 PM
  • Ok but what syntax in my script is causing the error?

    Sunday, January 4, 2015 11:53 PM
  • Ok but what syntax in my script is causing the error?

    It is too hard to tell because it is convoluted and the messages you are posting do not help. Much of your construct produces odd output and you original message indicates you are mmissing one or mmore closures.

    I am not trying to decode your script.  I am just showing you a script that is not likely to produce ambiguous errors.

    Your error can be caused by any one of the quoting issues in the script.  I have posted a mmethod of quoting that is robust.


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, January 5, 2015 12:00 AM
    • Marked as answer by Shabeaut Monday, January 5, 2015 12:50 AM
    Sunday, January 4, 2015 11:59 PM
  • The arguments section doesn't need this from your example but it can be done this way.

       $arguments=@(
            ('/SQLNCli:"{0}"'          -f "$InstallerFiles\sqlncli.msi"),
            ('/IDFX:"{0}'              -f "$InstallerFiles\Windows6.1-KB974405-x64.msu"),
            ('/IDFX11:"{0}"'           -f "$InstallerFiles\MicrosoftIdentityExtensions-64.msi"),
            ('/Sync:"{0}"'             -f "$InstallerFiles\Synchronization.msi"),
            ('/KB2671763:"{0}"'        -f "$InstallerFiles\AppFabric1.1-RTM-KB2671763-x64-ENU.exe"),
            ('/MSIPCClient:"{0}"'      -f "$InstallerFiles\setup_msipc_x64.msi"),
            ('/WCFDataServices:"{0}"'  -f "$InstallerFiles\WcfDataServices.exe")
       )

    This forces quotes around all paths.  I also fixed a typo.


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, January 5, 2015 12:07 AM
    Monday, January 5, 2015 12:07 AM
  • Here is an even easier way to do this if the formatters scare you.

    param( [string]$ipreReq='c:\ipreReq' ) $InstallerFiles=Join-Path $ipreReq 'PrerequisiteInstallerFiles' If (Test-Path $InstallerFiles){ Write-Host "Using path $InstallerFiles" -fore green }else{ Write-Warning 'Your specified download path does not exist. Please verify your download path then run this script again.' return $false } $installer="$ipreReq\PrerequisiteInstaller.exe" Write-Host @' Installing Prerequisites required for SharePoint 2013 This uses the supported installing offline method If you have not installed the necessary Roles/Features this will occur at this time. '@ Try{ $arguments=@( ('/SQLNCli:sqlncli.msi', ('/IDFX:Windows6.1-KB974405-x64.msu', ('/IDFX11:MicrosoftIdentityExtensions-64.msi', ('/Sync:Synchronization.msi', ('/KB2671763:AppFabric1.1-RTM-KB2671763-x64-ENU.exe', ('/MSIPCClient:setup_msipc_x64.msi', ('/WCFDataServices:WcfDataServices.exe' ) Start-Process -FilePath $installer -ArgumentList $arguments -WorkingDirectory $InstallerFiles -ErrorAction Stop
    Write-Host "Script execution is now complete!"
    } Catch{ Throw $_ }



    ¯\_(ツ)_/¯



    • Edited by jrv Monday, January 5, 2015 12:23 AM
    Monday, January 5, 2015 12:20 AM