Skip to main content

Posts

Showing posts from 2019

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…

Test AD account password without logging in to the computer

Documenting AD password is a good practice and should be a part of IT policy.
It’s easier to troubleshoot and support users if the password is known to IT. Of course, ethical use of the password should be followed.
How to test an active directory account password whether it’s working or not, without logging in or signing in on a computer?
PowerShell can help to test a user account password quite easily.
AD admin account is needed and the PowerShell must be elevated while running the script below. Correct version of PowerShell is needed for this script.
See image below:


That’s it! Just replace the username and password to be tested and you can tell your users that the password is not working and needs password reset for their account to work.
The script is written for educational purposes and used it ethically.
Cheers!! Till next time. Happy Coding!!!
================================ Free Android Apps:
Click  links below to find out more:
Excel Keyboard guide: https://play.google.com/store/apps/det…

Replace column value of text files using awk

AWK is a handy tool to process large text files.
Ever came across a need to replace 100 or more text files value in a single column?
Of course, the old school method is to do it manually which is definitely time consuming and not efficient at all.
Below is a sample code how to replace value in a column for all text files found in the directory specified.
#!/bin/bash
for file in /home/pc_text/Documents/source/*
do xfilename=$(basename $file)
#echo "$xfilename" if you need to display the filename while the code is running
awk 'FNR==1{print $0}' $file >> /home/pc_text/Documents/output/$xfilename
awk 'NR>1{print $1 , $2 , $3 , $4, "0.873" , $6 , $7 }' $file >> /home/pc_text/Documents/output/$xfilename
done
Code explanation:
for file in /home/pc_text/Documents/source/* - get all text files for processing
xfilename=$(basename $file) – get all the filename of the text files
awk 'FNR==1{print $0}' $file >> /home/pc_text/Documents/outpu…

Error: the type or namespace name does not exist in the namespace using visual studio 2017

When compiling an error will occur that a name space does not exist. An example error like the message below:
The type or namespace name 'Microsoft.Office.Interop.Outlook' does not exist in the namespace 'Microsoft'(are you missing an assembly reference?)
The system is trying to find a reference for a specific namespace or dll.
One solution for this is to add the reference to the missing namespace.
Find the “solution explorer” window like the image below:


After opening the “solution explorer” window, right click the name of the project just below the solution explorer. Beside the C# icon.
A new window will open like the image below. Click “Add”, then click “Reference”.



After clicking “Reference”, the “Reference Manager” window will open.
Click “COM” option, then use the filter option to go directly to the desired namespace or reference. Since the error is a Microsoft namespace, type “Microsoft” and “Microsoft” namespace will be filtered from the list. See image below…

Copy or migrate shared folders to another server

Migrating or copying files to another server and retaining the permissions is a common task when migrating a file server.
If all permissions are successfully retained it will make the migration seamless and nobody will ever notice that a migration has taken place.
If there are shared folders and with different permissions, re-sharing the folder by scratch is just time consuming and giving access denied to users will be inevitable.
But how to copy files and folders, like it was exactly done on the old server?
In Windows environment, just 3 steps are needed. 3 steps sound easy and quick.
Steps below will work for NTFS permissions and folder access rights solely depends on it.
a.Copy the files to the new server and retaining its permissions while files and folders are being copied b.Export the shares registry (old server) c.Import the shares registry (new server)
The link below from Microsoft website shows how xcopy can copy folder and retain the permissions.
https://support.microsoft.com/…

PowerShell Insert Multiple Lines or text to another file dynamically

Copying and pasting text to another file is a common thing to do, copy and paste done. Boom!
In PowerShell scripting copying and pasting text from one file to another dynamically isn’t as easy as it is done in a spreadsheet or document. Dynamically while the code is running  and doing things in the background without human intervention.
As the odds say, if there’s a will there’s a way. And making things efficient and easy is a good way in life.
If ever a scenario occurs that you need to copy text or lines in a file from one file to another, without breaking the code execution. Script below works just fine. Just insert the code where it is needed.

PowerShell code snippet:
#================================
$reader=[System.IO.File]::OpenText("D:\test-read-paste\main1.txt") #get-content can also be used
$lineNumberx=3 #adjust this number where you need to start inserting the text
#Loop line by line and process while($null-ne ($line=$reader.ReadLine())) {
$textToAdd=$line
$newLineToAd…