Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8084883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:55:53+00:00 2026-06-05T17:55:53+00:00

I have recently began using C# to invoke powershell scripts, with some success :)

  • 0

I have recently began using C# to invoke powershell scripts, with some success 🙂

$spWeb = Get-SPWeb -Identity http://127.0.0.1 
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary 
$spWeb.Lists.Add($args, "", $listTemplate) > $myDirectory

$spWeb.Lists.Add returns a SharePoint GUID.

Question:

I simply wish to pass in the directory/filename in which the GUID will
be written. How could that be done?

I have posted on the MSDN forums here: http://goo.gl/5p0oz but have continued my search on stackoverflow due to a seemingly dead end thread. This post is a cumulative gathering of the information found through MSDN responses.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:55:55+00:00Added an answer on June 5, 2026 at 5:55 pm

    You can try using the Set-Content cmdlet instead, like this. You need to pass the $myFile as a string and Set-Content will do the rest for you –

    Inside your script i.e. MyScript.ps1 here, you will have this piece of code –

    param([string]$parameter, [string]$myFile)
    try
    {
        $spWeb = Get-SPWeb -Identity http://127.0.0.1 
        $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary 
        $guid = $spWeb.Lists.Add($parameter, "", $listTemplate)
        $guid | Set-Content $myFile
    }
    catch
    {
        throw ("Failed. The error was: '{0}'." -f $_ )
    }
    

    How to Run:
    Open Powershell Prompt and type this

    .\MyScript.ps1 "someparam1" "D:\Output.txt"

    C# Bit –

    private PowerShell _ps;
    _ps = PowerShell.Create();
    
    var parameter = new List<string>
                                    {
                                        parameter,
                                        myFile
                                    };
    
    var sr = new StreamReader(@"C:\MyScript.ps1");
    _ps.AddScript(sr.ReadToEnd()).AddParameters(parameter);
    _ps.Invoke();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While I'm fine with standard control styling in silverlight I have recently began using
I recently have began using prepared statements again in a web application, and I
I have recently begun learning the Win32 API using this tutorial: http://www.winprog.org/tutorial/ (though I'm
I recently began using BIRT and have developed a report to use with my
I've recently began using dTrace and have noticed just how awesome it is. Its
I have recently inherited a large project using an sqlite3 database and currently I
I have recently upgraded to the RC versions of the WebApi using Nuget but
I have recently released an app on Google play see here When using Google
I have recently begun using Scala. I've written a DSL in it which can
I recently began to start using functions to make casting easier on my fingers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.