Skip to main content

Posts

Showing posts from 2019

PowerShell Match Drive Letter to Volume ID in AWS

Matching AWS volume ID to its corresponding Windows drive letter is an easy task using PowerShell.
Win32_DiskDrive holds the info for the volume-ID.
Here’s the script, below enjoy 😊

$get_disks=gwmi-query"SELECT * FROM Win32_DiskDrive"
ForEach($diskin$get_disks){ $get_partitions=gwmi-query"ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
ForEach($partitionin$get_partitions){
$get_logicaldisks=gwmi-query"ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} WHERE AssocClass = Win32_LogicalDiskToPartition" ForEach($logicaldiskin$get_logicaldisks){
$insert_the_dash= ($disk.SerialNumber).Insert(3,"-") #insert dash to match AWS volume
$volume_partition="Drive Letter "+$logicaldisk.DeviceID +"is equals to volume: "+$insert_the_dash
Write-Output$volume_partition } }

PowerShell check Windows boot time and uptime

Checking boot time is essential in determining the server or workstation uptime.
If ever there is a server or computer that is not supposed to be rebooted or shutdown but then to check whether the server or computer hasn’t done a power cycle is to check its uptime.
Checking the uptime will determine how long the server has been online.
PowerShell is just an awesome tool to do this kind of task.

Here’s the script:
#run a command line using PowerShell $boot_time=&systeminfo|find"System Boot Time" Write-Output$boot_time
#display a pop-up message box using PowerShell [System.Windows.MessageBox]::Show('Hello, the '+$boot_time)
#split string using regex and match spaces $splitx=$boot_time-split'\s+'-match'\S'
#get the 4th array on the array element $xtime=Get-Date$splitx[4]
#get the current date and time of the system $Date=Get-Date
Write-Output$date
#subtract the current date and time with the boot time $get_duration=$Date-$xtime $xmin_total=$get_duration.TotalMinut…

Robocopy backup using Task Scheduler

Backup is a simple word that has a very good significant value in today’s digital world.

Unattended backup or automated backup is a good strategy, so the user or the whoever is managing the backup won't need to manually trigger the backup.
No data backup is a head-on strategy, that leads to catastrophe.
Backup is very, very important in today’s digital world. You will never know when a data disaster will strike.
The whole laptop will be lost, the hard drive will fail without any sign, a virus might corrupt the whole system or just simple mistake to overwrite or delete a data. All this scenario requires a backup rescue to recover the data.
Robocopy is a built-in command in Windows that does a pretty awesome job to backup or copy files.
Using Windows task scheduler, robocopy and Vbscript will create an important task to backup data.
How the three tools will be used, to backup data?
Robocopy – to backup or copy the files Vbscript – to hide the robocopy in the background while Roboc…

PowerShell Add Custom Result Property

PowerShell has its own or default format of displaying the results or the output of the cmdlets or PowerShell commands.
However, PowerShell is customisable, and the output property can be modified.
Example below, gets the name of the file and display the date only without the time.
PowerShell code snippet below filter a single  and gets its lastwrite date.

get-childitem "C:\Users\ps_testing\Documents" -filter IMXP2611.jpg -recurse |select Directory, Name, @{Name="LastWriteDate";   Expression={$_.LastWriteTime.ToString("yyyy-MM-dd")}} | ft -wrap

This can be modified using wildchars like "*", which filters all "jpg" regardless of filename.

get-childitem "C:\Users\ps_testing\Documents" -filter *.jpg -recurse |select Directory, Name, @{Name="LastWriteDate";   Expression={$_.LastWriteTime.ToString("yyyy-MM-dd")}} | ft -wrap

LastWriteDate == is a custom label for the output
yyyy-MM-dd == is a custom format that dis…

PowerShell regex count specific character or number

Example input is: 0009911000


$Input_Number = '0009911000'

#[1] = tells regex to match on the right or look forward
$xtotal=[regex]::Matches($Input_Number,'0+')[1].Value.Length
#[0] = tells regex to match on the left or look backward
$ytotal=[regex]::Matches($Input_Number,'0+')[0].Value.Length

#Matches($Number,'0+') means #Matches($input, $pattern)

Write-Output $xtotal Write-Output $ytotal
Image output from PowerShell ISE:


Above code works or matches if input is something like this: “0009911000” There are zeroes on the left and right and in between are any numbers or characters.
For input like this: 0000991100010 in which zeroes are in different position of the string the below code will work.
$Input_Number = '0000991100010' $xytotal=[regex]::Matches($Input_Number,'[0]*[0]*[0]+') Write-Output $xytotal

Output will be something like this: Groups: {0000} Success: True Captures : {0000} Index: 0 Length: 4 Value: 0000
Groups: {000} Success: T…

Print error 016-799 - Fuji Xerox

016-799 Fuji Xerox print error code. That shows a description error as “Print instruction Fail detected in decomposer.”
The error code and error description are alien languages for users and even system administrators who are not familiar with Fuji Xerox error code.
The error code is quite simple and easy to fix, if the job print goes to the printer but print out doesn’t come out.
So, basically the print job was received by the printer, but the printer just doesn’t know what type of paper or what size to use or which tray to utilize for the print out.
In some instances, this is just a paper mismatch but the error description; if using Windows 10 to print does not exactly points to what is the issue.

First thing to check, is the paper size selected by the user to print.
Example, if the printer configuration is A3 and A4 sizes only.

But then the person printing the file accidentally chooses “A4 Cover” then this error 016-799 will occur.

It’s quite misleading “A4 Cover” and “A4” only, so …

PowerPoint contact System Administrator error while opening the file

Office 365 PowerPoint shows an error contact system administrator when opening the file.
The error if interpreted literally shows that a system administrator is needed to fix the issue due to a security or permissions issue.
Notification errors or any errors that are displayed to inform the user that some processes have gone wrong while processing or opening the file are quite helpful to begin troubleshooting.
But some errors are quite generic or does not really point to what type of solution should be done to resolve the issue.
Literally interpreting the error to resolve the issue sometimes work but sometimes it won’t work as well.
For this error it seems like a permission issue but it’s not.
The first thing to try to eliminate the issue is to open the file manually, like going to “File”, select “Open”, then browse to the folder location of the file and open the file.
If the file can be opened, then security issue or permission issue is not a concern.
But when double clicking the f…

Backup SystemState Windows Server to a network share

Backup SystemState of a server to a network share is preferable rather than backing up to another partition within the local server.
Backing up to a network share is quite a good practice, so just in case anything goes wrong to the local server the system state is still safe since the backup is on a network share.
So, it’s like the old adage. Don’t put eggs in one basket. If all eggs are in one basket and if the basket is broken then everything is gone. Same logic goes to a server backup, protecting a server with a backup but then putting the backup to a local partition does not really protect the server from hard disk failure.
How to backup system state using wbadmin to a network share?
It’s quite straight forward but command prompt must be run at an elevated mode, and a network share that is accessible by the server and has enough space to hold the backup.
Command below will work with Windows 2008 and Windows 2012; newer version of Windows may still work but not tested.
wbadmin star…