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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:24:04+00:00 2026-05-28T19:24:04+00:00

//powershell code $quiotent = divRemainderQuiotent ($a) ($b) ([ref] $remainder) # I need to pass

  • 0
//powershell code

$quiotent = divRemainderQuiotent ($a) ($b) ([ref] $remainder) # I need to pass this $remainder as reference

For that I need to pass it as PSReference

//csharp code 

private PSReference remainder= null;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1044:PropertiesShouldNotBeWriteOnly"),
       Parameter(
           Position = 2,
           Mandatory = true,
           ValueFromPipeline = true)]
        [ValidateNotNullOrEmpty]
        public PSReference Remainder // if I don’t use this and use a value type and later change it to ref (inside C#) the result won’t bubble up, which I think is bad.
        {
            set { remainder = value; }
        }

But now the problem becomes, the function that takes this parameter as ref integer.

  protected override void ProcessRecord()
        {
            //main method, this is executed when cmdlet is run
            int r = remainder ; //this is the problem I cannot convert PSReference to other object type (integer here).
            int q = _csharpDivideRemainderQuiotent(a,b, ref r); // if I change this function to take PSReference type, I will have to make changes down the line for every function.
            WriteObject(q);
        } // method ProcessRecord
  • 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-28T19:24:05+00:00Added an answer on May 28, 2026 at 7:24 pm

    I haven’t used PSReference before but couldn’t you just do this:

    protected override void ProcessRecord() 
    { 
        //main method, this is executed when cmdlet is run 
        int r = Convert.ToInt32(this.Remainder.Value); 
        int q = _csharpDivideRemainderQuiotent(a,b, ref r);
        this.Remainder.Value = r;
        WriteObject(q); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code in a powershell function that looks like this: try {
This is the C# code. Can you help me translate this to powershell? private
I have a few lines of PowerShell code that I would like to use
I use this code to load a .Net assembly to PowerShell: [System.Reflection.Assembly]::Load(System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
Given this powershell code: $drivers = New-Object 'System.Collections.Generic.Dictionary[String,String]' $drivers.Add(nitrous,vx) $drivers.Add(directx,vd) $drivers.Add(openGL,vo) Is it possible
I've seen some code samples that allow to load specific PowerShell scripts from C#,
I wanted to create some clickable PowerShell scripts, and I found this answer that
What is the equivalent of this code in PowerShell? call opmnctl stopall >> %LOGFILE%
What is the equivalent of this code in PowerShell? @echo off SET PATH=%PATH%;D:\oracle\FRHome_1\dcm\bin\;D:\oracle\FRHome_1\opmn\BIN\;D:\oracle\FRHome_1 \opmn\BIN
This is my current PowerShell code: connect-QADService -service 'view.domain.com' -Credential 'MyDomain\Administrator' $AllVMs= ( get-QADObject

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.