Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell script pipeline only taking one record

$
0
0

This started off as a "why doesn't my pipepline input work, but I tested today and it kind of did work.  Previously it didn't read anything.  Now the PowerShell script pipeline only is only taking one of the records I put in the CSV file.  Strangely it is taking the last record.  I only tested with two records this time and the second was created.  Here is my code:

Param 
(
    [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [string]$SamAccountName,
    [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [string]$GivenName,
    [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
    [string]$Initials,
    [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [string]$SurName,
    [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [string]$EmployeeID,
    [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [string]$Title,
    [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [ValidateSet("BES","CES","EES","GES","NES","PES","WES","JHE","JHW","SHS","DEC","DIS","DSS","Substitutes","TEST")]
    [string]$Building,
    [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
    [Int]$Enabled = $true,

    [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
    [Int]$EnableMail = $true
)

 

CSV import file has headers that match the properties for AD Users with the exception of "EnableMail".  They are: SamAccountName, GivenName, Initials, SurName, EmployeeID, Title, Building, Enabled, EnableMail

 

Using the following command it works:

PS D:\PowerShell> import-csv .\User-New.csv | % { .\User-New.ps1 -sam $_.SamAccountName -g $_.GivenName -i $_.Initials -sur $_.SurName -emp $_.EmployeeID -t $_.Title -b $_.Building -Enabled $_.Enabled -EnableMail $_.EnableMail }

Using this command it takes only one record:

PS D:\PowerShell> Import-Csv .\User-New.csv | .\User-New.ps1

I do not have any sort of foreach in the code inside the file.  Any suggestions that would help fix things.  I know I didn't post much, but hopefully someone knows what is happening.


Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>