Jump to content
Sign in to follow this  
support

Validate Password for Cisco Account (by Click Studios)

Recommended Posts

Script Name

Validate Password for Cisco Account

 

Description

Checks if a Cisco Account Password is correct

 

System Requirements

  • SSH Access to the router or switch

 

Successfully Tested Against

  • Cisco Catalyst 2950 Switch with iOS Version 12.1(22)EA14 (C2950-I6K2L2Q4-M)
  • Cisco 877 Router with IOS V15.1(1)T (C870-ADVSECURITYK9-M)

 

Failed Testing Against

  • None reported 

 
PowerShell Script

<#
.SYNOPSIS
Connect to a Cisco networking host via SSH, and validate the password for an account.
#>
function Validate-CiscoHostPassword
{
	[CmdletBinding()]
	param (
		[String]$HostName,
		[int]$Port,
		[String]$UserName,
		[String]$CurrentPassword
	)
		
	try
	{
		#Make a connection to the host
		Add-Type -Path "[PasswordstateBinFolderPath]\Renci.SshNet.dll" #Include SSH.NET Assembly
		
		$connectionInfo = New-Object Renci.SshNet.PasswordConnectionInfo($HostName, $Port, $UserName, $CurrentPassword)
		$connectionInfo.Timeout = New-TimeSpan -Seconds 30
		
		$sshclient = New-Object Renci.SshNet.SshClient($connectionInfo)
		$sshclient.Connect()
		$sshclient.SendKeepAlive()
		
		if ($sshclient.IsConnected)
		{
			Write-Output "Success" 
		}
		else
		{
			Write-Output "Failed to connect to the Host '$HostName' to validate the password for the account '$UserName'. Please check the Host is online, and accessible on the network."
		}
		
		#Dispose of SSH Client
		$sshclient.Disconnect()
		$sshclient.Dispose()
	}
	catch
	{
		switch -wildcard ($error[0].Exception.ToString().ToLower())
		{
			"*connection failed because connected host has failed to respond*" { Write-Output "Failed to connect to the Host '$HostName' to validate the password for the account '$UserName'. Please check the Host is online, and accessible on the network."; break }
			"*No connection could be made because the target machine actively refused it*" { Write-Output "Failed to connect to the Host '$HostName' to validate the password for the account '$UserName'. Please check the check the Port Number specified is cirrect."; break }
			"*Permission denied (password)*" { Write-Output "Failed to connect to the Host '$HostName' to validate the password for the account '$UserName'. Please check the username/password are correct. Error = 'Permission denied (password)'."; break }
			#Add other wildcard matches here as required
			default { Write-Output "Failed to validate password for account '$UserName' on Host '$HostName'. Error = " $error[0].Exception }
		}
	}
}

#Make a call to the Validate-CiscoHostPassword function
Validate-CiscoHostPassword -HostName '[HostName]' -Port '[RemoteConnectionPort]' -UserName '[UserName]' -CurrentPassword '[CurrentPassword]'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×