PowerShell Template (modification of post by gmagerr view diff)
View followups from Gene Magerr | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/777"></script>download | new post
I created this function to generate a new PowerShell Script template. It will prompt for the name of the script you want to create (don’t need to add the .ps1 extension) and the email (don’t need to add email) then it will create the template in the C:\Scripts directory (Dir should already exist)
- Function New-Script
- {
- $strName = $env:username
- $date = get-date -format d
- $name = Read-Host "Filename"
- if ($name -eq "") { $name="NewTemplate" }
- $email = Read-Host "eMail Address"
- if ($email -eq "") { $email="youremail@yourhost.com" }
- $file = New-Item -type file "$name.ps1" -force
- $template=@"
- ###########################################################################"
- #
- # NAME: $name.ps1
- #
- # AUTHOR: $strName
- # EMAIL: $email
- #
- # COMMENT:
- #
- # You have a royalty-free right to use, modify, reproduce, and
- # distribute this script file in any way you find useful, provided that
- # you agree that the creator, owner above has no warranty, obligations,
- # or liability for such use.
- #
- # VERSION HISTORY:
- # 1.0 $date - Initial release
- #
- ###########################################################################"
- "@ | out-file $file
- ii $file
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository