none
Desperate to run on liner DOS commands in powershell RRS feed

  • Question

  • I am down to 3 diffident on liners that work perfectly from the dos prompt but in Powershell I  get the below error.

    ADSchemaAnalyzer.exe : The term 'ADSchemaAnalyzer.exe' is not recognized as the name of a cmdlet, function, script file, or 
    operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    The command is

     ADSchemaAnalyzer.exe  /targetLDIF "C:\Domain2LAB\INFO\PRODSchema.ldif" /baseServer $baseserver /outputLDIF "C:\Domain2LAB\INFO\LAB.LDIF"

    This is the full section of script

    ###################################################
    # Schema START
    ###################################################
    $env:COMPUTERNAME
    
    $baseserver = "$env:COMPUTERNAME.$DNSHostName"
    If (Test-Path "C:\Domain2LAB\INFO\PRODSchema.ldif") { #1
    
    # Find ADSchemaAnalyzer.exe and set location start
    (Get-ChildItem -Path c:\windows -Filter ADSchemaAnalyzer.exe -Recurse).Directory |Export-Csv $env:temp\scrappath.csv -NoTypeInformation 
    $changepath = (Import-Csv $env:temp\scrappath.csv).FullName[1]
    $changepath
    Set-Location "$changepath"
    # Find ADSchemaAnalyzer.exe and set location end
    
    ADSchemaAnalyzer.exe  /targetLDIF "C:\Domain2LAB\INFO\PRODSchema.ldif" /baseServer $baseserver /outputLDIF "C:\Domain2LAB\INFO\LAB.LDIF"
    
    "Wait 15 seconds"
    Start-Sleep 15
    
    ldifde -i -f "C:\Domain2LAB\INFO\Test.ldif" -c dc=x $DistinguishedName
    
    
    } # 1
    
    
    ###################################################
    # Schema END
    ###################################################

    Please tell me there is a way to run a a one liner like the one above?

    Thanks


    Lishron

    Wednesday, March 25, 2015 12:41 PM

Answers

  • I found it before I asked the question.   Duhhh

    It was a syntax error on my part.   I had one too many commas

    Thanks

     $command = @'
    cmd.exe /C ADSchemaAnalyzer.exe  /targetLDIF "C:\Domain2LAB\INFO\PRODSchema.ldif" /baseServer $baseserver /outputLDIF "C:\Domain2LAB\INFO\LAB.LDIF"
    '@
    
    Invoke-Expression -Command:$command


    Lishron

    • Marked as answer by Lishron Wednesday, March 25, 2015 12:47 PM
    Wednesday, March 25, 2015 12:47 PM

All replies

  • I found it before I asked the question.   Duhhh

    It was a syntax error on my part.   I had one too many commas

    Thanks

     $command = @'
    cmd.exe /C ADSchemaAnalyzer.exe  /targetLDIF "C:\Domain2LAB\INFO\PRODSchema.ldif" /baseServer $baseserver /outputLDIF "C:\Domain2LAB\INFO\LAB.LDIF"
    '@
    
    Invoke-Expression -Command:$command


    Lishron

    • Marked as answer by Lishron Wednesday, March 25, 2015 12:47 PM
    Wednesday, March 25, 2015 12:47 PM
  • It's not necessary to use invoke-expression. Just run the command.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, March 25, 2015 2:47 PM
    Moderator