Category Archives: scripting

SSH with Powershell: Backup multiple Cisco devices

Today, I was asked to write a script to connect to all our Cisco devices and backup the configs to our fileserver. After a few hours of figuring it out, this is what I came up with

You ONLY need a READ ONLY account on the Cisco devices.

We run this every day at 2:00 AM and backup many Cisco devices.

I downloaded and use this SSH.NET Library: SSH With Powershell

You have to move it to your powershell modules directory and then import-module

##################################
# Ed Rockwell
# Requires SSH Module from here:
# http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library
# When downloading the above, you need to right click the download and unblock it in the properties
# Then add the contents to your powershell modules
# Free to distribute! Keep: http://www.EdRockwell.com
# 5/15/2014
 
Import-Module SSH-Sessions
 
$FileServerLocation = '\\path\to\file\server\'
$DeviceList = Get-Content '\\path\to\text\file\of\devices\NetworkDeviceList.txt'
$Date = (Get-Date -f yyyyMMdd)
 
md $Date
cd $Date
 
foreach ($Device in $DeviceList)
{
New-SSHSession -ComputerName $Device -Username YourCiscoUser -Password Password4CiscoUser
$DeviceBackup = Invoke-SshCommand -ComputerName $Device -Command 'show start'
$DeviceBackup | out-file $device'.txt'
}
 
cd ..
Move-Item $Date $FileServerLocation

Change a website to use a specific user in app pool (impersonate:false)

How to script moving a website username/password from web.config to an app pool is pretty easy if you have the correct syntax.

First, you need to use a tool called appcmd. that is located and must be ran from the following location:

c:\windows\system32\inetsrv

Before you make the change, this process updates the applicationHost.config file AND the web.config in the website directory so ALWAYS make a backup.

Simply copy the file called applicationHost.config from C:\Windows\System32\inetsrv\config so you have a backup.

Also copy the web.config from the website you’re changing as well.

Once your backups are done, open a CMD prompt and change directory to c:\windows\system32\inetsrv and run the following commands:

appcmd set config “SITE_NAME_HERE” /section:identity /impersonate:false

appcmd set config /section:applicationPools /[name=’SITE_NAME_HERE’].processModel.identityType:SpecificUser /[name=’SITE_NAME_HERE’].processModel.userName:DOMAIN\user_name /[name=’SITE_NAME_HERE’].processModel.password:Password_Here

it isn’t necessary to restart the app pool but it doesn’t hurt to do so.

To verify:

Test the site… Check the site logs… Check your security logs…

All done!