Solved

Using a variable to name output in powershell script

Posted on 2016-11-28
2
29 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
ID: 41904970
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
ID: 41905034
Perfect!!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

20 Experts available now in Live!

Get 1:1 Help Now