Tuesday, May 14, 2013

Powershell Internationalization

When you need you script work in all computers around the world, please define a cultureinfo ("en-US" cultureinfo for example)
(below an example in my 'french' computer)
$date = Get-Date            
$culture = New-Object System.Globalization.cultureinfo("en-US")         
$date
samedi 4 mai 2013 09:55:18


$date.Tostring("dddd",$culture)
Saturday


$date.Tostring("D",$culture)
Saturday, May 04, 2013


$culture = New-Object System.Globalization.cultureinfo("fr-FR")
$date
samedi 4 mai 2013 09:55:18


$date.Tostring("dddd",$culture)
samedi


$date.Tostring("D",$culture)
samedi 4 mai 2013


Culture List here or in this old cultureinfo Framework information.To play with different pattern culture go to datetimeformatinfo

Friday, January 25, 2013

Disable/Bypass all RDP prompt

There is an article on Microsoft which explain how to remove credentials:
Remote Desktop Connection 6.0 prompts you for credentials before you establish a remote desktop connection http://support.microsoft.com/kb/941641
To resume, edit your default.rdp file (hide file on your "My document" directory" Then add or modify lines using these line
authentication level:i:0
enablecredsspsupport:i:0
But, what about trust computer window ? Each time you connect a new computer you must check "Don't prompt me again for connections to this computer". What a pity that Microsoft
To avoid that problem, I created a "5 minute powershell script" below
#
# Generate registry for RDP Prompt
# 
# by Franck RICHARD 
# 2012 November
#
 
# Script Directory
$strCurDir = Split-Path -parent $MyInvocation.MyCommand.Path
 
# Generate Files
$date_for_file = get-date -format "yyyyMMdd"
 
$Content =  @"
Windows Registry Editor Version 5.00
 
[HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\LocalDevices]
"@ + "`r`n"  
 
$stComputer = Get-Content computer.txt
Foreach ($strLine in $stComputer) {
 If ($strLine.length -gt 0) { # take only line with data and without # at begininng of the line
  If ($strLine.substring(0,1) -ne "#") {
              $Content = $Content + '"' + $strLine.Trim() +'"=dword:0000000d' + "`r`n" 
         }
 }
}

$RegistryFile = "RDP_dontprompttrusted_" + $date_for_file + ".reg"
New-Item $RegistryFile -Type file -Force | Out-Null
$Content | Out-File -encoding ASCII -Append $RegistryFile
You just need a computer.txt file like below with all your computers
computer1
computer2
To generate this file, you can for example use this command (on a server), which generate ALL computers in your AD
dsquery computer -limit 0 -o rdn > domain_computers.txt
or this command for servers only:
dsquery * domainroot -limit 0 -filter "(&(objectCategory=computer)(operatingSystem=Windows Server*))" -attr Name > domain_servers.txt
Powershell file generate a RDP_dontprompttrusted_DATE.reg file you just to run to avoid prompt