by TechiBee
on November 11, 2011
Mapped drives are the shares on remote computers for which you assigned a drive letter for easier access. We can query these drives and the target shares behind them with a simple and easy powershell one liner.
Here is the tip of the day. Happy Learning.
Get-WmiObject -Class Win32_MappedLogicalDisk | select Name, ProviderName
{ }
by TechiBee
on November 11, 2011
If you have worked on SCOM extensively, I am sure you would have already realized about one of the important features that SCOM administrators expect, that is “Scheduling maintenance mode”. That means, one should be able to define at what time a server should enter maintenance mode on daily, weekly, monthly, yearly, run-once basis. Unfortunately, there is no such option in UI.
Couple of days back I was hit with same requirement. A few services on a server are expected to go down for maintenance performed by the application installed on the server. It brings back the services once its activity is completed which never exceeds 30 minutes. These services are CRITICAL for reset of day and not during the time when application is performing the shutdown/startup activity. Initially, I thought I can create a schedule and keep the server in maintenance mode for that 30 minutes daily but I was disappointed after seeing no such option in maintenance mode wizard.
I felt this is a kind of basic requirement for a System administrator to schedule a servers maintenance mode. It helps during scheduled patch reboots and application maintenances.
So, I started looking for the options to fulfill this purpose. After some research ended up with only two options.
- #1: A third party powershell based tool that helps you schedule the maintenances:
The tool name is “SCOM Remote Maintenance Mode Scheduler“. It seems popular tool in internet for scheduling the maintenance mode since many people suggested this when I posted the requirement in technet forum. I read the documentation of it and per my understanding it has DotNet based GUI application which takes inputs from you and creates a scheduled task which inturn executes the powershell scripts that keeps the given computer(s) in maintenance at given schedule. I really like this idea and but felt something which is integrated with SCOM is more useful. The author of this tool has produced some more useful tools for SCOM world. Don’t miss to check them when you visit the site.
- #2: A MS given facility to schedule the maintenance:
After some more research, I came across “System Center Operations Manager 2007 R2 Admin ResKit “which has utility to schedule the maintenance mode. And the plus point with this is, it integrates with SCOM server. That means, you can see all the schedules by connecting to SCOM server and manage them. This is what exactly I needed. After exploring this further, I was bit disappointed because of it’s buggy behavior. It is giving too many dotnet errors and some of the menues in the application are some times not responding because of these errors. I couldn’t explore this tool completely due to these continuous dotnet errors which keeps popping up every time you click something on the utility.
I didn’t expect such buggy product from Microsoft for it’s own baby(SCOM). I wish they will hear this feedback and make it work lazy admins like me. I tried both x64 and x86 versions of the tool and their behavior is same.
So we don’t any other option than leaning towards the first utility if we really want to schedule some maintenance windows.
Hope this analysis helps.
{ }
by TechiBee
on November 10, 2011
You might see the error message outlined in subject while installing/uninstalling software on windows 2003 computer by connecting to terminal services. We all know that application installation has certain limitations when it comes to terminal services (anyone know why?). In such cases if you still want to install/uninstall the application on these terminal services enabled servers, you need to choose one of the following methods.
If this the requirement is just one of the case, then option#1 best suits you.
Option#1:
start mstsc with /console or /admin option and then connect to the server. This allows you to connect to the console of the server directly eliminating terminal services piece from you way.
Go to start -> Run -> type “mstsc /admin /v:servername” and click OK if you are using RDP client v6 or above
Go to start ->Run -> type “mstsc /console /v:servername” and click OK if you are using legacy version of RDP client.
Option#2:
If your administrators are expected to install applications on servers by connecting via terminal services, then you need to make sure that application installation is allowed. You can do it via group policies.
“computer configuration” -> “administrative templates” -> “windows components” -> “windows installer” -> “allow admin to install from terminal server session” should be enabled
Hope this helps.
{ }
by TechiBee
on November 9, 2011
This powershell function helps you to get the network status of all network adapters in a given computer. Using this script it is easy to determine the status of all network connections in remote computer to see whether it is connected/disconnected/media disconnected/and different other statuses. This script queries Win32_NetworkAdapter WMI class for list of network adapters and then fetches the status of each adapter by querying “netconnectionstatus” parameter. This is a uint16 data type which returns any value ranging from 0-12. Each value from 0 to 12 has it’s own meaning. See the below table for details(source: MSDN)
Value |
Meaning |
- 0 (0x0)
|
Disconnected |
- 1 (0x1)
|
Connecting |
- 2 (0x2)
|
Connected |
- 3 (0x3)
|
Disconnecting |
- 4 (0x4)
|
Hardware not present |
- 5 (0x5)
|
Hardware disabled |
- 6 (0x6)
|
Hardware malfunction |
- 7 (0x7)
|
Media disconnected |
- 8 (0x8)
|
Authenticating |
- 9 (0x9)
|
Authentication succeeded |
- 10 (0xA)
|
Authentication failed |
- 11 (0xB)
|
Invalid address |
- 12 (0xC)
|
Credentials required |
So, here is the script which lists the network adapter name and its status.
Script:
function Get-NetworkConnectionStatus {
param(
$ComputerName=$env:computername
)
$statushash = @{
0 = "Disconnected"
1 = "Connecting"
2 = "Connected"
3 = "Disconnecting"
4 = "Hardware not present"
5 = "Hardware disabled"
6 = "Hardware malfunction"
7 = "Media Disconnected"
8 = "Authenticating"
9 = "Authentication Succeeded"
10 = "Authentication Failed"
11 = "Invalid Address"
12 = "Credentials Required"
}
$networks = Gwmi -Class Win32_NetworkAdapter -ComputerName $computername
$networkName = @{name="NetworkName";Expression={$_.Name}}
$networkStatus = @{name="Networkstatus";Expression=`
{$statushash[[int32]$($_.NetConnectionStatus)]}}
foreach ($network in $networks) {
$network | select $networkName, $Networkstatus
}
}
Usage:
Get-NetworkConnectionStatus -ComputerName PC1
Hope this helps…
{ }
by TechiBee
on November 3, 2011
Yesterday I got a requirement to verify if a given list of folders are replicated to new installed PF server or not. I added the new sever to replica list of required PF folders and now I need to verfiy if the replication is completed so that I can remove the old PF server from the replica list.
Either Exchange management console or the exfolder util(utility to manage PF replicas and permissions) is not having the option to verify the replication status. Exfolder.exe is helpful to some extent as it is showing the list of items in that PF so that I can compare and confirm that all mails are replicated. I can do this for folders which has less number of items, but if the folder has more number of emails, then it is not a ideal way of doing it.
After researching for time, I found the way that solves my problem. The “Get-PublicfolderStatistics” cmdlet is the right choice here. I used this and generated the email items count in a PF from a particular PF server. After that ran two queries (listed below) and directed the output to a file for comprison. I tried to assign the output of each command to a variable and tried to compare-object cmdlet to compare the contents of both the output variables, but it didn’t work as exepcted for some weird reason. Let me know if it works for you.
Get-PublicFolderStatistics -Server PFServer1
Get-PublicFolderStatistics -Server PFServer2
Hope this helps…
{ }
by TechiBee
on November 3, 2011
Are you trying to create your own Management pack for custom needs? Then, you should read “SCOM MP Authoring Guide” to kick start. This gives you some deep insight into classes, relations,, discovery, discovery targets, discovery relations, discovery scripts(basically helps you create custom discoveries), different types of monitors(event, script, service, health, performance, unit, etc), different types of rules(event, collection), tasks, etc. It also helps you to understand how to perform tasks like groups creation, monitor/rules creations, etc.
You can also down full SCOM 2007 R2 documentation from here
Happy SCOMing.
{ }
by TechiBee
on November 1, 2011
I have seen hits from people coming to my blog with query string “converting string to a char array”. I don’t a post which shows how to do this but a similar post(https://techibee.com/powershell/know-about-ofs-a-special-variable-in-powershell/794) in my blog is catching these hits. Since many peopel are looking for this, I felt I should write one.
Converting a string into a character array is very straight forward. For example, take a string $website=”techibee.com”. Here $website is a string and if you want to convert this into a array of characters each letter fitting into one item in array, then just use [char[]]$website and you are done. You can go through the below little script for demonstration.
[string]$website = “TechiBee.com”
$chararray = [char[]]$website
write-host $chararray
#You can pick the element you want by passing the number to array index
write-host $chararray[2]
#You can also see what type of object $chararray is by invoking below command
$chararray.gettype()
Hope this little script helps you..
{ }
by TechiBee
on November 1, 2011
We all know that it is easy to get date time using powershell. It is as simple as
$currenttime = Get-date
write-host $currenttime
But the real challenge comes when you want the variable to hold current time whenever we query it. In the above example if you query the value of $currenttime it will show the time when it got the value from get-date. That means it is just holding one instance which is not valid if you want it to hold always currect time.
Today I came across a little PS tip which helps us to do this. That means we can have a dynamic variable which always returns the latest time when queries.
$global:currenttime= Set-PSBreakpoint -Variable currenttime -Mode Read -Action { $global:currenttime= Get-Date }
write-host $currenttime
start-sleep 5
write-host $currenttime
start-sleep 5
write-host $currenttime
After executing the above code, you will see output similar to this.
Hope this little tip helps you…
{ }
by TechiBee
on November 1, 2011
In SCOM there is no straight forward way to list all the groups of a given computer object. In last few days I worked extensively on SCOM and hit with this requirement of knowing the groups to which a computer account belongs. We can use some SQL queries to list the groups but I felt having a powershell code will be much more useful and wrote the below function.
You need to make sure that you are executing this script from SCOM operator shell. Otherwise it will fail as it is using SCOM PS cmdlets. We can make the script from a normal PS windows as well but that needs some more effort which I want to put in at later stage.
Another good thing with this script is, it fetches the nested groups as well.
Code:
function Get-GroupNames {
[cmdletbinding()]
param($computerFQDN)
$containmentRel = Get-RelationshipClass -name:’Microsoft.SystemCenter.InstanceGroupContainsEntities’
$computerClass = Get-MonitoringClass -name:”Microsoft.Windows.Computer”
$criteria = [string]::Format(“PrincipalName = ‘{0}'”,$computerFQDN)
try {
$computer = Get-MonitoringObject -monitoringClass:$computerClass -criteria:$criteria
$relatedObjects = $computer.GetMonitoringRelationshipObjectsWhereTarget($containmentRel,[Microsoft.EnterpriseManagement.Configuration.DerivedClassTraversalDepth]::Recursive,[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive)
}
catch {
$_
write-host “An error occurred while querying groups of $computerFQDN”
}
foreach($group in $relatedObjects)
{
[array]$Groups = $groups + $group.SourceMonitoringObject.DisplayName
}
if($groups) {
return $groups
} else {
write-host “No groups available for $computerFQDN”
}
}
Usage:
Get-GroupName -ComputerFQDN myserver1
Hope this helps….
{ }
by TechiBee
on October 29, 2011
Windows 7 comes with a few default themes which you can view from “Control Panel” -> “Appearance and Personalization” -> “Change the theme”. While exploring something today, I came across a hidden location where a few more window 7 themes are available.
To access the location, go to start -> Run and type “c:\Windows\Globalization\mct”. This lists the folders and here you can see the themes for “AU – Australia”, “CA- Canada”, “US – United States”, “GB – United Kingdom”, and “ZA – South Africa”. Out of these we generally see United Stated theme only in control panel. This is because of most of us select Country/language as US during the installation. If we choose some other country during the installation, the respective theme will get added.
If you like any theme in these hidden ones, just go to that folder and execute the file inside themes folder to install and activate it. I liked ZA theme among them 🙂
{ }