Solved

Using a variable to name output in powershell script

Posted on 2016-11-28
2
51 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

617 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