by TechiBee
on March 23, 2010
Use the script at https://techibee.com/powershell/powershell-script-to-query-softwares-installed-on-remote-computer/1389 to get installed software. Using Win32_Product has it’s own set of problems.
I have seen my colleague writting multi line script to do subjected task in powershell today. Scripts works great but felt why can’t we do it with single line code. After messing up with options, I ended at below command.
Get-WmiObject -Class Win32_Product -Computer <remote-comp-name> | Sort-object Name | select Name
Looks cool and simple right? This command lists all the application installed in a given machine.
Now lets extend the functioanality to check if a particular application exists or not…and this can be done with single command again!!.
Get-WmiObject -Class Win32_Product | sort-object Name | select Name | where { $_.Name -match “Office”}
Happy Learning..,
Sitaram Pamarthi
{ }
by TechiBee
on March 18, 2010
One other nice thing I found with PowerShell is it’s ability of using APIs by importing DLLs. Below is one example, where user32.dll is imported and LockWorkstation Function is invoked to lock the desktop. Btw, I grabbed this script from TechNet Library
Function Lock-WorkStation {
$signature = @”
[DllImport(“user32.dll”, SetLastError = true)]
public static extern bool LockWorkStation();
“@
$LockWorkStation = Add-Type -memberDefinition $signature -name “Win32LockWorkStation” -namespace Win32Functions -passthru
$LockWorkStation::LockWorkStation() | Out-Null
}
After executing above code, invoking “Lock-WorkStation” command from PowerShell window will lock your PC.
Happy Learning..,
Sitaram Pamarthi
{ }
by TechiBee
on March 17, 2010
Often we fall into a situation where resetting VM from Virtual Center console won’t help and server remains hung. In such cases we need to “hard” reset the VM to get it back online.
To hard reset a VM, there are two options…
Option 1:
- SSH to host as root where VM is hosted
- Issue “vmware-cmd -l” to list the guests on the current host
- In output you will see VMX file location for each guest
- Now issue “vmware-cmd <path_of_guest_vm_vmx_file_that_you_want_to_restart> stop hard”
- If above command is successful, start the VM either from VC console or with command “vmware-cmd path_of_guest_vm_vmx_file_that_you_want_to_restart> start”
Option 2:
In most cases, it option#1 should work. If it throws errors for some reason, try below method.
- SSH to host as root where VM is hosted
- Issue “vm-support -x”
- Result will give vmid(s) of guests running on the current host
- Now issue “vm-support -X 1234” where 1234 is the vmid of guest which you want to force reset
- Answer all the questions — mostly yes for all, but use your won intelligence
- This process will generate some debug information, so I prefer to execute this command from /tmp location.
- Once execution is completed, either use step#5 in option#1 or Virtual Center to start your guest VM.
Hope this helps…
{ }
by TechiBee
on March 10, 2010
Many times during my operations, I came across a requirement to create a file of specific size. In earlier times, the requirement was to create a dummy file of size in few MBs. That dumb procedure I used to follow was copy pasting images into word document and save it as desired file. But today my requirement is to create 1GB file and this time I feared about copy pasting the files as it is really waste of efforts. I just looked around in google and came across a fantastic way to my job. Here it is…
fsutil file createnew c:\tempmyfile.txt (1gb)
Wow..it created the file in few seconds time and my requirement is served with less efforts. There are still people around us who depend on their own cum dump techniques to create such large files for their requirements. I thought of making a post for helping such people, and this page born.
Happy Learning..,
Sitaram Pamarthi
{ }
by TechiBee
on March 10, 2010
I am working on testing a specific functionality in Windows 7 today and as part of that I have to clear “Application” event viewer every time I repeat the test. After running the test for few times, I got vexed up to open eventvwr to clear it manually from GUI. I quickly looked out for powershell option to clear event viewer and ended with below command.
Clear-EventLog -LogName Application
Look at the syntax of Clear-EventLog cmdlet to know more about it’s options.
I saved this command as ps1 and kept it on my desktop. Now I am able to clear event viewer by single mouse click..hey hey.. 🙂
Happy Learning..,
Sitaram Pamarthi
{ }
by TechiBee
on March 9, 2010
Do you think I am crazy..? Not me it’s Trevor who had this requirement and had written a script to do his task. It really sounds cool right? I love powershell only because of its capability of working with .Net components which makes many tasks possible in the world of IT administration.
You read Trevors post to know how to upload YouTube videos using PowerShell. If you want to send a email with GMAIL account using PowerShell, read one of my previous post.
{ }
by TechiBee
on March 9, 2010
[Last updated on 07/05/2010]
A article on working with powershell remoting is available at https://techibee.com/powershell/administering-remoting-in-windows-7-powershell/541
Powershell.com has released a guide for administering Remoting in PowerShell. It deals wtih A-Z of remoting, various concepts, how to enable it, disable it, creating sessions for frequent access, etc, etc.
I love this guide because of the depth of content it covered. Don’t miss to download your copy from here.
Happy Learning..,
Sitaram Pamarthi
{ }
by TechiBee
on March 9, 2010
There is no windows built-in command to do this, but you can make use of a third party utility called nircmd.exe for this purpose. Download a copy of it from http://nirsoft.net and execute the below commands
To open …
nircmd.exe cdrom open D:
To Close …
nircmd.exe cdrom close D:
Where d: is your cd drive letter.
Happy Learning..,
Sitaram Pamarthi
{ }
by TechiBee
on February 26, 2010
This I learned today through powershell.com. If you want to open a notepad or iexplore, or someother application in maximized or minized or restored mode, you can do that easily with Powershell.
To open a process in maximized mode, use this.
Start-Process notepad -WindowStyle maximized
To open a process in minimized mode, use this
Start-Process notepad -WindowStyle minimised
To open a process in restored mode
Start-Process notepad -WindowStyle normal
To open a process in hidden mode
Start-Process notepad -WindowStyle hidden
You can query and kill all these processes at one shot by using below command
Get-Process -Name Notepad | Stop-Process
Hope it is useful to you.
{ }
by TechiBee
on February 26, 2010
You can use this simple command to query CPU utilization of local/remote machine with PowerShell. This is really useful for troubleshooting issues. Enjoy…
Get-Counter -ComputerName "RemotePC" '\Processor(*)\% Processor Time' -Continuous -SampleInterval 5
This queries remote computer CPU usage for every 5 seconds continously.
If you want to query the local computer CPU utilization, simply use below command.
Get-Counter '\Processor(*)\% Processor Time' -Continuous -SampleInterval 5
Hope you liked it.
{ }