Questions tagged [new-object]

`New-Object` cmdlet creates an instance object in powershell

Docs: MSDN: New-Object

Usage

$object = New-Object -TypeName PSObject -Property @{  ​
    'Name' = 'Susan'
    'Age' = 32
}

See also

26 questions
4
votes
1 answer

Loading .xls file with macros using PowerShell Core for Mac

I am trying to load an Excel file using PowerShell Core for Mac but I am encountering an issue with New-Object. It's failing on the very first line $Excel = New-Object -ComObject Excel.Application This is the error message I receive: New-Object :…
kevin02
  • 41
  • 2
2
votes
1 answer

Unexpected results when reusing a custom object for the pipeline

A while ago I changed my Join-Object cmdlet which appeared to cause a bug which didn’t reveal in any of my testing. The objective of the change was mainly code minimizing and trying to improve performance by preparing a custom PSObject and reusing…
iRon
  • 20,463
  • 10
  • 53
  • 79
1
vote
1 answer

PowerShell (New-Object) C# and Struct

I have been able to get the following code to work and would like to understand more about STRUCT and New-Object. If I move the STRUCT (MyRect) inside of the CLASS (MyClass), how would I reference it? Right now, it is as follow (outside of the…
1
vote
1 answer

Passing an Array Parameter Value

I have some code in PowerShell (below) to call the System.Guid constructor with a byte array (byte[]) as the only parameter. The C# equivalent of this code is: byte[] binaryData = userObj["ADGuid"].Value; Guid adid = new…
Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73
1
vote
1 answer

Powershell Runspace - New-Object not recognized

Given the following... Powershell script that implements a runspace pool A HashTable of named scriptblocks Scriptblocks that call New-Object to create SQL related objects (SMO, SqlClient, etc) My script iterates through a list of servers and adds…
1
vote
1 answer

Nested OrderedDictionary & Array data structure with New-Object

I have been developing a nested dictionary data structure to build a list of files to work with later in the code. Currently I am using this successfully to create the empty data structure. $manageLocalAssets = @{ resources = @{ …
Gordon
  • 6,257
  • 6
  • 36
  • 89
1
vote
0 answers

How to keep new Frame forming

I'm a beginner in JAVA. My Question is my GUI have one Button. If the Button is pressed it should print some texts on the GUI. But When I pressed the Button. It'll show a whole new Frame then show the texts. How can I do to keep it all in the same…
Rio Wu
  • 11
  • 2
0
votes
0 answers

how to fix an start bit transfer error in powershell?

I want to download a file with powershell and here is a part of script $downloadurl…
0
votes
1 answer

How can i use a for loop to create objects with params?

I try to create objects in a for loop like: String[] empArr[] = { {"Moe","Jude","Employee","2017"}, {"Noe","Joel","Employee","2019"}, {"Poe","Juce","Employee","2021"} }; Employee[] emp; emp = new Employee[empArr.length]; // get…
Big Sanch
  • 1
  • 1
0
votes
5 answers

How to create a function that omits key/value pairs from an object, and creates a new object with the remaining properties and values?

I've been working on creating an omit function with a source and keys parameter, that checks for keys within the source, and if they are found, those properties are omitted from the source, then create a new object literal with the remaining…
0
votes
1 answer

how to add Microsoft.WindowsAzure.Storage assembly in powershell script

Add-Type -Path c:\AzureStorageFile\Microsoft.WindowsAzure.Storage.dll $AzStorObject = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext Gives me error New-Object : A constructor was not found. Cannot find an…
0
votes
2 answers

Powershell change/edit value of Object in Variable

I create variables in a ForEach loop using data collected from a CSV file like this: New-Variable -Name $FlexVPN.'IP-adress' -Value (New-Object PSObject -Property @{ IP = $FlexVPN.'IP-adress' Information = $FlexVPN.'Information' …
0
votes
2 answers

Constructor function

What is the difference between these two codes? let user = new function() { this.name = "John"; this.isAdmin = false; } vs let user = { name: "John", isAdmin: false }
Vahid
  • 13
  • 5
0
votes
1 answer

How to create a td object jquery

I'm searching a way to create a td by object methode and not by creating a html element that tranform in object So I'm searching a way to make some thing like my_td = $('td'); my_td = new $('td'); Actualy when I do this all my td are modified by…
0
votes
1 answer

ModifiedProperties on a custom object?

Can it be done ? I want to mimic the behaviour of an ADObject on a custom object in a way that when you change a property it is listed in 'modifiedproperties' eg. $ADUser = Get-ADUser 'someSamAccountName' -Properties description $ADUser.Description…
1
2