Skip to main content

Posts

Showing posts with the label Script

PowerShell Ping IP get status or reply

How to ping sweep a network?
How to ping sweep a subnet?
There’s a lot of ways to ping the whole subnet or do a sweep ping to the whole network, of course download any free software that can do this, or just manually ping the whole network by manually changing the IP address.
Or do an old school method, using a batch file. This link shows how to ping the whole subnet via command line. http://quickbytesstuff.blogspot.sg/2015/11/how-to-ping-whole-subnet-using-batch.html
Since PowerShell is readily available from Windows 7 up to the newer versions of Windows. Then PowerShell is the perfect choice to do this task.
Open PowerShell ISE or the PowerShell command line, then type or copy the commands below:
$ping = New-Object System.Net.Networkinformation.Ping 1..254 | % { $ping.send(“192.168.1.$_”) | select address, status | ft -auto }

Change the IP Address (192.168.X.X) to the IP address range of your network.
What the script does, is to Ping the whole network starting from 1 to 254, basically the w…

Remove startup files in Windows 10

How to delete, remove the files or program during startup in Windows 10?

To disable the startup program in Windows 10, right click on the task bar choose the empty space and select task manager.

On the Window tabs, Processes, Performance, etc. click on "Startup".

Right click on the program you want to manage select "Disable" if you need to disable, or if you need to enable it again select "enable" of course.

There's also an option "Open File location"|, if you need to check the  exact location of the program or file.

If you need to add custom files to start-up folder, the path would be:

C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Or open run box, by pressing shortcut key Windows + R and on the run box type: shell:startup

This will open the startup folder path location stated above.



Till next time. Cheers!

================================ Free Android Apps:
Click on links below to find out more:
Catholic Rosary Guide  …

Check PowerShell Version

How to check PowerShell version?

Open PowerShell ISE or PowerShell command line and type: get-host | select version

Sample Output:
Version: 2.0

Why need to check the PowerShell version?

If some commands that you find online is not working, it's either the command is wrong or the command is available for specific versions only.

New commands will work on new version of course, old commands may not work also on newer version if the command is obsolete or deprecated.

As the odds say, "Change is the only permanent thing in this world." and this quote is quite applicable in today's digital world.


Till next time. Cheers!

================================ Free Android Apps:
Click on links below to find out more:
Catholic Rosary Guide  for Android:
https://play.google.com/store/apps/details?id=com.myrosaryapp
http://quickbytesstuff.blogspot.sg/2014/09/how-to-recite-rosary.html
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Excel Keyboard shortcuts guide http…

How to get uptime in Windows using PowerShell

If you need to monitor how long the machine has been up, or whether the machine rebooted by itself or someone has just rebooted the server for without any reason. Then getting the uptime of the machine or server is important.
PowerShell code below gets the uptime by using a command line and processing its output.
#==========================
#get the uptime and save to text file Invoke-command -ScriptBlock { net statistics server >c:\online.txt }  $xcmd = select-string -path "c:\online.txt" -Pattern "since" | select line |ft -hidetableheaders  write-output $xcmd | out-file c:\online1.txt  $stry = get-content c:\online1.txt | out-string  $concatString = $stry.Substring(18,15) Write-host  $concatString
#Get the date $StartDate= [datetime] $concatString $EndDate= (GET-DATE) $xdate = NEW-TIMESPAN –Start $StartDate –End $EndDate write-output $xdate #==========================
Sample output:
Days              : 3 Hours             : 12 Minutes           : 12 Seconds           : 17 …

PowerShell registry keys basic operation

Working with registry keys is good and bad.
Good if you know exactly what you are doing, bad if you are just experimenting and you mess up the entire system.
Anyway, virtual machines will always save the day during test or experiment stage. Once everything is okay then deploy to the actual or production environment. If the test goes haywire, just trash the VM and start all over again.
Below are just simple and basic commands in PowerShell to query or get data from the registry.
This command below will list all the software listed on HKCU\Software path.
Get-ChildItem -Path HKCU:\Software
It’s quite useful to run it sometimes, so you will know what software is inside your system.
Below will list the user shell folders on the system.
Get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
Sample output:
AppData                                : C:\Users\Administrator\AppData\Roaming Local AppData                          : C:\Users\Administrator\A…

Linux list folders recursively

