Skip to main content

Posts

Showing posts from May, 2016

Check setting for local group policies

Local group policies define policies for a particular windows system; Set restriction policies, such as limiting number of connection for a remote desktop and other numerous settings that can be set by the system administrator. The local group policy has a lot of settings to configure and is quite tough to remember those settings unless you have an extraordinary super memory. Keeping track of the changes in local group policy is important for troubleshooting purposes or if there are some issues that will arise due to policy change. A proper documentation such as screenshots or other methods is necessary to ease the pain of why and how the problem started. Windows provided an RSOP tool  to view the list of enabled configuration in group policy settings. RSOP.msc (resultant set of policy) shows which policy is enabled on the system. So the System Admin can just set and forget which of course not a good practice. But if need to reconfigure but don't know whic...

Disconnect Remote Desktop from command line

How to kill remote desktop sessions from the command line? How to close RDC sessions from the command line? One solution is to use batch file scripting or use PowerShell. For old timers batch file might be the preferred solution because you don't need to install anything, it  comes in handy with the native command prompt. Of course, PowerShell is also one of the best solutions; provided the environment is PowerShell ready. The method used below utilizes batch file or the command prompt, just like the good old DOS environment of yesterday. Command below can be run directly from the command prompt. To use batch file scripting open notepad and save the file with ".bat"  file extension. Once saved as a batch file, the script is ready for automation with the help of Task Scheduler. Here's the command: for /f "tokens=2,5" %a in ('netstat -ano ^| find "3389"') do echo %a & tskill %b /v For folks ...

Check Domain Name, DHCP and IP Address

In Active Directory world especially for newbie System Administrator or even for seasoned System Administrator who just acquired a messed up network from someone else hand, knowing or checking the domain name and whether network is using DHCP or not is quite important to get started on the job. Of course, IPCONFIG and its parameters is an important tool to manage or troubleshoot a Windows system. Typing “ipconfig /all” from command line will list a long and detailed output depending on the configuration of the system. With the aid of other command line tools, as long as the system administrator knows exactly what he or she wants the output can be very specific. In Linux environment piping commands or running multiple commands in one line is quite common. For Windows System Administrator Powershell will come in handy if executing multiple commands in one line. Command prompt in Windows also offers to run multiple commands in one line. Example below ...

PowerShell Copy Specific File Extension

PowerShell Code snippet to copy files with a particular extension. $extension = ('.pdf', '.docx', '.txt') Gci d:\WorkFolder $_ | Where-Object {   $extension -contains $_.Extension   } | % {Copy-Item $_.FullName d:\mix_backup} To read files with specified filename extension. $extension = ('.pdf', '.docx', '.txt') Dir d:\WorkFolder $_ | Where-Object {   $extension -contains $_.Extension   } or $extension = ('.pdf', '.docx', '.txt') Gci d:\WorkFolder $_ | Where-Object {   $extension -contains $_.Extension   } | % {write-host $_.FullName } Copying files with the long path will result to an error. Robocopy a command line tool is able to copy files exceeding 256 characters. Below is the modified code that uses robocopy to copy files with long paths. Do not interchange source and destination when using robocopy, the files will be overwritten. $e...

Touch file equivalent in Windows

Linux and Unix world has the luxury of using touch via command line or the terminal Window to change or modify the time and date of the file. How about in Windows? What is the equivalent of Touch in Windows environment? Touch result or touch output in Linux and Unix world can also be done in Windows. Just need to get your hands wet, with a little bit of coding in .NET. .NET offers the File.SetLastAccessTime, File.SetCreationTime and File.SetLastWriteTime methods. SetLastAccessTime MSDN link: http://msdn.microsoft.com/en-us/library/system.io.file.setlastaccesstime.aspx SetCreationTime MSDN link: https://msdn.microsoft.com/en-us/library/system.io.file.setcreationtime.aspx SetLastWriteTime MSDN link: http://msdn.microsoft.com/en-us/library/system.io.file.setlastwritetime.aspx MSDN links above provides a sample code on how to use the methods to set or change the creation time, last access time and last write time. So Windows users a...

Text file compare using PowerShell

PowerShell is able to compare text file easily. Technet article at the link below suggest using Get-FileHash cmdlet to compare whether files are different or not.   https://blogs.technet.microsoft.com/heyscriptingguy/2015/04/01/use-powershell-to-compare-two-files/ Below code is taken from Technet link above that shows how to use the Get-FileHash method. PS C:\> (Get-FileHash $fileA).hash   -ne (Get-FileHash $fileC).hash     True PS C:\> (Get-FileHash $fileA).hash   -ne (Get-FileHash $fileB).hash    False The output of the cmdlet is either True or False. True if the file is the not same with the other file, false if file is the same with the other file. It is just true or false to check whether both files are the same or not the same. But if files are not the same, how to check which lines or contents does not match with the other file? In my own point of view if there ...

Copy all matching files

Batch file script to copy all matching files recursively. Using the dir command and passing the values to the copy command the script below is able to copy files recursively. Script can be run via PowerShell using the Invoke-Command cmdlet. Invoke-command cmdlet with -Computer option and proper privileges the script below can be used to copy files on a remote computer provided that the correct path is specified. Replacing the file name extension specified on “dir command” (*.txt) the script is able to copy any files by replacing or specifying the file extension. Using PowerShell old batch file scripts if working properly doesn't need to be re-written but can be easily integrated and used by specifying Invoke-command and the batch file script filename. To know more about the syntax of Invoke-Command, open PowerShell ISE and type Get-Help Invoke-Command -Full. The output displayed shows examples and explanation that can easily be followed. Paramete...