Solved

format Variable in string in Powershell

Posted on 2011-09-02
3
519 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
  • 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. 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

Suggested Solutions

Title # Comments Views Activity
Powershell script; disk size 3 38
Powershell - SystemTray application 3 36
hiding bulk external contacts 2 32
Powershell Modification Requests 17 8
Synchronize a new Active Directory domain with an existing Office 365 tenant
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A short film showing how OnPage and Connectwise integration works.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

21 Experts available now in Live!

Get 1:1 Help Now