Solved

Using a variable to name output in powershell script

Posted on 2016-11-28
2
14 Views
Last Modified: 2016-11-28
I have a script that for what I am doing works fine. I wanted to make it a little more useful and added an import, and 'for each' section.
it outputs to CSV. The name of the file is getting a bunch of extra characters.
import-CSV C:\scripts\get-folder-permissions\servers.csv |
foreach-object {./get-perms.ps1 -ComputerName $_.name  | Export-Csv -Path "D:\$_.name-Permission.csv" -NoTypeInformation
}

Open in new window

the called dscript get-perms, works just fine. I get a file where I want it, with the data I want, but the name is
@{name=servername01}.name-Permission.csv.
Is this an easy fix?
0
Comment
Question by:SquigglyMonkey
2 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
In a string, you just need to use a subexpression to reference the object property.
"D:\$($_.name)-Permission.csv"

Open in new window

0
 
LVL 1

Author Closing Comment

by:SquigglyMonkey
Comment Utility
Perfect!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now