powershell script object osobjectype variable

Azuretech 90 Reputation points
2023-03-01T15:42:13.24+00:00
I am trying to write a function.

  function Get-data {

        param (   

        [Parameter()]

        [PsCustomObject[]]$allvmdata,

        [Parameter()]

        [PsCustomObject[]]$jsondata

        )   

 

        ForEach ($vm in $allvmdata) 

        {}

}

    

$allvmdata is an csv file with multiple  rows.

group , name

rg1, vm1

rg2,vm2


Jsondata is .json file.

json format.

{
	"name": "",
	"subscriptions": 
	[

    "av",
	"cd",
	"dff"
	]

}

 Please let me know what should be the correct data type- as above is not giving the right results. if i a removing the datatypes ,it's working fine.

will the data type be otherthan   

PsCustomObject[]? or issue with syntax.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,416 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,175 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,186 Reputation points
    2023-03-01T16:15:23.83+00:00

    If you're providing the contents of the CSV as an array of line from a file, that's not going to work.

    Something like this would work:

    Get-Data -allvmdata (Import-CSV -Path ...) -jasondata ((Get-Content -Path ... -Raw)|ConvertFrom-Json)
    
    0 comments No comments