Skip to main content

Posts

Showing posts with the label security

PowerShell Compare and Get Hash File

 Hash File comparison is a good thing to do, to make sure that file in transit, transferred, downloaded, or copied over is not corrupted or has been altered or modified. PowerShell has a built-in module to do this that makes life easier and an easy task to do. Here's an example code snippet to do this: #Path location of the file $file="C:\Users\User1\Downloads\Win10_22H2_EnglishInternational_x64.iso" # Get the file hash $hashSrc = Get-FileHash $file -Algorithm "SHA256" write-output $hashSrc #copy the Hash file  $Display_hash_only = $hashSrc | Select-Object -Property Hash | ft -HideTableHeaders Write-Output $Display_hash_only Output of the write-output $hashSrc command, will show the Algorithm used, the Hash of the file and path location of the file. Algorithm : SHA256  Hash: AC5522F9DB9F4F432A1AADE69FEF268C8C0B5FD3F22D3A6987719752F8A7108   Path : C:\Users\User1\Downloads\Win10_22H2_EnglishInternational_x64.iso  After getting the Hash File run this code...

Copy a single file using robocopy

Copy a single file using robocopy from a local folder to a shared folder on the network. A simple rule of thumb before any disaster strike, don't interchange the source and the destination. If source and destination is mistakenly reverse, files might get overwritten. To avoid any loss of data do a test with a dummy file to ensure things work perfectly. Robocopy [source]    [destination]   [file to be copied] robocopy c:\local_c_folder  \\PC_network\shared_folder   file_to_be_copied_xx.txt The command will be completed successfully provided the network access right has no issues. Robocopy works quite good on large files. A simple copy or xcopy command will also work but the speed might vary. However, if the file (ex. an ISO file) and is more than 4GB and the filesystem  of the thumbdrive or the storage is FAT system, then robocopy or any methods of copying will not work. Since FAT has a file size limitation of less than 3GB. Roboco...

PowerShell check if port is open

PowerShell code snippet to check or test whether a port is open or closed on the IP Address specified. ==============================   $port_num= "2443" $IP_Add="192.168.2.1" $result = New-Object Net.Sockets.TcpClient $IP_Add, $port_num     if($result.Connected)     {        write-host "Port 443 is open."        $result.close()     } else     {      write-host "Attempt to connect failed, check firewall or other settings."     } ============================== If port 2443 is open in IP Address 192.168.2.1 then PowerShell script will show "Port 443 is open." If port 2443 is close the script will show "Attempt to connect failed, check firewall or other settings." If the port is closed it could be that the firewall is not set to accept incoming connections for the particular por...

Netsh show firewall state

How to check Windows firewall advance security current state using command line? Command line below will check whether the firewall state is on or off. To check the firewall state via command line type:        netsh advfirewall monitor show firewall Command above will display the current firewall state. If the state shows “ON” the firewall is working. Sample output: Domain Profile Settings: ---------------------------------------------------------------------- State                                                   ON Firewall Policy                                   BlockInbound,AllowOutbound LocalFirewallRules                            Enable L...