tag:blogger.com,1999:blog-7753723998721699054.post4890894882372169900..comments2023-05-11T05:47:20.870-04:00Comments on Dan's PowerShell Stuff: PowerShell pretty printer / code cleaner V1Dan Wardhttp://www.blogger.com/profile/16527935206385462422noreply@blogger.comBlogger38125tag:blogger.com,1999:blog-7753723998721699054.post-41275432622794149762020-08-02T16:45:09.790-04:002020-08-02T16:45:09.790-04:00Hey Peter -
Nice work - I'm going to check it...Hey Peter - <br />Nice work - I'm going to check it out! I had thought about rewriting the Beautifier to use AST a few years ago but ran into some issues - including not having any time. It's amazing how fun writing PS utilities is; I wish I could do it as a full-time job.<br />-DanDan Wardhttps://www.blogger.com/profile/16527935206385462422noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-19347521155998191322020-07-31T03:37:42.405-04:002020-07-31T03:37:42.405-04:00Hi Dan,
I am currently developing also an PowerSh...Hi Dan,<br /><br />I am currently developing also an PowerShell Code beautifier.<br />Some idias are taken from your Module.<br /><br />THANK YOU for your Inspiration!<br /><br />If you want have a look into, it is here.<br />https://github.com/Kriegel/BeautyOfPowerPeter Kriegelhttps://www.blogger.com/profile/00719298568042961033noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-72683170707866000442019-03-13T07:49:05.990-04:002019-03-13T07:49:05.990-04:00I would recommend my profile is important to me, I...I would recommend my profile is important to me, I invite you to discuss this topic... <a href="http://copierandprinter.co.za/shop/" rel="nofollow">Buy Espon printer</a>seomonsterhttps://www.blogger.com/profile/15567824806505296284noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-2908488107045029032017-08-29T13:23:44.883-04:002017-08-29T13:23:44.883-04:00You are my hero! Thanks for sharing it on github. ...You are my hero! Thanks for sharing it on github. Eduardhttps://www.blogger.com/profile/06230543593598447922noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-75263598420353832812017-05-18T05:39:17.112-04:002017-05-18T05:39:17.112-04:00Imagine my surprise when opening this page! Keep u...Imagine my surprise when opening this page! Keep up the good stuff and Hello from Luxembourg!Alanhttps://www.blogger.com/profile/07654712319700727826noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-16179880227277406062017-04-16T10:35:42.805-04:002017-04-16T10:35:42.805-04:00Hey Eric -
I've been planning on putting the p...Hey Eric -<br />I've been planning on putting the putting the PowerShell beautifier / pretty printer up on GitHub in the next few weeks. As part of that I'd love to work with the atom-beautify folks to get PowerShell support integrated.<br />-DanDan Wardhttps://www.blogger.com/profile/16527935206385462422noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-57904412719655183182017-04-15T21:25:43.989-04:002017-04-15T21:25:43.989-04:00Dan, is there any chance you might have interest i...Dan, is there any chance you might have interest in being involved in making a beautifier for Atom? https://github.com/Glavin001/atom-beautify/issues/333<br /><br />I believe you're existing module could do the trick, and there seems to be a number of interested people on github.Anonymoushttps://www.blogger.com/profile/06829043957369394503noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-12973301501359932742016-04-16T12:06:13.225-04:002016-04-16T12:06:13.225-04:00Just what the doctor ordered - thank you so much!Just what the doctor ordered - thank you so much!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-45409520537199753532016-01-15T17:15:25.184-05:002016-01-15T17:15:25.184-05:00Your script doesn't support full UNC paths. I...Your script doesn't support full UNC paths. I.e., this doesn't work:<br /><br />PS C:\> Edit-DTWCleanScript \\my_share_server\share_drive\start-Procmon.ps1<br /><br />Exception calling "ReadAllText" with "1" argument(s): "The given path's format is not supported."<br />At C:\Users\username\Documents\WindowsPowerShell\Modules\DTW.PS.PrettyPrinter\DTW.PS.PrettyPrinterV1.psm1:735 char:5<br />+ $script:SourceScriptString = [System.IO.File]::ReadAllText($SourcePath)<br />+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /> + CategoryInfo : NotSpecified: (:) [], MethodInvocationException<br /> + FullyQualifiedErrorId : NotSupportedException<br /> <br />Tokenizing script content<br />Edit-DTWCleanScript : Edit-DTWCleanScript :: error occurred during processing<br />At line:1 char:1<br />+ Edit-DTWCleanScript -SourcePath \\my_share_server\share_drive\start-Procmon.ps1<br />+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /> + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException<br /> + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Edit-DTWCleanScript<br /> <br />Edit-DTWCleanScript : Exception calling ".ctor" with "3" argument(s): "The given path's format is not supported."<br />At line:1 char:1<br />+ Edit-DTWCleanScript -SourcePath \\my_share_server\share_drive\start-Procmon.ps1<br />+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /> + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException<br /> + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Edit-DTWCleanScript<br /> <br />Write destination file: Microsoft.PowerShell.Core\FileSystem::\\my_share_server\share_drive\start-Procmon.ps1<br />Finished in 0.285 seconds.<br /><br /><br /><br />Although, that looks like it's a bug with System.IO.File rather than in your code. Just figured I'd point it out. Simple work around is to just copy the file to a place with a drive letter, and then copy it back.supercheetahhttps://www.blogger.com/profile/04610013420742722640noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-85022374678588592352016-01-13T13:45:01.517-05:002016-01-13T13:45:01.517-05:00Nice tool dude! I always struggle with making my ...Nice tool dude! I always struggle with making my scripts look neat.Lesliehttps://www.blogger.com/profile/06868637923089876695noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-17263242855012064732015-09-14T09:47:46.565-04:002015-09-14T09:47:46.565-04:00This comment has been removed by the author.Bill Loyttyhttps://www.blogger.com/profile/08129758862222581649noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-1623918431486532072015-09-02T15:54:17.288-04:002015-09-02T15:54:17.288-04:00Hello,
I know this is a old post, but i was getti...Hello,<br /><br />I know this is a old post, but i was getting the below error when i run your script....<br /><br />PS U:\> Edit-DTWCleanScript -SourcePath C:\users\user\Downloads\test.ps1<br />Reading source: C:\users\user\Downloads\test.ps1<br />Tokenizing script content<br />Tokenize-SourceScriptContent : Tokenize-SourceScriptContent:: error occurred tokenizing source content<br />At C:\Users\user\Downloads\PS\DTW.PS.PrettyPrinterV1.psm1:1513 char:5<br />+ Tokenize-SourceScriptContent -EV Err<br />+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /> + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException<br /> + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Tokenize-SourceScriptContent<br /><br />Property 'Name' cannot be found on this object. Make sure that it exists.<br />At C:\Users\user\Downloads\PS\DTW.PS.PrettyPrinterV1.psm1:766 char:33<br />+ Write-Error -Message "$($MyInvocation.MyCommand.Name):: $($_.Message) Co ...<br />+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /> + CategoryInfo : NotSpecified: (:) [], PropertyNotFoundException<br /> + FullyQualifiedErrorId : PropertyNotFoundStrict<br /><br />:: Unrecognized token in source text. Content: @, line: 259, column: 79<br />At C:\Users\user\Downloads\PS\DTW.PS.PrettyPrinterV1.psm1:765 char:29<br />+ $Err | ForEach-Object {<br />+ ~<br /> + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException<br /> + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException<br /><br />Property 'Name' cannot be found on this object. Make sure that it exists.<br />At C:\Users\user\Downloads\PS\DTW.PS.PrettyPrinterV1.psm1:766 char:33<br />+ Write-Error -Message "$($MyInvocation.MyCommand.Name):: $($_.Message) Co ...<br />+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /> + CategoryInfo : NotSpecified: (:) [], PropertyNotFoundException<br /> + FullyQualifiedErrorId : PropertyNotFoundStrict<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-91601573780646896402014-10-22T02:48:48.783-04:002014-10-22T02:48:48.783-04:00Very useful. Thank you. Very useful. Thank you. Stuthinoreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-62830690806518332882013-06-03T10:45:01.487-04:002013-06-03T10:45:01.487-04:00The script is removing brackets
For example [Syst...The script is removing brackets<br /><br />For example [System.Windows.Forms.MessageBox] would end up with brackets removed, thus not working. Everything else seems to be intact.Anonymoushttps://www.blogger.com/profile/12547825103713540807noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-1064596712573605552013-02-26T17:01:19.913-05:002013-02-26T17:01:19.913-05:00Would be cool to configure spacing for () and {}.
...Would be cool to configure spacing for () and {}.<br /><br />I like to use tabs to indent.<br /><br />If you put the code up on github and then I would be happy to help contribute.<br />Michael Westhttps://www.blogger.com/profile/18044666120222821194noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-87358740685754668942013-02-20T12:44:23.367-05:002013-02-20T12:44:23.367-05:00Thanks! I haven't done any serious PowerShell...Thanks! I haven't done any serious PowerShell scripting in some time so I'm thinking about start v2 soon. Please comment if you have any functionality requests.Dan Wardhttps://www.blogger.com/profile/16527935206385462422noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-60588417046311525762013-02-16T14:32:34.237-05:002013-02-16T14:32:34.237-05:00Well done. This is the only thing out there of it...Well done. This is the only thing out there of its kind that I see. Version 2? Hell, if you charged a little bit...EzTekhttps://www.blogger.com/profile/00519458855927007390noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-78738522951422500422013-02-10T19:35:45.975-05:002013-02-10T19:35:45.975-05:00Oh, no idea. I started a new job last year and I&...Oh, no idea. I started a new job last year and I've been crazy busy since. I have no idea when I'll get back to this... :-(Dan Wardhttps://www.blogger.com/profile/16527935206385462422noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-24806198558443627492013-02-10T09:39:46.161-05:002013-02-10T09:39:46.161-05:00When do you plan to release the prospected V2 :)When do you plan to release the prospected V2 :)吴波https://www.blogger.com/profile/15669017859528197859noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-76149841214288092652013-02-03T17:41:31.876-05:002013-02-03T17:41:31.876-05:00No problem, Fed Up. This isn't a built-in Pow...No problem, Fed Up. This isn't a built-in PowerShell module, it's a custom one, so the easiest way to load it is store it some custom folder and then load it into your shell using the full path. So let's say you downloaded and unzipped the files to c:\temp\PS, you would load my module into your shell using this:<br /><br />Import-Module "C:\temp\PS\DTW.PS.PrettyPrinterV1.psd1"<br /><br />You should now be able to see it in memory by typing Get-Module; it'll list at least mine (if not more) with the Name DTW.PS.PrettyPrinterV1. You will also see two ExportedCommands, one of which is Edit-DTWCleanScript. That's the main function that you call to clean a script.<br /><br />To see a few examples of how to use Edit-DTWCleanScript plus the rest of it's help, call the function with Get-Help:<br /><br />Get-Help Edit-DTWCleanScript -Full<br /><br />Please read all the help text - the SINGLE most important detail in there is MAKE SURE YOU BACK UP YOUR SCRIPT before running this utility on it. My function, by default, is designed to rewrite your files in place, overwriting the original copies. You need to check in your file, copy it to a temp location or test on a temp copy first - and then maybe diff after - to ensure that it doesn't screw up your script.<br /><br />Now, all that said, this is V1 of the PrettyPrinter (and I don't know if I'll ever get to V2). This version does not restructure your code across lines - it does not move script block openings, closings, etc. (that was planned for V2), it cleans up whitespace, expands types names, resolves aliases and a bunch of other things. <br /><br />If you are looking for something to completely rewrite your code and make it "perfect", this may not be the exact tool, but it's a good start. If you want a good example to learn from - to see how to write detailed, clean code with proper help, types on parameters, etc. - take a look at other people's code. Start with mine - download PowerGUI (a PowerShell editor) and take a look through the file DTW.PS.PrettyPrinterV1.psm1. That's the best way to learn, but mind you, everyone formats their code a little differently depending their background.<br /><br />Have fun learning PowerShell!<br />Dan Wardhttps://www.blogger.com/profile/16527935206385462422noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-12601064180845803212013-02-01T12:53:50.926-05:002013-02-01T12:53:50.926-05:00ok...forgive me for being a total Noob or not exac...ok...forgive me for being a total Noob or not exactly knowing what to do with this..recently I was flamed by someone for not formatting my scripts properly..being new to PS and not having any formal script training I have a hard time with that..and no one seems to want to teach me..so..I found your tool..exactly what do I do with the files once I have downloaded them?<br />I created a new folder in the modules directory..copied the files into it..open PS..type IPMO edit-DTWCleanscript and get a message stating no valid module is found..<br />for us noobs can you provide a "readme" file in the zip file?Fed Uphttps://www.blogger.com/profile/14359929556511620353noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-74071862392944501792013-01-23T21:34:17.502-05:002013-01-23T21:34:17.502-05:00The bug (which I haven't fixed; life has been ...The bug (which I haven't fixed; life has been busy) was handling files that used unix-style end of line characters (i.e. LF) instead of Windows-style EOL (CR+LF). Test files that failed had either all LF or a mix of each and this utility only currently handles only EOL CR+LF, so you might want to re-save your file explicitly with the Windows style and re-run the utility. I've seen this most often with script people cut-and-paste from browsers.<br /><br />Yeah, I totally agree with you on the spacing issue. One of the configurations I planned on having in V2 was the ability to tighten the code based on the overall expression length. So, if the expression length was below some value (you choose) and the tighten was enabled, it might even shorten a short code block like this:<br /><br />if ($num -lt 5) <br />{<br /> $num + 3<br />} <br />else <br />{<br /> $num + 1<br />}<br /><br />to this:<br /><br />if ($num -lt 5) <br />{ $num + 3 } <br />else<br />{ $num + 1 }<br /><br />or even this:<br />if ($num -lt 5) { $num + 3 } else { $num + 1 }<br /><br />I normally like things spaced out but for concise code, especially if it's repeated often, all in one line is nice.<br /><br />Also, I started down the road awhile back to PowerGUI-ify it but again, ran out of time, alas.Dan Wardhttps://www.blogger.com/profile/16527935206385462422noreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-85981297539849871362013-01-23T15:54:29.985-05:002013-01-23T15:54:29.985-05:00Here is another sample to test on:
http://powershe...Here is another sample to test on:<br />http://powershelldevtools.wordpress.com/2010/07/20/how-to-deal-with-a-combobox-control/<br /><br />Before, it works<br />After, it kinda works but not quite and you get 4 errors.<br /><br />--------<br />I was really looking forward to seeing this work.<br />I also hoped I could add it to PowerGUI as an add-on and then right-click on a TAB and select PrettyPrinter but no.<br /><br />For V2 I hope you can add ways to select how much spacing it adds. I can't stand Double-spaced code because I need to scroll around too much to see a code block. I like tightly formatted code like this:<br /><br />If ( ) {<br /> [code]<br /> } else {<br /> [code]<br /> }<br /><br />yours does this (very AIR-y):<br /><br />If ( ) <br />{<br /> [code]<br />} <br />else <br />{<br /> [code]<br />}Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-48173173748832030482012-12-10T08:24:47.368-05:002012-12-10T08:24:47.368-05:00Import-Module .\DTW.PS.PrettyPrinterV1.psd1
Get-He...Import-Module .\DTW.PS.PrettyPrinterV1.psd1<br />Get-Help Edit-DTWCleanScript -FullAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-7753723998721699054.post-18135108290717289422012-07-19T13:59:23.466-04:002012-07-19T13:59:23.466-04:00Awesome, glad it's working for you. I'll ...Awesome, glad it's working for you. I'll update the code at some point; maybe this weekend...Dan Wardhttps://www.blogger.com/profile/16527935206385462422noreply@blogger.com