Script Help

I am looking for some help with a quick easy script. I need to backup the IIS configuration using powershell. Steps.

1. shutdown IIS services
2. execute
Import-Module WebAdministration
3. store contents from %windir%\System32\inetsrv\backup\ inside a new folder based on date+time IE V:\IISBackup\%datetime%
Restart IIS

Having some trouble with the time variables.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan McFaddenSystems EngineerCommented:
You can set a date & time variable with the following:

$dt = Get-Date - Format yyyyMMddTHHmm

Open in new window

The Format is as follows:

yyyy = 4 digit year
MM = month number (single digit has leading zero included)
dd = day number (single digit has leading zero included)

I include a "T" to indicate that next part is time

HH = 24 hour time  (single digit has leading zero included)
mm = minutes of the hour  (single digit has leading zero included)

Reference link for time formatting:

You can then use the variable to create either a directory or you can use the variable in the "Backup-WebConfiguration" command to name the directory that backup names

Reference link:

Backup-WebConfiguration -Name $dt

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jbla9028Author Commented:
Thanks Dan this helped guide me in the right direction.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.