Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 62
  • Last Modified:

Using a variable to name output in powershell script

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
SquigglyMonkey
Asked:
SquigglyMonkey
1 Solution
 
footechCommented:
In a string, you just need to use a subexpression to reference the object property.
"D:\$($_.name)-Permission.csv"

Open in new window

0
 
SquigglyMonkeyAuthor Commented:
Perfect!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now