PowerShell script for AD name change
I need to change all users logon name in AD to their first name.last name Server 2003
Here is my suggestion of a PowerShell V1 script to rename all users (sAMAccountName):
# Filter on all users that have givenName and sn assigned.
$searcher=[adsisearcher]'(&(objectCategory=person)(objectClass=user)(givenName=*)(sn=*))'
[void]$searcher.PropertiesToLoad.Add('distinguishedName')
[void]$searcher.PropertiesToLoad.Add('sAMAccountName')
[void]$searcher.PropertiesToLoad.Add('givenName')
[void]$searcher.PropertiesToLoad.Add('sn')
$searcher.PageSize
= 200
$Results =
$searcher.FindAll()
ForEach ($Result
In $Results)
# Retrieve values.
$DN
= $Result.Properties.Item("distinguishedName")
$NTName
= $Result.Properties.Item("sAMAccountName")
$First
= $Result.Properties.Item("givenName")
$Last
= $Result.Properties.Item("sn")
# Construct desired "pre-Windows 2000 logon" name.
$NewName
= "$First.Last"
# Make sure new name 20 characters or less.
If ($NewName.Length
-gt 20)
# I don't know how to trim $First in PowerShell to make $NewName 20 characters.
# Check if name should be updated (case insensitive).
If ($NTName
-ine $NewName)
# Trap possible error.
Trap
"Unable to rename user $DN to $NewName"
"Error description: $_"
Continue
# Bind to user object in AD.
$User
= [ADSI]"LDAP://$DN"
# Assign new name.
$User.sAMAccountName
= $NewName
# Save the change to AD.
$User.SetInfo()
Test first, by commenting out the SetInfo() statement and echo $DN and $NewName for all users. Note that the script could trim $First to limit $First.$Last to 20 characters, but I could not find a way to do this. Also, this script does nothing to prevent
duplicate sAMAccountName values, but the possible error will echo to the screen.
Richard Mueller - MVP Directory Services
Similar Messages
-
Using Echo Command in PowerShell Script for Configuration Item
Hello All,
Before you tell me to post my PowerShell question to the PowerShell Forum, please know that the PowerShell portion of my task works just fine. It is the SCCM portion of my task that keeps failing, so that is why I am here. To give some background...
There are two servers in our SCCM test environment. Both the SCCM server and SQL DB server are 2012, patched and updated.
Test servers in my Device Collection being used for running Baselines and Reports against are 2008R2 and 2012, patched and updated.
I have created a Configuration Item that checks to see if the FTP Server Role Feature has been installed on a 2008 or 2012 server. To do the check, I am using the following PowerShell script:
(get-windowsfeature -Name Web-Ftp-Server).Installed
When I log into my 2008R2 and 2012 test servers, and run this command directly on the server, it will return a "True" if the FTP Server Role Feature is installed on either server, and a "False" if it is not installed. Basically,
it works as advertised.
When I setup my Configuration Item and then deploy my Baseline, or run a report against my device collection of test servers, SCCM will return a correct response (True or False) for the 2012 test server, but throws the following error for the 2008R2
server:
0x87df00329 application requirement evaluation or detection failed
Google searches for this have not been very helpful.
Now, when I created the Configuration Item and referenced PowerShell, the configuration screen has the following note:
"Specify the script to find and return the value to be assessed for compliance on client devices. Use the echo command to return the script value to Configuration Manager."
Since I did not include an echo command in my PowerShell script above, I figured that was my problem, so I did the following:
Logging onto both of my test servers (2008R2 & 2012) I was able to successfully run the following PowerShell commands and get the expected responses of True or False:
(get-windowsfeature -Name Web-Ftp-Server).Installed | echo
(get-windowsfeature -Name Web-Ftp-Server).Installed | write-output (http://technet.microsoft.com/en-us/library/hh849921.aspx)
(get-windowsfeature -Name Web-Ftp-Server).Installed | write-host (http://technet.microsoft.com/en-us/library/ee177031.aspx)
However, when I use any of these PowerShell commands in my Configuration Item, NEITHER of my test servers returns a response to the SCCM server.
When I check the report, both servers show as "Unknown" and when I click on the number 2 (as in 2 servers unknown), the following report page (List of unknown assets for a configuration baseline) has absolutely no data/information at all.
So...I am at a loss.
SCCM tells me to use an echo command to return a script value to Configuration Manager. The PowerShell scripts above, with the various echo related commands, work just fine on the servers themselves, but they return no information when run via SCCM.
What am I missing?
Any help will be appreciated.
Thanks in advance for your time.Sorry for my ignorance, but I don't understand. (I forgot to mention that I am new at both PowerShell and SCCM.)
After I change the PowerShell script to add the echo/write-output/write-host cmdlet, I open the ConFig Item and "Clear" the PowerShell script and then re-add it. When I do that, it correctly shows the change in the ConFig Item.
Next I open the Baseline, then open the ConFig Item within the Baseline to make sure the change is reflected there as well, which it is.
I then deploy the Baseline to my Device Collection. After that, I run a report against the Baseline and Device Collection and it returns the "Unknown" result.
If I open the PowerShell script and remove the echo/write-output/write-host cmdlet, then go through the rest of the process of updating and reporting, the result it returns changes, showing one server in compliance and the other server out of compliance,
which leads me to think that all changes have taken correctly.
Does that sound right? If I manually deploy the Baseline, is that the same as the client retrieving policies from the management point?
Sorry to be so thick but I'm learning as I go.
Thanks again for your help. -
Powershell script for security groups and users for multiple share folders
Hi scripting team,
I need your help with powershell script for the below queries
1. List out the security groups for more than one server share path and output it to a file ( csv )
For eg.
If the are are two share paths
\\servername\foldermain\folder1
\\servername\foldermain\folder2
So I needs the list of security groups for each share path
And the output needs to be under each any every path.
2. Grab the users belongs to main security groups and it nested groups for more than one security group and listed the users under each and every group. No need to display nested groups. Just users belongs to main group and users under nested.
Your teams help is much appreciated
Thank you.
Thilochana kumararatneHi Braham,
Thanks for your quick reply.
Are we able to do this on two stage method
1. grab the security groups from the share paths
if can grab the share path from a separate txt file than copying it to the <your path> location
so i can modify the txt file
once run the script
if can the output like below to a CSV file
\\servername\foldermain\folder1group 1group 2group 3\\servername\foldermain\folder2group 1group 2group 3then i know which groups belongs to which share paththen i can remove the duplicate groups and keep the common groups to grab the users belongs to itso with the second script same as the first copy the security groups to a txt file and the out put as below.what I needs is the users full name and the samaccount name ( user id )group 1user1user2user3
group 2user1user2user3looking forward your help on thisThank you.Thilo -
Hi,
I have a text file in which some SamAccountNames are present.I need to check the file while creating a new users through ADUC console.If a username that is going to create through ADUC console is present in the file, then it should prompt a message
that the user is already present in the text file.
Is there any possibility of contacting the powershell script from the ADUC console.If so, then while creating a new user through ADUC console, what is the proceedure for executing that powershell script.
please provide me the approriate solutions.
Thanks
Prasanthi kRun the below Powershell Script for users are exist or not in AD. Later you can create the users.
#Find Users exist in AD or Not?
#Biswajit Biswas
$users = get-content c:\users.txt
foreach ($user in $users) {
$User = Get-ADUser -Filter {(samaccountname -eq $user)}
If ($user -eq $Null) {"User does not exist in AD ($user)" }
Else {"User found in AD ($user)"}
Active Directory Users attributes-Powershell
http://gallery.technet.microsoft.com/scriptcenter/Getting-Users-ALL-7417b71d
Regards~Biswajit
Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights.
MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, MCTS, Enterprise Admin
MY BLOG
Domain Controllers inventory-Quest Powershell
Generate Report for Bulk Servers-LastBootUpTime,SerialNumber,InstallDate
Generate a Report for installed Hotfix for Bulk Servers -
Scripting a file name change as a data merge element.
My goal of the work being done with InDesign is to utilize the Data Merge functionality of InDesign and the, already available, ability to create a new document per record in your data source where the docuement name is changed based on data contained in the data source.
A very simple example of this would be the following:
EXAMPLE
======================
Given the following data source in excel:
First_Name
Last_Name
ResultingFileName
George
Smith
c:\A45.pdf
Mary
Lopez
c:\C99.pdf
Steve
Barns
c:\tmp\XM96TR.pdf
Along with a simple two text box InDesign documents, I would perform a standard data merge with First_Name linked to one text box and Last_Name linked to another. By setting the “Record Limits Per Document” to 1, I would end up with three different documents. By default, the documents would be named Untiltled-1, Untiltled-2 and Untitled-3.
Untitled-1 would contain George and Smith. Untitled-2 would contain Mary and Lopez and Untitled-3 would contain Steve and Barns.
At this point in time, I would run the new created script, which would do the following:
Rename Untitled-1 to A45 and/or save Untitled-1 as C:\A45.pdf
Rename Untitled-2 to C99 and/or save Untitled-2 as C:\C99.pdf
Rename Untitled-3 to XM96TR and/or save Untitled-3 as c:\tmp\XM96TR.pdf
I am open to modifying the manner in which the data merge source is created. For example, separating the path and the file name into separate columns. In addition, I am flexible in putting preset information and/or file save types into the data merge document.
Please feel free to contact me directly at [email protected]
Thanks in advance for the help.
MattHi Matt,
I think it’s better to use an XML-based approach for your task.
I’ve never scripted Data Merge process, but I don’t see a straightforward way of doing it. May be you can create the 3rd textbox on pasteboard or a non-printing layer, which will contain the file path from ‘ResultingFileName’ field, and the contents from which can be used for naming & saving the current file and exporting it to pdf-file. But this approach is so clumsy.
Instead, you’d better to keep your data in excel file, or even better Access or some other database program.
Export the data from it in XML-format.
Then import it to an InDesign file and process it by script. XML support is very powerful in InDesign: you can process your data by xml-rules. I once made a script for a newspaper, which processed data for classified ads. The script applied all formatting, changed colors for different headings and placed images.
Kasyan -
Cannot load script for the required change in butt...
I got the email saying Skype will be changed after 15 March. It says we need the new buttons. So I go the site, and then there is a big box which says: "cut and paste this" which is:
<script type="text/javascript" src="http://www.skypeassets.com/i/scom/js/skype-uri.js"></script>
<div id="SkypeButton_Call_[Removed for privacy]_1">
<script type="text/javascript">
Skype.ui({
"name": "call",
"element": "SkypeButton_Call_[Removed for privacy]_1",
"participants": ["[Removed for privacy]"],
"imageSize": 32
</script>
</div>
So where do I paste this script. Plus I get we need to do on our Ipads as well.Hi sheshu0022,
Based on my research, the issue can be occurred due to something get corrupted in the script task. To fix this issue, please copy the code in the task, then rebuild the script task with the same code to test again.
The following similar thread is for your reference:
http://stackoverflow.com/questions/15165760/ssis-script-task-fails-on-server-with-error-cannot-load-script-for-execution
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
can anyone pls point out whats the power shell script for "use this termset for site navigation" in the termstore management tool in my central admin';s manage serv appln-->managed metadata serv appln ->term styore mgmnt tool
i would like to check this "checked" through powershell script
help is appreciated!Hi,
To check if the term set has been set to be used for site navigation, we need to check the
NavigationTermSet.IsNavigationTermSet property for the term set.
Here is the code example for using PowerShell to get the setting:
$site=Get-SPSite "your site collection URL";
$session = Get-SPTaxonomySession -Site "your site collection URL ";
$termStore = $session.TermStores["Managed Metadata Service"];
$Group = $termStore.Groups[“Group Name”];
$TermSet = $Group.TermSets[“Term Set Name”];
$navTermSet = [Microsoft.SharePoint.Publishing.Navigation.NavigationTermSet]::GetAsResolvedByWeb($termset, $site.RootWeb, "GlobalNavigationTaxonomyProvider");
write-host $navTermSet.IsNavigationTermSet
Best regards.
Thanks
Victoria Xia
TechNet Community Support -
FIM Reporting ETLScript PowerShell Script for SCSM 2012?
Hi,
The FIM Reporting Deployment Guide is great, however on a few occasions it forgets to mention where you meant to execute things (http://technet.microsoft.com/en-us/library/jj133855(v=ws.10).aspx) .
For example, if it wasn't for the screenshot in the article, we would not have known that we need to run the ETLScript from the FIM Service/Portal server.
Everything until the ETLScript has thus far worked; and we have deployed the Service Manager 2012 console on the FIM Service/Portal server (since we are using SCSM 2012 for FIM Reporting).
However, it appears that the ETLScript (in the deployment guide) has been written for SCSM 2010.
So, has Microsoft or anyone published an updated SCSM 2012 ETLScript script?
Thanks,
SKCould this be it?
http://gallery.technet.microsoft.com/PowerShell-Script-to-Run-a4a2081c -
Powershell script for mailbox permissions
Hello,
Part of my tasks as an Exchange admin is to give access to shared mailboxes. The access usually are:
Send AS
Receive As
Send on Behalf Of
Full mailbox
Is there a powershell script out there that does all of the above?
thanks,
AlexisHi,
Probably not prewritten, but you can check the repository for starters:
http://gallery.technet.microsoft.com/scriptcenter
EDIT: I should mention - this isn't too hard to write, so this could be a good opportunity to learn how to get around in the EMS.
Don't retire TechNet! -
(Don't give up yet - 12,830+ strong and growing) -
Powershell script for deleting sitecollection and its content db
want to know whether any powershell script is avlble for deleting the sitecollection and its content db at oneshot!
i have created sitecollection specific content db and i wanna delete the same.Hi,
Below link will help to delete site collection
http://technet.microsoft.com/en-us/library/cc262392(v=office.15).aspx
Thanks
Somnath Matere -
Powershell script for removing some users from a particular Site Collection
Hi,
I am looking for a PowerShell script to delete a few users from a particular Site Collection. I am unable to delete them from/_catalogs/Users/simple.aspx page therefore need some other medium to
delete users from the site collection.
My ultimate aim is to have no user profile with "tp_deleted" field's value as 0 in the USERINFO table. Currently there are about 40 odd users with this field's value as 0 and this is affecting my crawling of this content database.Thanks for the reply Alex & eHaze,
I have a content source of root site which crawls all the site collections under it. Out of the 9 site collections, only 8 are getting crawled and 1 doesn't get crawled at all. The error in the crawl logs is
The SharePoint item being crawled returned an error when requesting data from the web service. ( Error from SharePoint site: Value does not fall within the expected range. )
I tried a lot of things, searched over the net and finally found
this which helped me solve the same issue in my development environment. I deleted these users from userInfo table and ran a full crawl. And the issue was fixed.
Now since I cannot delete the users from userInfo table directly from PROD environment, I used .../_catalogs/Users/simple.aspx list
to delete users from this site collection. While some of the users I could delete, quite a few I could not. Clicking on the profile redirected me to the home page rather than the info page of the profile.
This
is why I have to delete these users from the site collection.
Alex - the link you shared, I guess it is for a web application level.
eHaze - the script you shared throws this error:
Get-SPSite : Cannot find an SPSite object with Id or Url: http://dev-apps/divisions/BT. At C:\PowerShell Scripts\DeleteUserFromSiteCollection1.ps1:4 char:19
+ $site = get-spsite <<<< $siteURL
+ CategoryInfo : InvalidData: (Microsoft.Share...SPCmdletGetSite:
SPCmdletGetSite) [Get-SPSite], SPCmdletPipeBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetSite
You cannot call a method on a null-valued expression.
At C:\PowerShell Scripts\DeleteUserFromSiteCollection1.ps1:9 char:27
+ $site.SiteUsers.Remove <<<< ($LoginName)
+ CategoryInfo : InvalidOperation: (Remove:String) [], RuntimeExc
eption
+ FullyQualifiedErrorId : InvokeMethodOnNull
hope this info helps. -
SharePoint 2010 Powershell scripting for user profile
Please help to have a powershell script which will provide the details related to user profile service application like:
Number of user profiles:
Number of user properties
Number of Organization properties
Number of Organization profiles
Number of Audiences
Un compiled Audiences
Audience Compilation status
Last compilation time
Synchronization schedule
Santosh sethiHi,
If you're looking for prewritten scripts, you can check these two places:
http://gallery.technet.microsoft.com/scriptcenter
http://get-spscripts.com/
You should read this too:
http://social.technet.microsoft.com/Forums/scriptcenter/en-US/a0def745-4831-4de0-a040-63b63e7be7ae/posting-guidelines?forum=ITCG
Let us know if you have any specific questions.
Don't retire TechNet! -
(Don't give up yet - 12,830+ strong and growing) -
PowerShell Script For Finding Database Instance Names
G'day
I am trying to get information on a couple of dozen SQL database servers database instances - long story, but our DBA's do not have complete lists at the moment, and I need to find out this information.
I have done a bit of work with PowerShell (and love it) version 3, however I do not know many SQL commands and was wondering if someone could point me in the right direction please.
This is the code I have at the moment:
Get-Service -ComputerName MSQLULTDBS04 | ?{$_.DisplayName -like "*SQL*"} | Select name,DisplayName,status
It gets the information on the SQL Server install on the remote server.
What I am trying to do however is get a list of the databases that are running on this server. Can someone help me out please?Hello Scott,
Please have a look at TechNet ScriptCenter:
Create Inventory of SQL Server in Network as Html
It lists also all databases, but of course you need permissions to logon to that SQL Servers.
Olaf Helper
[ Blog] [ Xing] [ MVP] -
PowerShell Script for Setting the Welcome Page View of a document set
Hi,
We are using document set in the document library and we have created the separate view in the document set and it will show only particular metadata columns. We need to change from default view to another view. For this, we need to write the power shell
script and update the document set welcome page view link in the document set template. Please let me know how we can get this.
Thanks,
MylsamyHey Mylsamy,
welcome page view is stored in $contenttype.XmlDocuments. Here is how you can change the view using powershell:
$web = Get-SPWeb "WEBURL"
$list = $web.Lists["LISTNAME"]
$contenttype = $list.ContentTypes["CONTENTYPENAME"]
$viewid = $list.Views["VIEWNAME"].Id
$xmldocs = $contenttype.XmlDocuments
foreach($xmldoc in $xmldocs)
if($xmldoc.Contains("WelcomePageView"))
Write-Host "XML contains WPV"
$newview = [XML] @"
<wpv:WelcomePageView xmlns:wpv="http://schemas.microsoft.com/office/documentsets/welcomepageview" ViewId="$viewid" />
$xmldocs.Delete("http://schemas.microsoft.com/office/documentsets/welcomepageview")
$xmldocs.Add($newview)
break;
$contenttype.Update($updateChildren, $false)
Write-Host "Welcome Page View updated at " $list.Title
Regards,
Alexander -
Script for document name labels
How hard would this be?
A script that would type the file name into the document. I searched for similar threads but no luck. Here are the details...
1. If the document was named TEST.pdf the script would type TEST in the document.
2. The font color, size, and type would be Black, Arial Bold, 0.4 in.
3. The font would be converted to outlines.
4. A rectangle 0.05" larger than text would be placed around the text.
5. The rectangle would have no fill and a 100% magenta spot color named "CC" stroke.
6. The rectangle stroke would be moved to the CC layer (pre-existing layer).
7. The text "TEST" would be moved to the Artwork layer (pre-existing layer).
Thanks for any input or help.
AntonAnton, this should be pretty close for a guide… I don't know what your exact font name would be… so this uses my closest match. Also you don't mention text positioning on the artboard/doc… The stroke is default 1pt as is. The height of the outlined text would be dependent on your font and you may have to tinker with the size where shown…
#target illustrator
function docNameToText() {
if (app.documents.length = 0) {
return;
} else {
var docRef = app.activeDocument;
var docName = docRef.name;
var text = docName.replace(/\.(ai|eps|pdf)$/i,'');
var arialFont = app.textFonts.getByName('ArialMT-Bold'); // Add font name here…
var nameText = docRef.textFrames.add();
nameText.contents = text;
var nameChar = nameText.lines[0].characters;
for (var i = 0; i < nameChar.length; i++) {
nameChar[i].characterAttributes.textFont = arialFont;
nameChar[i].characterAttributes.size = 40; // Adjust font size here…
var textGroup = nameText.createOutline();
textGroup.position = [36,-36]; // Half Inch down/across from top/left
var groupBounds = textGroup.visibleBounds;
var ccLayer = docRef.layers.getByName('CC');
textGroup.move(ccLayer, ElementPlacement.INSIDE);
var artLayer = docRef.layers.getByName('Artwork');
// This can't be the right way to do this now can it?
var boxTop = groupBounds[1] + 4;
var boxLeft = groupBounds[0] - 4;
var boxWidth = (groupBounds[2] - groupBounds[0]) + 8;
var boxHeight = (-groupBounds[3] - -groupBounds[1]) + 8;
var spotBox = docRef.pathItems.rectangle(boxTop,boxLeft,boxWidth,boxHeight);
spotBox.filled = false;
spotBox.stroked = true;
//spotBox.strokeWidth = 1; // Default is 1pt
var ccSpot = docRef.swatches.getByName('CC');
spotBox.strokeColor = ccSpot.color;
textGroup.move(artLayer, ElementPlacement.INSIDE);
docNameToText();
Maybe you are looking for
-
Not able to open Windows Media Player files with Quicktime Pro
Hi, I have recently downloaded a couple of videos that I am planning to use in FCP. The file extension of the downloaded videos is .asf and I am able to play them with Windows Media Player. However, to use them in FCP I have to convert them into Quic
-
Music is not supported on this 2nd gen iPod
Why is it that half my daughter's music is not supported on this 2nd gen iPod shuffle? These songs worked fine for years and now are gone. They work on iPad, iPhone (2nd and 3rd gen), and iPod classic 2nd gen. I tried reformating to ACC version- no H
-
Ldif2db virtual memory error Directory Server enterprise 6
Hello, I installed directory server ee 6 on a Solaris 10 sparc machine, 8 gigs of ram. This is a testing environment. The installation, startup, and tools, like dcc/webconsole all work fine. I created a new DS instance. Next I copied a 5.2 instance f
-
Hi I have a problem... When I configure a new channel of type "diameter/diameters" I receive this error: The WebLogic Server did not start up properly. java.lang.NumberFormatException: 0.0.0.0 at java.lang.Integer.parseInt(Ljava/lang/String;I)I(
-
New JAAS Logon Module that calls RFC
I want to build a new logon module that extends AbstractLoginModule. I want to call an RFC in ECC using JCA in this logon module. The purpose of this RFC call is to read the users roles in the backend, if they have a certain role I will dynamically a