Skip to main content

Cool Things you can do with PowerShell

Be very cautious while trying these steps


Yes, this is a tool worthy of the name. PowerShell can easily cause massive configuration changes, positive or negative: so protect yourself and establish a test environment for your learning experiences. Also consider using the "-confirm" parameter to test configurations before execution for certain commands.

Number 1: Report all of the USB devices installed

PowerShell is Windows Management Instrumentation (WMI) aware. From PowerShell, you can make a WMI call to retrieve the USB devices installed in a local or remote system:

gwmi Win32_USBControllerDevice -computername SERVER1 |fl Antecedent,Dependent
This will apply a filter to bring back the antecedent and dependent fields from the SERVER1 computer. Should you want the full export, you can omit the pipe and filter statement to have a comprehensive export of the USB devices on a system. I have found this useful to maintain a report for servers that have a USB license device installed so that their connectivity is maintained from the device perspective.

Number 2: Perform your favorite CMD tasks in PowerShell

Yes, you can stop using the DOS prompt and start doing all of those same tasks within PowerShell. This can make learning a little easier and help you become more familiar with the interface. Unfortunately, from the run prompt, there is no three-letter launcher like cmd. But powershell will launch it. You can also assign a shortcut key to PowerShell so Ctrl + Shift + P launches it directly.

Number 3: Kill a process in PowerShell instead of Task Manager

When you have a Windows service running that will not respond to stop commands, you can use PowerShell to perform the equivalent actions of ending the task within Task Manager. For instance, you'd do the following for BadThread.exe:

get-process BadTh*
The results will be similar to this:

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
28       4  -210844    -201128  -163    25.67   2792 BadThread
Once the Process ID has been identified, you can kill the errant process by entering:

stop-process -id 2792
At that point, the BadThread example will be hard stopped and you can resume your attempt to start the service. You can do that right here in PowerShell as well.

Number 4: Use PSDrive to view more than just drives

The PSDrive command lets you view objects of the Windows environment beyond traditional network, local, or removable drives. One popular view is the HKLM PSDrive to view the HKEY_LOCAL_MACHINE top-level hive of the registry. To get into the registry, enter the following command:

PS    C:>        cd HKLM:
PS    HKLM:/>
You are then transported into the registry hive and can view and even delete items, should you wish.

Number 5: Export NTFS folder permissions -- recursive or not

Managing NTFS permissions is a whole separate matter, but with PowerShell, you can export the permissions to audit access or take a quick look at access control lists (ACLs) for the security configuration. This can be a great accountability mechanism to run in a scripted format periodically -- or you can run it on demand to diagnose a particular issue. For example, take the following iteration:

PS    E:>Get-Acl N:Data
This will give you a quick report of your security rights to the specified path (note that it won't give the share access). That alone is nothing too exciting, as it will report only the single specified path, but if you want to include recursion for the entire path, you can use other strategies. For the same path (N:\Data), you'd use the Get-ChildItem command (cmdlet) within PowerShell, combined with the Get-Acl command. Consider the following example:

PS    E:>Get-ChildItem N:Data -recurse | Get-Acl
This will span the entire N:\Data path and display the ACLs for the contents of the path. What happens here is that the Get-ChildItem provides an inventory of the file system objects, and that collection is passed to Get-Acl to provide the results for each item.

If you want to archive this to a comma-separated variable (CSV) document, you pass "| export-csv c:\filename.csv" at the end of the cmdlet. You can also pass the normal "> C:\filename.txt" to the end of the command to get it exported to a text file. Note that when you use the -recurse option, it does just that and will traverse the entire path you specify. So be careful when doing it across a large volume or over the network.

Comments

Popular posts from this blog

3 main differences between cloud and on-premises storage

Cloud storage and on-premises storage are two great options for storing, serving, and protecting data   but there are three main differences that one must be aware of before choosing between these two: availability, data protection and   performance. To set start with, cloud storage, means hosted object stores like Microsoft OneDrive, Amazon S3, and AT&T Synaptic Storage. While on-premises storage, are all file-oriented storage including NAS, clustered NAS, unified storage, and object storage. Although there are clear technological differences between on-premises storage, many of those differences are erased when deployment is considered. 1>        Cloud storage is highly available as compared to many on-premises storage deployments, with much less complexities. Cloud storage is an attractive choice for data, as prices continue to drop down and the services are getting mature. The advantage of pay-as-you-go versus investing in physical infrastructure and then

How to convert your Classes/Courses/Tuition into an online course without spending any money?

Using a variety of online services available for free on the internet you can convert your Classes/Courses/Tuitions into an online course without spending any money. Using a web blog, a page on Facebook, or other social network pages can be a central hub where the course syllabus and activities can be scheduled. An outline for the course can be created. Document sharing tools like Google Drive, DropBox, One Drive can be used to share the important notes and course contents. Tools like Skype, Whatsapp, Google Duos, Hangout can be used to communicate and hold webcam based meetings. Instagram and other photo sharing tools can be used to share photographs. To share videos services like Vimeo and Youtube can be utilized. Tools like Camtasia can be used to capture screenshots and record synchronized lecture or explanations about them. But, if you choose these mix of different online tools instead of a dedicated LMS, Many challenges arise, including the follow

Teach from home

Seeking volunteers for mentoring aspirants for different competitive exams. Benefits:  - earn handsomely - contribute to the creation of world-class content - teach from the ease of your home - help in building new horizons of learning Your help can give countless people around the country, the Guidance - the one thing they need most.  to connect: drop an email at contact@eprabodh.in