Solved

format Variable in string in Powershell

Posted on 2011-09-02
3
526 Views
Last Modified: 2012-08-13
I am trying to create a script to remove specific users from groups.

The following works just fine:
$group.remove("WinNT://"+$env:COMPUTERNAME+"/Bad_User,user")

However I want to use a variable for the account name and I can't ge t it to work.  Something a long the line of:

$BU = "Bad_User"
$group.remove("WinNT://"+$env:COMPUTERNAME+"/"$BU",user")

Please,
How do I format this string, and what should i have googled to figure it out?
0
Comment
Question by:brittonv
[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
3 Comments
 
LVL 18

Expert Comment

by:x-men
ID: 36473562
$group.remove("WinNT://$env:COMPUTERNAME/$BU",user")

0
 
LVL 18

Accepted Solution

by:
x-men earned 250 total points
ID: 36473573
ups...

$group.remove("WinNT://$env:COMPUTERNAME/$BU,user")

0
 
LVL 16

Assisted Solution

by:Dale Harris
Dale Harris earned 250 total points
ID: 36474297
Google: formatting strings in powershell

Click on second link:
http://technet.microsoft.com/en-us/library/ee692790.aspx

HTH,

Dale Harris
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

635 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