Category: PowerShell

Verify Connectivity to a Remote Computer

Verify Connectivity to a Remote Computer

Telnet from a Windows Machine

When providing accessible public services a requirement may arise to test the connectivity externally. This can be done using the built in command line Telnet subject to the Telnet Windows feature is installed. This is unlikely as in most scenarios, Telnet is only installed if required. Additionally, using Putty you can achieve the same result, however try downloading Putty through some Proxy’s and you wont have much luck. But using the built in Windows 10 PowerShell command Test-NetConnection, this is easily achiveable. If you need to test SMTP, HTTP, HTTPS, running  the below command can provide you with either “True” or “False”.

Test-NetConnection -Port 80 -ComputerName kamhussain.com | ft TcpTestSucceeded

 

Uninstall a Windows HotFix

Uninstall a Windows HotFix

Removing a Windows hotfix

To uninstall a Windows hotfix, locate the KB hotfix number and run the below PowerShell command:

function Uninstall-Hotfix {
[cmdletbinding()]
param(
[string] $computername,
[string] $HotfixID
)            
 
$hotfixes = Get-WmiObject -ComputerName $computername -Class Win32_QuickFixEngineering | select hotfixid            
 
if($hotfixes -match $hotfixID) {
    $hotfixID = $HotfixID.Replace("KB","")
    Write-host "Found the hotfix KB" + $HotfixID
    Write-Host "Uninstalling the hotfix"
    $UninstallString = "cmd.exe /c wusa.exe /uninstall /KB:$hotfixID /quiet /norestart"
    ([WMICLASS]"\\$computername\ROOT\CIMV2:win32_process").Create($UninstallString) | out-null            
 
    while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyContinue).Count -ne 0) {
        Start-Sleep 3
        Write-Host "Waiting for update removal to finish ..."
    }
write-host "Completed Uninstall of $hotfixID"
}
else {            
 
write-host "Hotfix($hotfixID) not found"
return
}            
 
}
 
 
 
Uninstall-HotFix -ComputerName PC1 -HotfixID KB3068708
Set AD Password with PowerShell

Set AD Password with PowerShell

Set a user’s Active Directory password using PowerShell

To set a AD password via PowerShell using plain text run the below PowerShell Command:

Set-ADAccountPassword –identity karchbol -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "1234" -Force)
Open a PSSession

Open a PSSession

How to run commands including PowerShell commands on a remote machine using PSsession

An alternative way to run commands remotely you can open a PS Session to a remote machine. What ever you type in the PS Session command prompt will run on the remote machine.

• Create a session (New-PSSession)
• Use the session (Enter-PSSession)
• Leave the session (Exit-PSSession or simply Exit)
• Close the session (Remove-PSSession)