{"id":1381,"date":"2009-05-05T08:00:15","date_gmt":"2009-05-05T16:00:15","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/2009\/05\/05\/may-powershell-onliner\/"},"modified":"2009-05-05T08:40:07","modified_gmt":"2009-05-05T16:40:07","slug":"may-powershell-onliner","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2009\/05\/05\/may-powershell-onliner\/","title":{"rendered":"May PowerShell Oneliner"},"content":{"rendered":"<p>In case you missed this recent SAPIEN newsletter, here&#8217;s my one liner for this month.<\/p>\n<p>I have a quick one-liner that will create a random filename with a preferred file extension in a folder that you specify. By default the <strong>GetRandomFileName()<\/strong> method will return a short 8.3 string with a random file name and extension. My one-liner uses the <strong>ChangeExtension()<\/strong> method to change the extension to something you prefer and the <strong>Join-Path<\/strong> cmdlet to combine a folder path with the random file name.<\/p>\n<p><span style=\"font-family: Consolas; color: #0000ff; font-size: x-small;\">PS C:\\&gt; $myfile=[system.io.path]::changeExtension((join-path &#8220;c:\\files&#8221; ([system.io.path]::GetRandomFileName())),&#8221;log&#8221;)<\/span><\/p>\n<p><span style=\"font-family: Consolas; color: #0000ff; font-size: x-small;\">PS C:\\&gt; $myfile<br \/>\nc:\\files\\gknnawtt.log<br \/>\nPS C:\\&gt;<\/span><\/p>\n<p>Now you have a temporary file to use with an extension you prefer in a location that you specify.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In case you missed this recent SAPIEN newsletter, here&#8217;s my one liner for this month. I have a quick one-liner that will create a random filename with a preferred file extension in a folder that you specify. By default the GetRandomFileName() method will return a short 8.3 string with a random file name and extension. [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[500,263,499,28,57],"class_list":["post-1381","post","type-post","status-publish","format-standard","hentry","category-windows-powershell","tag-extension","tag-file","tag-io","tag-powershell","tag-scripting"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=1381"}],"version-history":[{"count":1,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1381\/revisions"}],"predecessor-version":[{"id":1382,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1381\/revisions\/1382"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=1381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=1381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=1381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}