Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using Powershell, How to list all servers with region format other than English (Australia) ?

Posted on 2014-12-22
6
Medium Priority
?
343 Views
Last Modified: 2015-02-12
Hi,

Can anyone here please assist me how to modify the script below to display the servers Locale and Regional settings in the domain ?

$path = "C:\temp\"
$serverlist = Get-QADComputer -SearchRoot 'mydomain.local/Servers/Production Servers' -OSName "Windows*Server*" -ShowProgress -Activity
 
foreach ($server in $serverlist){
    $result = Test-Connection $server -Count 1 -Quiet
    if ($result -eq "True") {
         # I need some help here.....
    }
    else {
        Add-Content "$path\OfflineServers.txt" -Value $server
    }
}

Open in new window


because for some servers, I received confusing timestamp MM/DD/YYYY instead of DD/MM/YYYY as the standard in our country.

Thanks,
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 11

Accepted Solution

by:
marek1712 earned 2000 total points
ID: 40514449
You can check for this property:
$Host.CurrentCulture

Open in new window

i.e.:
$computers = Get-Content C:\servers.txt
$cred = Get-Credential
foreach ($item in $computers)
{
Invoke-Command -Command {$Host.CurrentCulture} -ComputerName $item -Credential $cred
}

Open in new window

Make sure WinRM is working properly in your company.

THEN, based on the LCID you can do some substring swapping in the conditional statement to get the date in the correct format.
0
 
LVL 8

Author Comment

by:Senior IT System Engineer
ID: 40514458
Marek,

will that works for Win2003 host ?
0
 
LVL 11

Expert Comment

by:marek1712
ID: 40515769
If it has PowerShell 2.0 installed - yes. Make sure to enable WinRM though (i.e. through winrm quickconfig).
Alternatively - you can check this WMI class, especially Locale and OSLanguage properties.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 8

Author Comment

by:Senior IT System Engineer
ID: 40527069
Hi marek,

for some server, I got  the following error with WinRM:

[DomainController01-VM] Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in
 the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the
WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following c
ommand on the destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Trou
bleshooting Help topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken

how to perform Try catch to change the error message into just the server name only that needs to be enabled rahter than the full detailed error message ?

this is your script that I have modified:

$computers = Get-QADComputer -SearchRoot "domain.com/Servers/DC Servers" | Where-Object {(Test-Connection $_.Name -Count 1 -Quiet)}
$cred = Get-Credential -Credential "DOMAIN\Administrator"
ForEach ($item in $computers) {
	try {
		Invoke-Command -ScriptBlock {$Host.CurrentCulture} -ComputerName $item.Name -Credential $cred
	} catch [Exception] {    
	    If ($_.Exception -is [System.Management.Automation.Remoting.PSRemotingTransportException]) {
	        Write-Host "Error while sending command to the " $item.Name " server"
	    } Else {
	        $_.Exception.GetType().FullName
	    } 
	}
}

Open in new window

0
 
LVL 11

Assisted Solution

by:marek1712
marek1712 earned 2000 total points
ID: 40527823
What happens when you try to issue winrm quickconfig on these machines by hand?
You can use $ErrorActionPreference variable to handle errors or ErrorVariable to store it in another variable.
You could also use the Split method to cut through the error message and get only the computer name. Try doing it yourself - shouldn't be too hard. If it is - let me know and I'll help you with the script itself.
0
 
LVL 8

Author Comment

by:Senior IT System Engineer
ID: 40528542
Marek,

Yes with the winrm quickconfig command it enables the Powershell.

About hundreds of the server is not running so it is going to take very long time to enable it manually one by one.

But as for splitting the error, I'm not sure how to so that since I'm just a beginner in Powershell. I appreciate any help and suggestion so that I can export it to csv for easy read.

Thanks
0

Featured Post

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question