To list all folders on the root directory, type:
  ls -d /*
Sample Output:
/bin     /dev   /smsbackup  /lost+found  /mnt  /proc  /selinux  /tmp /boot    /etc   /lib        /media       /net  /root  /srv      /usr /cgroup  /home  /lib64      /misc        /opt  /sbin  /sys      /var
To list all folders on the current folder, one level depth only; type:
[xxx@mx var]$ ls -d */
Sample Output:
account/  cvs/    games/  local/  lost+found/  opt/       spool/  yp/ cache/    db/     gdm/    lock/  sms/        preserve/  tmp/ crash/    empty/  lib/    log/    nis/         run/       www/

List all folders and sub folders, 2 level depth or 2 level hierarchy; type:
[xxx@mx var]$ ls -d */*/
Sample Output:
cache/abrt-di/        lib/misc/        log/ConsoleKit/      run/portreserve/ cache/cups/           lib/mlocate/     log/cups/            run/rhsm/ cache/fontconfig/     lib/net-snmp/    log/sms/            run/saslauthd/ cache/foomatic/       lib/nfs/         log/gdm/             run/sepermit/ cache…

Access denied renaming shared folder

If you are working in a shared active directory environment and has a shared folder that needs to be renamed once in a while.
But every time you want to rename there is always a user who is using the folder and therefore, renaming the folder is denied.
How to rename the folder when the shared folder is always in use?
Automation will come for the rescue in such a scenario.
How to automate renaming the folder?
Task scheduler and a simple batch file can do the task and a life saver.
Here's how to do it:
Of course, disconnect all the open files. Users should shutdown their computers when they went out of the office,
If they don't shutdown, force their disconnection by using the command below:
openfiles /disconnect /o read/write openfiles /disconnect /o no access
Then, rename the folder with the ren or rename command of course.
Syntax is the good old fashioned source folder or path and the new folder name.
If the batch file will be run directly on the server, then the drive letter w…

Use tar command to backup in Linux

tar or tape archive is a basic tool that every Linux user should know.

Its syntax is quite different from the traditional copy or move command.

Since tar works from a 'current working directory' perspective.

Traditional syntax for copy or move is source then the destination.

In tar, the syntax is the filename or the path where the backup will be save and the source or the folder to be backed up or archived.

Typing: man tar (at the terminal shows the following)

tar -cf archive.tar foo bar
# Create archive.tar from files foo and bar.

Basically, it's like the destination where the file will be saved and the source or the files that will be archived.

Here's a simple bash script that will append the time and date the tar file was executed to the filename of the tar file.

If the bash script is automated via cron, the filename of the tar file will include the date and time the cron executes the script.


#script begins

#!/bin/bash
NOW=$(date +%Y%m%d%H%M)
echo $NOW
tar -Pczvf   /mnt/o…

PowerShell get folder capacity

Get the folder capacity using PowerShell via the old-school method.
Old-school since we will utilize the native “dir” command, just like the good old days of DOS.
PowerShell dir command output is not the same with the native windows system32 dir command line just like in DOS system.
The output will be in bytes since it is from the command line but of course, if you are command line junkie it will be easy to read even if the capacity is written in bytes.
First, fire up notepad write the dir command plus the full folder path of the specified folder in which you like to monitor or want to know the capacity.
 dir “c:\users\dmusic\music folder 001”
The path is enclosed in quotes since the folder has spaces and save the notepad as a batch file with “.bat” extension.
Open PowerShell command line window or PowerShell ISE and type the following command:
#change the path to where the batch file was saved
$folder_base_cap = d:\read_folder_cap.bat 
$ folder_base_cap | Select-String "bytes&qu…

PowerShell disable USB ports

Disabling USB ports using PowerShell by modifying registry values.
How to user PowerShell to modify an existing value in Windows Registry?
PowerShell code below modifies the registry value and disable USB ports in Windows.
The code must be run in an elevated mode to modify the registry.
Here's the code:
Modify the registry key value using PowerShell:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\USBSTOR\" -Name "start" -Value 4
To enable the USB ports, change the value to 3:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\USBSTOR\" -Name "start" -Value 3
Disabling USB ports is quite annoying of course, but if security is a concern then I guess it is justifiable especially computers that can easily be accessed by unwanted guests or individuals.

It will also protect the network or computers from getting malware's or viruses that is transferred or copied via USB storage.



Cheers! Till next time.


==============…