Closed rlwakefield closed 3 years ago
Save-HTML comes from PSWriteHTML and its soft-way of fallback when the given path doesn't exist so that the file is not lost. Creating a path may be a dangerous way so I try not to do it and expect the user to do it themselves properly. Not sure I want to change that behavior as I am a bit afraid of the flaw in that logic and consequences for more complicated paths.
Oh yes, I completely understand and agree that it can be a difficult thing. I guess the bigger reason I was thinking was let's say we schedule the report to run over multiple groups and to store the HTML in a folder that is named something dynamically. Well, the problem here is I now have to add it to my code to make sure that I create those dynamically named folders which means adding more code to my script/call.
So for example, here is my script.
$groupName = "[name]" Show-WinADGroupMember -GroupName $groupName -FilePath (-Join("C:\Temp\Reports\",$groupName,"GroupMembership.html"))
The method/call works GREAT, but it just has to fall back to saving the file to my "C:\Users[username]\AppData\Local\Temp[number].html" path to save the file. Maybe as an alternative (again, just a suggestion), an additional parameter could be used like "-Force" and combine it with a Test-Path method call? Of course I have to rely on your expertise and knowledge of the code and all to determine if this is really able to be used or not. If I need to put in a Pull Request for official work/review, I am more than happy to do so. :)
What happens if the user makes a typo and it creates a path? I can't solve all problems. The Save-HTML is supposed to help if a mistake was made and the user was using cmd interactively. Surely if you're going to schedule something you can add 2-3 more lines of code?
The cmdlet can take multiple groups, so just create folder and use a single file for multiple groups?
Or add the single line above? New-Item -ItemType Directory "C:\Temp\Reports\" -Force
Also this join for sure doesn't give you C:\Temp\Reports\GroupNameGroupMembership.html
-FilePath (-Join("C:\Temp\Reports",$groupName,"GroupMembership.html"))
And if I would force it for you the C:\Temp\ReportsSomeGroupNameGroupMembership.html
would be used, and just C:\Temp would be created.
I do sometimes add dir creation with force of path - but I just don't feel this is the correct place to do it.
Thank you for those details. I completely understand and respect your choice. I will close out this issue as your answer makes sense and does help. 😃
Hello there,
When I ran the command "Show-WinADGroupMember" I put the FilePath parameter value to "C:\Temp\Reports\GroupMembership.html", but it errored out with the following.
Unless I am missing something, it doesn't automatically create the folder if it doesn't exist. I'm not sure if there is another parameter like "-Force" or something that I can use, or if this is something that needs added to the code.
Thanks.
Ryan