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.

Similar Messages

  • Executing a powershell script for checking duplicate users while creating a AD user throug ADUC console.

    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 k

    Run 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

  • Looking for Help with Active Directory Script to Remove a User from msExchDelegateListLink

    I'm struggling to put together an Active Directory Powershell script that will remove a specific user from the msExchDelegateListLink.
    It looks like Set-AdUser would do the trick. I would want to remove a user in the format of
    {CN=Wood\, Sandy,OU=Networking,OU=IT,DC=my,DC=domain,DC=com}
    Has anyone succeeded in doing this before?
    Orange County District Attorney

    I use this:
    $user = '<user name>'
    $userDN = Get-ADUser $user | select -ExpandProperty DistinguishedName
    $delegates = Get-ADUser $user -Properties msExchDelegateListBL |
    select -ExpandProperty msExchDelegateListBL
    foreach ($delegate in $delegates)
    Set-ADUser $delegate -Remove @{msExchDelegateListLink = "$UserDN"}
    Never quite got around to putting it into a function.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Vb scripts to remove the user from the member of perticular group (say from domain admin) from windows servers 2003 and 2008

    Hi,
    I need VB script which to checks the perticular user in AD and if it exists;that user needs to be removed from the member of perticular group
    Ex:- Lets say
    I have a user 783562 , I need to search this user in AD to verify user exists or not. If not then I no need to remove the mebership from perticular group
    Second scenario:-
    If user exists then I need to remove the user membership from the perticular group.I want to do it in automation
    Manual Path:-
    1.Type dsa.msc in run command of IT session(we using it to connect remote desktop).
    2. Select the domain & right click (EX:-corp.ds.xxyyzz.com) and select "Find" to find the user form the domain.
    3. Type the user name in the Name field and click on "Find Now" button user name will be displayed in search result.
    4. Double click on this user ID and select "Member Of" tab.
    5. Select any member of group from the Name section then click on "Remove" button.
    6. Finally click on "Apply" and "OK" button.
    Kindly help me out to do this by using vb script.
    Thanks
    Raja

    Usage: CScript NameOfVBS.vbs //NOLOGO /User:Jane.Doe /GroupDN:CN=Group1,DC=Contoso,DC=com
    Option Explicit
    On Error Resume Next
    Dim str_User
    Dim str_GroupDN
    Dim obj_Connection
    Dim obj_Command
    Dim obj_RootDSE
    Dim str_DNSDomain
    Dim str_Base
    Dim str_Filter
    Dim str_Attributes
    Dim str_Query
    Dim obj_RecordSet
    Dim obj_Group
    Dim str_ADsPath
    Dim obj_User
    str_User = WScript.Arguments.Named("User")
    str_GroupDN = WScript.Arguments.Named("GroupDN")
    If Len(Trim(str_User)) > 0 And Len(Trim(str_GroupDN)) > 0 Then
    Set obj_Connection = CreateObject("ADODB.Connection")
    Set obj_Command = CreateObject("ADODB.Command")
    obj_Connection.Provider = "ADsDSOOBject"
    obj_Connection.Open "Active Directory Provider"
    Set obj_Command.ActiveConnection = obj_Connection
    Set obj_RootDSE = GetObject("LDAP://RootDSE")
    str_DNSDomain = obj_RootDSE.Get("defaultNamingContext")
    str_Base = "<LDAP://" & str_DNSDomain & ">"
    str_Filter = "(&(objectCategory=person)(sAMAccountName=" & str_User & "))"
    str_Attributes = "cn,ADsPath"
    str_Query = str_Base & ";" & str_Filter & ";" & str_Attributes & ";subtree"
    obj_Command.CommandText = str_Query
    obj_Command.Properties("Page Size") = 1000
    obj_Command.Properties("Timeout") = 1
    obj_Command.Properties("Cache Results") = False
    Set obj_RecordSet = obj_Command.Execute
    obj_RecordSet.MoveFirst
    If obj_RecordSet.RecordCount = 0 Then
    WScript.Echo str_User & " was not found"
    Else
    Set obj_Group = GetObject("LDAP://" & str_GroupDN)
    str_ADsPath = obj_RecordSet.Fields("ADsPath")
    Set obj_User = GetObject(str_ADsPath)
    obj_Group.Remove(obj_User.AdsPath)
    If Err.Number = 0 Then
    WScript.Echo str_User & " was removed from group " & str_GroupDN
    ElseIf Err.Number = -2147016651 Then
    WScript.Echo str_User & " not a member of group " & str_GroupDN
    Else
    WScript.Echo str_User & " error removing from group " & str_GroupDN
    End If
    End If
    End If

  • Help with script for "Import AD users from CSV with checks first"

    Hi everyone.
    Can anyone tell me if i am on the right track here?
    I want to be able to provide a CSV with users and import into a new AD domain/forest. But i know there already are some AD accounts so i need to run some checks. For now i am checking only on Name and Email.
    The issue i have is is with "write-host "$UserFullName was not found. Creating user.". It outputs this 19 times which is the same amount of times as there are users in AD in this OU.
    Not sure if my method is right. 
    $allImportedUsers=@()
    $allUsersArray=@()
    $searchbase="OU=PL,DC=EUECS,DC=CORP,DC=ARROW,DC=COM"
    $path = "OU=Users,OU=PL,DC=EUECS,DC=CORP,DC=ARROW,DC=COM"
    $allImportedUsers = Import-CSV polandusers_edited.csv
    $allUsersArray = Get-ADObject -LDAPFilter "objectClass=User" -SearchBase $searchbase -Properties * | select *
    $allImportedUsers | ForEach-Object {
    $Firstname = $_.givenname
    $Lastname = $_.surname
    $UserMail = $_.EmailAddress
    $UserFullName = $Firstname+" "+$Lastname
    $importUserSAM = $_.Samaccountname
    $allUsersArray | ForEach-Object {
    $currUserFirstname = $_.givenName
    $currUserLastname = $_.sn
    $currUserMail = $_.mail
    $currUserFullName = $_.name
    $currUserSAM = $_.samaccountname
    $currUserDN = $_.DistinguishedName
    if($currUserFullName -eq $UserFullName) {
    write-host "CSV $UserFullName matched on name"
    $userMatched=1
    if($currUserMail -eq $UserMail -AND $userMatched -ne 1) {
    write-host "CSV $UserFullName matched on email"
    $userMatched=1
    if($userMatched -ne 1) {
    write-host "$UserFullName was not found. Creating user."
    $userMatched=0
    If only i had a cool signature!! ;)

    Move below to outside the inner for-each loop:
    if($userMatched -ne 1) {
    write-host "$UserFullName was not found. Creating user."
    $userMatched=0
    so the bottom should look like
    }if($userMatched -ne 1) {
    write-host "$UserFullName was not found. Creating user."
    $userMatched=0

  • Can't Remove some users from proxy list

    There are 3 users who keep being added to my proxy list, and when i go to remove the from from file -> proxy, i select their names and click remove. They are removed from the box and then i hit ok. But when i go back to my proxy list they are still there and the removing didn't work.
    Please help.

    Originally Posted by laurabuckley
    Hi,
    I suggest running a standalone GWCheck on your user.db with the misc. option of proxyfix.
    Let us know how that goes.
    Cheers,
    This worked!
    Thank you so much

  • Remove a User from Catalog

    can anyone provide some sample code for removing a user from the BI Beans catalog?
    thanks
    Julian

    Users are maintained using PL/SQL scripts in the JDEV_HOME/bibeans/bin. There are two scripts
    REMOVEUSER.SQL
    REMOVEGROUP.SQL
    Business Intelligence Beans Product Management Team
    Oracle Corporation

  • Need help with a script for moving bulk users to another OU and removing/assigning groups

    I've never used PowerShell before and have been asked to track down a script that can move bulk users from one OU to another, and remove and assign new group membership. I've been googling it for about 30 minutes and haven't really gotten anywhere. If
    somebody can point me in the right direction or give some tips I'd greatly appreciate it. I'm sure this kind of task has been done by several people in similar environments I just haven't been able to find those people/examples. 

    Here's what I've got so far...
    Moving to new OU
    CSV constructed like below...
    DN  
                                                                                                                                                    TargetOU
    “CN=John R, OU=BB,OU=ES,OU=Students,OU=OSD,DC=usd233,=DC=local”
                          "OU=PRT,OU=MS,OU=Students,OU=OSD,DC=usd233,DC=local"
    Import-Module activedirectory
    $UserList = Import-Csv "c:\yourCSVhere.csv"
    foreach ($User in $UserList) {
    $User.DN
    $User.TargetOU
    Move-ADObject -Identity $User.DN -TargetPath $User.TargetOU
    Would this work? I also need to remove the user from two groups and add them to two different groups as well. Would I need to use the addUsertoGroups and removeUserfromGroups commands?

  • 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 kumararatne

    Hi 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

  • Trouble removing a user from creative cloud for teams

    I am trying to remove a user from my team, however the X does not show the pop up menu with the option to remove them.  Also, when I click on any item on the left hand menu, nothing happens.

    Sorry... This is an open forum, not Adobe support... You need Adobe support to cancel a subscription
    -start here https://forums.adobe.com/thread/1703848
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html
    --and two links which may provide more details, if the above links don't help you
    -http://helpx.adobe.com/x-productkb/policy-pricing/return-cancel-or-change-order.html
    -http://helpx.adobe.com/x-productkb/policy-pricing/cancel-membership-subscription.html

  • I want to remove some photos from my account without losing them to make room for others.

    I want to remove some photos from my account and  save them to my computer. How do I do that?

    Please see:  FAQ: How Do I Download files from Revel?

  • 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.

  • Remove SP User from SharePoint subsite

    Hello All,
    I am trying to remove a user account form all sub sites except few.
    I am making use of following command.
    Remove-SPUser "Contoso\jdoe" -web http://webapp/sites/site1/web1/
     But this command is removing the user from all the sub sites including the site collection.
    Can anybody please help to delete the user from specific subsite only.
    Thanks & Regards
    MD Liakath Ali
    MD.Liakath ali

    Hi,
    You can try to delete user from specific SharePoint group at sub site level using Power shell script as below .
    #Remove
    user from SP Group
        $theGroup.RemoveUser($theUser);
    Fine
    more details on below blog
    http://markimarta.com/sharepoint/add-remove-user-to-sharepoint-groups-with-powershell/
    Regards
    Soni
    K

  • How can I remove some themes from Keynote??

    How can I remove some themes from Keynote??

    What a co-incidence... I just deleted those same goodies. They were in /Library/Application Support/Keynote-folder on my machine. I just deleted the whole folder, cause there seemed to be nothing more but those downloaded files. And Keynote worked great afterwards. There seemed to be another folder for iWork09, which is not to be removed.

  • Shared Services 11.1.2 Unable to remove assigned user from a security group

    In Shared Services 11.1.2 - trying to remove a user from the assigned users list of a security group. Initially, I am able to remove the user and the assigned users total decreases by one - but when I relaunch the group properties - this user is still in there? The change does not hold. Any suggestions would be appreciated - thanks,
    Paul

    Hello Paul,
    Not sure if this is related to yours, but it might be worth having a look at the following articles on Oracle support --
    External users in EPM Shared Services (e.g. MSAD users) cannot be removed from Native groups if they have multiple IDs in the external user directory. [ID 1526569.1]
    Users from External User Directories Cannot be Removed from Native Groups [ID 1272309.1]
    Thanks,
    hyperionEPM
    Please mark answers as correct or helpful for others to find them easily.

Maybe you are looking for

  • Display name not getting generated When creating user thorugh GTC

    We are using GTC flat file as a trusted source. We see that display name not getting generated. And same thing happening when creating a new GTC mapping. previously when we ran with few test user got created with display name through GTC flat file ,

  • Problem in delta for material master

    Hi all, We are using "0material_attr" as data source.Till now we were loading data for material using full update mode. Now we want to change the update mode from delta update mode. So we initialized update for material in BW using " initialize witho

  • Can't import RAW files in Elements 9

    I get a message saying "Nothing was imported. The files or folders selected to import did not contain any supported file types, or the files are already in the Catalog." And below that it has Reason: "The file is damaged or it is a format that cannot

  • MRP Run to Monitor Subcontracting/Service Provider Stocks

    Hi, As per the businee requirement, we want to run the MRP based on the ROL / Max stock level for the Individual component of a BOM (Child items) and for each subcontractor we need to monitor the stocks (special stocks), i.e., whenever the vendor sto

  • GetString issue

    Hi, We are experiencing some strange behaviour with the JDBC getString method on Jdeveloper 10g (I'll also post in the Jdeveloper forum). getString is returning the hex representation of the string when it is executing in the OC4J container, but retu