How do I test to see if a user has access on a site?

I am completely new to PowerShell, but I have a requirement to build a PowerShell script that will run against a site, a set of sites or a web application. How do I add a check within my script to test if a user has rights on the site they are running it
on or not? Am clueless on how to test if the user has rights to a site....I basically am trying to test, then let them know that they do not have access on a site or not. 
How can I get this done? Please help.

I now have this code which I think should do the trick, but I am getting an exception when i step through it. The $serverContext variable is always null. Does anyone know why I am getting this?
write-host "Please enter the url of the site collection"
$url = read-host
write-host "Please enter the username of the user"
$userName = read-host
$site = New-Object Microsoft.SharePoint.SPSite($url)
$serverContext = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$userProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serverContext)
$userProfile = $userProfileManager.GetUserProfile($userName)
$userLogin = $userProfile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value.ToString()
$webs = $site.AllWebs
foreach ($web in $webs)
$permissionInfo = $web.GetUserEffectivePermissionInfo($userLogin)
$roles = $permissionInfo.RoleAssignments
write-host "Now checking the permissions of the user " $userLogin " " "in the site " $web.Url
for ($i = 0; $i -lt $roles.Count; $i++)
$bRoles = $roles[$i].RoleDefinitionBindings
foreach ($roleDefinition in $bRoles)
if ($roles[$i].Member.ToString().Contains('\'))
write-host "The User " $userLogin " has direct permissions " $roleDefinition.Name
else
write-host "The User " $userLogin " has permissions " $roleDefinition.Name " given via " $roles[$i].Member.ToString()
Thanks for the help.
 

Similar Messages

  • Testing to see if a session has expired

    Hello all,
    I am trying to test to see if the user's session has expired by inserting the following code at the top of the page:
    HttpSession sess = request.getSession();
    if(sess.getAttribute("userId")=="null"){response.sendRedirect("logon.jsp");}The problem is that when the session expires and I refresh or go to the page with the above code, I get a null pointer exception and, of course , it wont redirect.
    Am I doing the comparison improperly?
    TIA!!

    I have changed my code somewhat but I still cant get the page to redirect.This is the first 20 lines of code:
    <%@page import="java.util.*,
              java.net.*,
              java.text.*,
              java.util.zip.*,
              java.io.*,
                    javax.servlet.http.*,sensorPac.methodClass"
    %>
    <%
    System.out.println("SESSION="+session.getAttribute("userId"));
    if(session.getAttribute("userId") == null){response.sendRedirect("logon.jsp");}%>When I look at the tomcat console window I get the following:
    When I first hit the page with a valid session I get:
    SESSION = fortegr
    When I refresh or revisit the page after a minute (session.setMaxInactiveInterval(1);)
    I get:
    SESSION=null
    Once again it will not redirect.
    Any ideas?
    TIA!

  • How do I check to see if my mac has spyware

    How do I check to see if my mac has spyware?

    Macs are not currently affected by Spyware, they have excellent security built into them. However there has been a recent Trojan attack. If you are running 10.6.7 run Software Update. I'd also recommend reading Viruses by Thomas Reed.

  • How to see, if some user has done multiple login at the same time

    Hi,
    i'm looking for a tcode to see, if some user has done multiple login in a date-range.
    Regards, Dieter

    It is also dependent on your license type, as it is populated at logon - prior to any Z-coding option - which will cause a lockout if attempted an access that way.
    I recently found a cool way to detect DB triggers and updates - very obscure...
    However I also "move around" during support in projects and don't always want to kick myself out. I guess SAP can "work-it-out" from the various fields of the table to map the user behaviour.
    Personally I dont believe that all of such information is appropriate for public domain, as all the SAP_ALLers out there combined with the types of authentication options are not always responsible with the information either.
    Thankfully, SAP has added a "salt" to the password hashes now. They offer RZ11 login/password_downwards_compatibility as a workaround...
    Take a look in your system!
    Cheers,
    Julius

  • How do you configure the iMac so separate users can access each other's files, especially iPhoto and iTunes? I need to be able to transfer media between two users and not just gain limited access using 'share'.

    How do you configure the iMac so separate users can access each other's files, especially iPhoto and iTunes? I need to be able to transfer media between two users and not just gain limited access using 'share'.

    See Terence Devlin's thorough explanation here.

  • See if a user has a record open

    Hi all,
    We have been caught out by two users editting the same form (BP/Quote etc) and of course losing the actions of one user as it isn't until they ty and update the form that they are told that it cannot be done due to another user.
    Is it possible to see if a user has opened the form or has it in edit mode - at which ever point SAP locks the record so it can't be updated by anothe user?
    We don't mind if its just a query that updates a search define that updates a UDF, as long as we can see that the record is open already - or is there an easy way we are not aware of?
    Any help is much appreciated.
    Kind Regards,
    Matthew

    Matthew,
    I understand that this can be frustrating at times but the whole purpose of a multi-user environment is the possiblity for multiple users to use the system at the same time.  Transaction are no different as there could be different departments accessing the same transaction but it is the way SQL works that two people cannot edit the same transaction.
    The first user who updates the transaction change the current values and the data on the screen of other user has already changed and thats why you get the message " Another user modified table ..."
    Unfortunately there is nothing you could do about it for now.
    Regards
    Suda

  • How can I check if an user has access to an url within my web app?

    Hi,
    I have a web application where I allow the users to set their startup page by presenting them a list of startup pages. However, some startup pages can accessed only by certain users, so I want to present the user only those pages the user has access to.
    How can I do this with weblogic?
    One way is to read the web.xml file and determine the roles that have access to the page, then check whether the user has any of those roles.
    Is there a better way eventually using some weblogic api?
    Thanks

    Just for the record, I decided to parse the web.xml file and to simulate whatever the container does.

  • How do I get a list of the reports that a user has access to?

    <p>I need to be able to determine which reports a specified user has access to.  This is for an application where users will be able to search and view reports that have been archived through a separate process.  </p><p>I&#39;ve searched through the developer library, but I can&#39;t find this specific information.  Can I use the ObjectPrinicpals class to get this info?</p><p>Thanks!</p><p>-Dell<br /></p>

    Hi Robert!
    Yes, the presentation went well. It was a lot of fun to do and I had a great time at the conference.
    Your suggestion works great if I'm walking down through the reports looking to see who has access to them.Â
    However, I need to do this starting from the User object. When I use the ObjectPrincipals of the User, I get a list of the users who have the rights to modify the user. I did a lot of work on this last week and it boils down to I'm going to have to actually log in as the user (I can use trusted authentication to do this without having the user's password) and then run a query to select all of the reports in the system - this should give me just the reports that the user has access to. Not the most efficient way to get the data from my perspective, but it should work.
    This would be a great feature to have added to future versions of the SDK. I need it for a couple of purposes:
    1. To gather information to set up the security in my archive viewer application.
    2. For auditing purposes - we currently have only Professional licenses so I don't have access to the internal auditing functionality. Plus, I'm not sure that that includes the kind of info I'm looking for so I'm building an app that extracts information to XML which is then used by a couple of reports so that I can provide the audit info as needed.
    -Dell
    Â - A computer only does what you told it to, not what you thought you told it to!</p>

  • Please,I want to stop users from visiting particular wensites while connected to the internet. How do I configure Firefox to automatically stop users from visiting such dangerous sites?

    Please,I want to stop users from visiting particular wensites while connected to the internet. How do I configure Firefox to automatically stop users from visiting such dangerous sites?

    Thanks, Ronda! I haven't been able to try your suggestion because I fried my router! So I need to get a new wireless router before proceeding.
    (I may start a new thread about getting a new router, but I will look for answers first to my questions and only start one if I cannot find answers.)
    After I get a new router, I will try what you suggested and report back here.

  • Is there some way to test to see if my computer has been hacked?

    Can someone tell me how I can test my computer to determine if it has or is being hacked?
    Thanks

    lindafromwhittier wrote:
    Dave
    ...what is filevault?  And now that you know the firewall was off, does that mean it could have been hacked?
    Not Dave, but I'll try to give you some answers.
    In System Preferences->Security click on the "?" in the lower left hand corner to learn how to make your computer more secure.  When you finish doing that type "About FileVault" in the search box in the upper left corner of Mac Help to learn what filevault is.  It has been known to cause issues with backups and if you forget your password there is no way to recover the information in your home folder.  They have revamped this capabiltiy in Lion (FileVault 2) to improve it, but I don't think users have had much of a chance to check it out to see how capable it is.  Since I don't use it I hesitate to comment.
    It's slightly more probable that you have been hacked with the firewall off through remote access, but now much. 
    Since I already paid for MacKeeper- thinking it was an Apple product, and seeing what is known about their ethics - which does matter to me, can I really get rid of it, thoroughly?
    MacKeeper support says that you can completely remove it by dragging it to the trash and answering a question about why you don't want it.  After you do that, the uninstaller is supposed to remove everything.  Users have found that their keychain still contained passwords for mackeeper or zeobit which shouldn't cause any problems.  A user the other day said they searched their hard drive and found three left over files, but I don't think they ran the uninstaller.  Depending on what features you activate you may have to Log out or restart your computer to completely stop the processes running in the background, but the uninstaller should have taken care of that, as well.
    If you decide to uninstall it and want a list of the known places to look for files let me know and I'll provide you with the list I have.

  • How can I check to see if my software has been registered?

    After a recent hardware replacement I am unable to find my Aperture 2 download. I never used it anyway so i'm not concerned but would like to be able to pass it on if it can be, is this possible? How can I check to see if I even registered it? I have the original packaging and all contents including Serial numbers, support ID, and four software coupons for updates. I am a bit technophobe, sorry!
    So,
    1. How can I check to see if it was registered correctly?
    2. Can someone else use the software?
    Hope someone can help.

    You don't need to check registration. In the Apple world registering software really doesn't have much of a purpose.
    If the software was bought on DVD and you have the serial number you are free to give it or sell it to anyone you wish.  Just keep in mind that Aperture 2 is very old and while it (sort of) works on the newer OS's it really isn;t a good solution for anyone serious about using Aperture. 
    It would be OK for someone with older hardware that is unable to upgrade past Snow Leopard but for anyone with newer hardware it would be a mistake to use.

  • How do I test a website with multiple users?

    Hello,
    I want to test a website with multiple users. Is there a testing tool that can simulate
    multiple users?
    I have already written some HTTPUnit tests and it would be cool to use these tests in
    a "multiple user test". Is there any way to reuse the HTTPUnit tests in a "multiple user
    test"?

    Take a look at JMeter "http://jakarta.apache.org/jmeter"
    And if your web app uses session variables.....use "BadBoy"
    http://www.badboy.com.au/

  • How to calculate the number of times an user has accesed a BEx report

    Hi Experts,
    We have number of reports in our BW portal and users logon to the portal and run the reports.
    How do we count the number of times each user has logged in and ran each report.
    Kindly advice.
    Thanks,
    Sai

    Hi Sai:
    I think you can use BI statistics information, which could provide you more detail information.
    You can follow the document
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/90080703-4331-2a10-cd98-9c1e95acdea0
    Regards,
    Louis Lu

  • How can I detect in javascript if a user has set "raise or lower windows" javascript option off?

    I am working on an application and include a feature that allows users to hide a window by calling the javascript "focus" method. However, this does not work in Firefox when the user has the "raise or lower windows" setting turned off. Not a big deal, but it seems as if there is no way to detect this via javascript so I can gracefully handle the situation for my users (e.g. send them a message that their browser will not allow that to occur).

    A good place to ask advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.<br />
    The helpers at that forum are more knowledgeable about web development issues.<br />
    You need to register at the mozillaZine forum site in order to post at that forum.<br />
    See http://forums.mozillazine.org/viewforum.php?f=25

  • How to check if a user has access to a responsibility

    Hi,
    I have a user_id in the controller. How do I know if this user has a particular responsibility added to him or not. I guess there a specific proflle call which gives this information. Can you give me that information.
    Thanks,
    HC

    Create a vo with the following SQL passing userid as bind value:
    SELECT C.USER_NAME,
    B.RESPONSIBILITY_NAME,
    A.START_DATE,
    A.END_DATE
    FROM APPS.FND_USER_RESP_GROUPS_DIRECT A,
    APPS.FND_RESPONSIBILITY_TL B,
    APPS.FND_USER C
    WHERE C.USER_ID = A.USER_ID
    AND C.USER_NAME= :1
    AND B.RESPONSIBILITY_ID = A.RESPONSIBILITY_ID
    You will have the list of all the responsibilities of a user.
    Kristofer

Maybe you are looking for

  • Opening a Tab or Comma Sep Doc in Pages 9 vs. Pages 10

    I just had an interesting, and frustrating, experience.  Using FilemakerPro, I Exported a file, with the goal of Opening that file in Pages.  I used Filemaker to Sort a large document, numerically and alphabetically.  My goal was to Open or Import th

  • Oracle support

    HI guys , i have bug in my system oracle 11g.2.2 ASM RAC under OL 5.6 2 nodes the bug is appear in FEB and then after 2 days is disappear so i open a ticket in MOS just to make sure this bug is not happen again and if happen again in one node or both

  • How to support tracking changes in pages

    How to track changes in pages?

  • Shop floor rfid

    Hi experts, My company has decided to go for implementation of rfid on shopfloor.Please help me out on these points 1) why implement rfid on shopfloor? 2) benifits 3) how do we implement this scenario? Thanks in advance Regards, Abhinay

  • Filtering by Entry Point

    At customer side there is a portal implemention which uses filtering by entry point functionality. Now i've upgraded the system from 7.0 SPS18 to 7.01 SP08 and the filtering by entrypoints function is not working any longer. I've checked everything a