Solved

Using a variable to name output in powershell script

Posted on 2016-11-28
2
41 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 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Synchronize a new Active Directory domain with an existing Office 365 tenant
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 …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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…

820 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