Hi team.
Am tying to check permissions issues on user folders . I am an admin and would like to run a script and check if i will be able to access a particlar users folder in the dfs. If i am denied permission ( meaning permissions on that particular folder are skewy), I would like to output that folder name into a text file, which i will then analyse and find out what the problem is at a later stage.
Please HELPPP!!!!!
Sam
Export unreachable folder names into a text file
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- SAPIEN Support Forums
- Posts: 945
- Last visit: Thu Oct 22, 2015 1:10 pm
Export unreachable folder names into a text file
This is an automated post. A real person will respond soon.
Thank you for posting, Sam.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
Anticipate follow-up questions!
Did you remember to include the following?
*** Make sure you do not post any licensing information ***
Thank you for posting, Sam.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
- - Scripting question? For questions about Windows PowerShell or other scripting languages, use Scripting Answers.
- Software question? For questions about PowerShell Studio, PrimalScript, or other SAPIEN products, use Product Support Forums for Registered Customers.
- Trial question? For questions about trial versions of any SAPIEN product, use Trial Software Questions.
Anticipate follow-up questions!
Did you remember to include the following?
- 1. Product, version and build
2. 32 or 64 bit product
3. Operating system, e.g. Windows 7 64 bit.
4. Attach a screenshot, if applicable
5. Attach logs, crash reports, etc., in a ZIP file
*** Make sure you do not post any licensing information ***
Re: Export unreachable folder names into a text file
I'll walk you through my script so you can see why the commands do what they do.Sam wrote:Hi team.
Am tying to check permissions issues on user folders . I am an admin and would like to run a script and check if i will be able to access a particlar users folder in the dfs. If i am denied permission ( meaning permissions on that particular folder are skewy), I would like to output that folder name into a text file, which i will then analyse and find out what the problem is at a later stage.
Please HELPPP!!!!!
Sam
Code: Select all
$OOPS.clear()
gci C:\users -recurse -errorvariable OOPS
If ($OOPS -ne $null)
{
$PermDenied=$OOPS
add-content -value $PermDenied c:\outputfiles\DENIED.TXT
}
Endif
GCI is the abbreviation for Get-Childitem
You can change the path (C:\users) to whatever path you need.
-Recurse tells gci to look through every subfolder, not just c:\users
-errorvariable tells Powershell to use the variable named "OOPS" to store any errors the script encounters (i.e. the names of the directories you can't access)
The If/Endif statement is where Powershell checks to see if OOPS is blank or not. (whether it contains the names of folders you can't access)
If OOPS is not blank, that information is assigned to the variable "PERMDENIED".,
Then, add-content statement tells Powershell to write the value of the variable "PermDenied" to the file located in C:\outputfiles called DENIED.txt
Add-Content will create the file if it doesn't already exist, and will append information to it if it does already exist...so make sure you create a separate file for each check you're performing.
This is probably a lot slower and less efficient method to search a large network drive than others use, but it works for me.
Re: Export unreachable folder names into a text file
You are trying too hard. The custom error variable is deleted and created automatically. We do not manage it. Just name it and use it.
Like this:
Like this:
PowerShell Code
Double-click the code block to select all.gci C:\users -recurse -errorvariable OOPS $OOPS | select TargetObject
Re: Export unreachable folder names into a text file
jvierra,jvierra wrote:You are trying too hard. The custom error variable is deleted and created automatically. We do not manage it. Just name it and use it.
Like this:
PowerShell Code
Double-click the code block to select all.gci C:\users -recurse -errorvariable OOPS $OOPS | select TargetObject
I kind of got the feeling the original poster didn't have any experience using power shell, so I "Rube Goldberg'd" some code together which would explain how to do what he/she wants, and provide an opportunity to also explain some additional things, like how you declare a variable, use abbreviations, use If/Endif statements, etc.
The code I use for this task is actually quite a bit different. It also tends to find and record the sub-folders contained within folders where my permissions are insufficient.
PowerShell Code
Double-click the code block to select all.$PCode=Read-Host "Enter Person for which this report is being run: " $target=Read-Host "Enter Drive letter or UNC Path Name: (Ex: C:\ or \\Server\Dept\Loc " $null = Get-ChildItem $target –Force –Recurse –ErrorAction SilentlyContinue –ErrorVariable AccessDenied ($AccessDenied.Exception)forgot to add that if you needed it in a text file you can use something like
Code: Select all
>c:\outputfiles\$pcode"_Denied.txt"
Re: Export unreachable folder names into a text file
notarat - yes, that should be helpful with one caveat. I used the "TargetObject" because it contains the name of the folder where access is denied. This avoids having to look at and save the whole exception.
The format of an output would be derived from processing all of this in a pipeline into either a set of CSV files or into a human readable report of some kind.
Note that the OP made some non-serious mistakes that I have noticed even many experienced scripters make. Too often non-programmers try to declare everything and do things like clearing a new variable. While this doesn't hurt it does make the code harder to read and understand.
The format of an output would be derived from processing all of this in a pipeline into either a set of CSV files or into a human readable report of some kind.
Note that the OP made some non-serious mistakes that I have noticed even many experienced scripters make. Too often non-programmers try to declare everything and do things like clearing a new variable. While this doesn't hurt it does make the code harder to read and understand.