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 262547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:31:29+00:00 2026-05-11T22:31:29+00:00

I’m rather new to Powershell and am working on setting up my profile.ps1 file.

  • 0

I’m rather new to Powershell and am working on setting up my profile.ps1 file. I have a few managed DLLs that I use often to maintain processes throughout the day which I’d like to be able to load up with quick function calls. So I created this function in my ps1 file:

function LoadSomeDll
{
    [System.Reflect.Assembly]::LoadFrom("c:\wherever\SomeLib.dll")
    return new-object "SomeLib.SomeObject"
}

Then, in Powershell, I do this:

PS > $myLibInstance = LoadSomeDll

The problem is that $myLibInstance, though it appears to be loaded, doesn’t behave the way I expect it to or if it would if I explicitly load it without the function. Say SomeLib.SomeObject has a public string property “ConnectionString” that loads itself (from the registry, yuck) when the object is constructed.

PS > $myLibInstance.ConnectionString
//Nothing returned

But, if I do it without the function, like this:

PS > [System.Reflect.Assembly]::LoadFrom("c:\wherever\SomeLib.dll")
PS > $myOtherLibInstance = new-object "SomeLib.SomeObject"

I get this:

PS > $myOtherLibInstance.ConnectionString
StringValueOfConnectionStringProperty

Why does this happen? Is there any way that I can return an instantiated new-object from a Powershell function?

Thanks in advance.

  • 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-05-11T22:31:29+00:00Added an answer on May 11, 2026 at 10:31 pm

    The problem you’re running into is that your original function is returning an array of objects, not a single object.

    One of the tricks in PowerShell is understanding that in a function, every statement which evaluates no a non-void value will be written to the pipeline. The return “value” of a function is simply the contents of the pipeline.

    The call to LoadFrom returns an assembly. So the actual return of the function LoadSomeDll is an array containing an assembly and an instance of your object. You’re actually calling ConnectionString on the type Object[] and hence it silently fails.

    Try switching the function to the following. I intentionally left off the keyword return because it’s confusing in the context of powershell.

    function LoadSomeDll
    {
        [System.Reflect.Assembly]::LoadFrom("c:\wherever\SomeLib.dll") | out-null
        new-object "SomeLib.SomeObject"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is

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.