none
PowerShell Script to run multiple child script with different instances windows PowerShell X86 & SharePoint 2013 Management shell RRS feed

  • Question

  • Hello Scripting Guys,

    I am trying to get data from Oracle 11G(32 bit) & save it to SharePoint 2013(64 bit)

    I had tried many permutations & combinations but unable to wrote a single script to do so, because of their “bit” dependency. Finally I wrote two different script.

    Script 1 (32-bit) : Get the data from Oracle 11G & save to csv

    Script 2 (64-bit): Get the data from csv file & save to SharePoint custom list.

    Now the issue is if I am running script 1 the by default it runs with 64 bit instance because machine is 64 bit server.

    If I try to change the execution path then the other scripts, which are running with 64 bit were stopped working.

    Can I have some solution by which I can force my scripting code to execute in specific bit . like

    Script 1 code should run with windows PowerShell X86 then pause for 5 mins then Script 2 code should execute with SharePoint 2013 Management shell.

    Friday, September 2, 2016 10:16 AM

Answers

  • It would be great if you could share some code snippet to do so. Also I truly agree with you that we need to deal with XML to get rid of data type conflict. Please try to share some link by which i can do the same.

    Hi,

    sure, here's an example:

    # Start x86 Script
    Start-Process "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Powershell.exe" -ArgumentList '-File C:\scripts\scriptx86.ps1' -Wait

    Working with XML is fairly simple, as the linked cmdlets work pretty much the same way as Export-Csv and Import-Csv do. You can ask PowerShell itself how a command works:

    # Just the Example
    Get-Help Import-Clixml -Examples
    Get-Help Export-Clixml -Examples
    
    # Detailed description
    Get-Help Import-Clixml -Detailed
    Get-Help Export-Clixml -Detailed

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Saturday, September 3, 2016 7:06 AM

All replies

  • Hi,

    sure you can do this from within a single script:

    You can use Start-process to run code of Script 1 in a x86 PowerShell process (use the -Wait parameter to wait until it's done), then you can simply take the exported function and continue on in the original script.

    Options to implement this:

    • Keep two separate scripts, one starting PowerShell.exe in the correct bitness with the -File parameter
    • Store both scripts in the same file (one as long text) and launch PowerShell.exe with the encoded command parameter (run "powershell.exe /?" and check the examples at the end for an explanation).

    Cheers,
    Fred

    PS: Consider transmitting the data as XML, rather than Csv if data types are relevant (Export-CliXml & Import-CliXml).


    There's no place like 127.0.0.1

    Friday, September 2, 2016 11:44 AM
  • Thanks Fred for your prompt response.

    It would be great if you could share some code snippet to do so. Also I truly agree with you that we need to deal with XML to get rid of data type conflict. Please try to share some link by which i can do the same.


    Friday, September 2, 2016 12:32 PM
  • You do not need to use a 32 bit client to connect to Oracle.  Oracle also has a 64 bit driver which should be installed on 64 bit systems.  There is no bit dependency.  We have never had to do what you are doing.


    \_(ツ)_/

    Friday, September 2, 2016 2:18 PM
  • It would be great if you could share some code snippet to do so. Also I truly agree with you that we need to deal with XML to get rid of data type conflict. Please try to share some link by which i can do the same.

    Hi,

    sure, here's an example:

    # Start x86 Script
    Start-Process "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Powershell.exe" -ArgumentList '-File C:\scripts\scriptx86.ps1' -Wait

    Working with XML is fairly simple, as the linked cmdlets work pretty much the same way as Export-Csv and Import-Csv do. You can ask PowerShell itself how a command works:

    # Just the Example
    Get-Help Import-Clixml -Examples
    Get-Help Export-Clixml -Examples
    
    # Detailed description
    Get-Help Import-Clixml -Detailed
    Get-Help Export-Clixml -Detailed

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Saturday, September 3, 2016 7:06 AM
  • Thanks again Fred. I ha tried as you suggested but while execution of second script, I am getting error. 

    Code Snippet: 

    Start-Process "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-File F:\R_Code\Script_PowerShell\ihrms\getdata.PS1" -Wait

    Start-Process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-File F:\R_Code\Script_PowerShell\ihrms\cpy2SP.PS1"

    Error Code: 

    The term 'Import' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spel
    ling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:19
    + $contents = Import <<<<  -clixml -Path F:\R_Code\Script_PowerShell\ihrms\ss64_ihrms_$today.xml
        + CategoryInfo          : ObjectNotFound: (Import:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException


    Saturday, September 3, 2016 8:35 AM
  • Hi,

    Try to avoid spaces within a cmdlet. It's Import-Clixml, not Import -Clixml.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Saturday, September 3, 2016 9:38 AM
  • Fred, I troubleshooted it & came to know that error is not coming due to syntax but In my second script I need to call SharePoint Management shell correct path ... where I was referring wrong path.

    correct path is C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe  -NoExit  " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' " 

    New Code : 

    Start-Process "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-File F:\R_Code\Script_PowerShell\ihrms\getdata.PS1" -Wait

    Start-Process "C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe  -NoExit " " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' " -ArgumentList "-File F:\R_Code\Script_PowerShell\ihrms\cpy2SP.PS1"

    Error code:--

    Start-Process : A positional parameter cannot be found that accepts argument '
    & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CON
    FIG\POWERSHELL\Registration\\sharepoint.ps1 ' '.
    At F:\R_Code\Script_PowerShell\ihrms\ParentpowerShell - Copy.PS1:1 char:1
    4
    + Start-Process <<<<  "C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.ex
    e  -NoExit " " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Ex
    tensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' " -ArgumentList "-
    File F:\R_Code\Script_PowerShell\ihrms\cpy2SP.PS1"
        + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterB
       indingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
       .Commands.StartProcessCommand

    Here I am still unable to craft the path correctly. Can you please suggest something. 

    Saturday, September 3, 2016 9:59 AM
  • Sure,

    # Step 1: Get Data
    Start-Process "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-File F:\R_Code\Script_PowerShell\ihrms\getdata.PS1" -Wait
    
    # Step 2: Import Sharepoint the same way the Sharepoint Shell does
    . "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\sharepoint.ps1"
    
    # Step 3: Call the copy script
    . "F:\R_Code\Script_PowerShell\ihrms\cpy2SP.PS1"

    Theoretically, you could implement this at the top of the copy script and save yourself a file (or take JRV's advice and use the x64 drivers for Oracle, allowing you to do it all from within a single script).

    Cheers,
    Fred


    There's no place like 127.0.0.1


    • Edited by FWN Saturday, September 3, 2016 1:04 PM typo
    Saturday, September 3, 2016 10:43 AM