Avatar of ntr2def
ntr2def
 asked on

Name Export via Powershell not working as expected

I am trying to dump application data from Azure into their own file, however, when i reference the DisplayName attribute for the application to save as the file name I get a weird naming convention. The code below imports the csv with the DisplayName and Object ID. Attached is sample file as well

import-csv .\AzureApplications.csv | ForEach {Get-AzureADApplication -objectID $_.ObjectID |export-csv .\$_.DisplayName.csv}

Open in new window

The output file name is as follows:
@{DisplayName=Test Application; ObjectId=10f3cd35-bf7e-468d-bdbb-298fa456b3c5; AppId=440ba5b1-0372-4b62-9379-edf7096c8cb5}.DisplayName.csv
Any help would be appreciated
PowershellAzure

Avatar of undefined
Last Comment
Jose Gabriel Ortega Castro

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jose Gabriel Ortega Castro

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Qlemo

Jose is correct. But as here, it is not obvious that a parameter is a string, because PowerShell tries to do its best in "helping" you to use parameters and types:
If the filename expression starts with a bracket or dollar, it would first get evaluated as expression and return a string.
In other cases the "expression" is seen as a string, with inline string evaluation only - that is what you see.
In fact. it is much more complicated ;-). But in general you can assume that file name parameters are (implicit) strings. Get-Content, Import-*, Export-* are examples for that behaviour.
ntr2def

ASKER
Thank you Jose for the re-education. It has been over a year since I have done programmatic administration and as you were explaining my immediate reaction was "Duh!"
Jose Gabriel Ortega Castro

Yeah? haha, so much fun! :)
Read the @Qlemo comment and as well as @odba I respect them much, especially on the Powershell area, they're gods of it :)
And I'm glad to help
Your help has saved me hundreds of hours of internet surfing.
fblack61