Wednesday, October 26, 2011

Exchange 2010 Gal Picture Upload Script.

Alright I been working on migrating to Exchange 2010 from Exchange 2007.  Once moved we wanted to upload the pictures for users. You can do this on Exchange 2007 not covered here though.

I made the below script by using multiple source to compile this. Some script I found did something I liked but lacked few things so I went ahead and made my own with all thse things I needed. I am pretty new to Powershell so if you find I can improve then do let me know :)

I added option to check if the picture is already on the user ad attribute to save time. You can disable it if you dont want that. I also used hashtable to keep a log file for successful or failed uploads of pics.

If you have any suggestions to add to this script do let me know :)

You probably need to change Pickup folder location which is $PicFolder

=============Update: 10/11/11===========

I did not explain what this script does cause I thought it was pretty much straight forward cause of comments I added. But anyways I looked at the post today and thought hell it doesn't really say that this can do.

So here it is :- (I listed it in way of execution)

1- Gets users from exchange with get-mailbox | foreach

2- Create and datestamp log files with start of script. (I didnt know how to datestamp each line so had to create it head of execution of script. Maybe someone can help me out with this.

3- Initiate Hashtables for Success Log (Slist) and Failed Log (Flist).

4- For each users found with get-mailbox fetch $alias from it and check $alias.jpg file in pickup folder. If the pic is not there for $alias skip user.

5- Function ChkPic is to check if user has picture already assigned if so skip the user. This is usefull if want to re-run this script with new pictures added to pickup folder. Method used here is Export-RecipientDataProperty with username to see if it shows something. Usually if pic is there it will show RunspaceID in the result. I using that as my ref for pic is there.

6- Check picture file size if its less then or equal to 10k. If bigger than 10k skip user. Otherwise go ahead.

7- So finally we reached here after all that checks YAY. Go ahead and import picture.

8- So you remember that ChkPic (Step 5) I created? we are going to use it again to check if it uploaded the picture successfully. Does the same thing but after uploading. If it finds the pic it says all good otherwise logs it to Flist and displays error.

9- Display information about the logs and location to user.

10- End Script

Please leave a comment cause sometimes I feel that no one is reading this LOL. :p anyways it comes handy for me :)

================ImporToExCh2010=====================
#Pickup folder for pictures.
$PicFolder = "c:\pics"

#Fetch users from Exchange
$results = Get-Mailbox | Foreach {$_.alias}

#DateStamp
$Date=$(Get-Date -format g) | add-content c:\ExPicSuccess.log, c:\ExPicFailed.log

#Using hashtable for logs.
$Slist=@{} #Successful Log file
$Flist=@{} #Failed Log File

#Function to check if pic is in user ad attr
Function ChkPic {
Param ($alias)

#Try to see if user already has pic uploaded
$ChkUpload = Export-RecipientDataProperty -Identity $alias -Picture | out-string

#Match for RunspaceId in result string
$RChk = $ChkUpload -match "RunspaceId"                            }
#End Function ChkPic

Foreach ($alias in $results)
{
$FileLoc = "$PicFolder\$alias.jpg"
$FileExists = Test-path $FileLoc

If ($FileExists -eq $True){
Write-host -f green "`nPicture found for $alias....checking size..."

#Check photo size if its less than 10k
$PhotoSize = Get-ChildItem $FileLoc | select Length

If ($PhotoSize.Length -le 10000) { Write-Host "[Size OK]" -ForeGroundColor Green }
Else {
$Flist.Add($alias, "Pic Size Exceeded 10k - Skipped!")
Write-Host "[Pic Size more than 10Kb..Skipping User!]" -ForeGroundColor Red; Continue}

#Precheck to make sure pic is not assigned. If assigned skip user. (You can disable this)
ChkPic $alias

If ($RChk -eq $True) { Write-Host "User already has picture assigned. Skipping User! `n" -f red;Continue}

#All good going ahead with uploading..
Write-host -f yellow "Uploading..."

#Import Picture to user ad attr
Import-RecipientDataProperty -Identity "$alias" -Picture -FileData `
([Byte[]]$(Get-Content -Path "$FileLoc" -Encoding Byte -ReadCount 0))

Write-Host -f green "Uploaded picture for $alias"
Write-host -f yellow "Checking if uploaded successfully..."

#Calling ChkPic Function
ChkPic $alias
#If statement to see if value is true which means successful and false means pic attr not found.
If ($RChk -eq $True) {
Write-Host -f green "[Uploaded Successfully] `n"

If ($alias) {$Slist.Add($alias, "Successful")}
}
Else {
Write-Host -f red "[Upload Failed]"

$Flist.Add($alias, "Upload Failed.")
}
                          }

Else{
Write-host -f red "Picture not found for $alias in $PicFolder"

If ($alias) {$Flist.Add($alias, "Picture not found.")}
    }
}

Write-Host -f yellow "#Note: Logs files can be found in C: with name of ExPicSuccess.log & ExPicFailed.log `n"

#Add Successful list to log file
$Slist | out-string | add-content c:\ExPicSuccess.log
Write-host -f green "`n Displaying Successful Upload Userlist `n"
$Slist

#Add Failed to log
$Flist | out-string | add-content c:\ExPicFailed.log
Write-host -f red "`n Displaying Failed Upload Userlist `n"
$Flist
=======================================================

Download ps1 from Google Docs

You can download the ps1 incase the copy paste doesnt work. Link provided above

Thursday, October 6, 2011

PowerShell print server inventory script by Michel Stevelmans

Scripts looks very interesting. I haven't tried it but will do that in awhile :)
--------------------------------------------------------------------------------------------
PowerShell script which lists all installed printers and gathers information like the printer name, driver, share name, location and the IP address (the actual IP address, not the portname without the “IP” prefix).




# Print server inventory script
# Created by Michel Stevelmans - http://www.michelstevelmans.com

# Set print server name
$Printserver = "PRINTSERVER"

# Create new Excel workbook
$Excel = new-Object -comobject Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Cells.Item(1,1) = "Printer Name"
$Sheet.Cells.Item(1,2) = "Location"
$Sheet.Cells.Item(1,3) = "Comment"
$Sheet.Cells.Item(1,4) = "IP Address"
$Sheet.Cells.Item(1,5) = "Driver Name"
$Sheet.Cells.Item(1,6) = "Shared"
$Sheet.Cells.Item(1,7) = "Share Name"
$intRow = 2
$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True

# Get printer information
$Printers = Get-WMIObject Win32_Printer -computername $Printserver
foreach ($Printer in $Printers)
{
    $Sheet.Cells.Item($intRow, 1) = $Printer.Name
    $Sheet.Cells.Item($intRow, 2) = $Printer.Location
    $Sheet.Cells.Item($intRow, 3) = $Printer.Comment
    $Ports = Get-WmiObject Win32_TcpIpPrinterPort -computername $Printserver
        foreach ($Port in $Ports)
        {
            if ($Port.Name -eq $Printer.PortName)
            {
            $Sheet.Cells.Item($intRow, 4) = $Port.HostAddress
            }
        }
    $Sheet.Cells.Item($intRow, 5) = $Printer.DriverName
    $Sheet.Cells.Item($intRow, 6) = $Printer.Shared
    $Sheet.Cells.Item($intRow, 7) = $Printer.ShareName
    $intRow = $intRow + 1
}

$WorkBook.EntireColumn.AutoFit()
$intRow = $intRow + 1
$Sheet.Cells.Item($intRow,1).Font.Bold = $True
$Sheet.Cells.Item($intRow,1) = "Print server inventory - Created by Michel Stevelmans - http://www.michelstevelmans.com"

Source : http://www.michelstevelmans.com/powershell-print-server-inventory-script/

Wednesday, October 5, 2011

Control Panel Shortcut




Control Panel Files [CPL's]

File name Purpose
-----------------------------------------------------------------------
Access.cpl Accessibility properties
Appwiz.cpl Add/Remove Programs properties
Desk.cpl Display properties
FindFast.cpl FindFast (included with Microsoft Office for Windows 95)
Inetcpl.cpl Internet properties
Intl.cpl Regional Settings properties
Joy.cpl Joystick properties
Main.cpl Mouse, Fonts, Keyboard, and Printers properties
Mlcfg32.cpl Microsoft Exchange or Windows Messaging properties
Mmsys.cpl Multimedia properties
Modem.cpl Modem properties
Netcpl.cpl or Ncpa.cpl Network properties
Odbccp32.cpl Data Sources (32-bit ODBC, included w/ Microsoft Office)
Password.cpl Password properties
Sticpl.cpl Scanners and Cameras properties
Sysdm.cpl System properties and Add New Hardware wizard
Themes.cpl Desktop Themes
TimeDate.cpl Date/Time properties
Wgpocpl.cpl Microsoft Mail Post Office



How to Start Single Sections of Control Panel With a Command

Control Panel Tool Command
---------------------------------------------------------------
Accessibility Options control access.cpl
Add New Hardware control sysdm.cpl add new hardware
Add/Remove Programs control appwiz.cpl
Date/Time Properties control timedate.cpl
Display Properties control desk.cpl
FindFast control findfast.cpl
Internet Properties control inetcpl.cpl
Joystick Properties control joy.cpl
Keyboard Properties control main.cpl keyboard
Microsoft Exchange control mlcfg32.cpl
(or Windows Messaging)
Microsoft Mail Post Office control wgpocpl.cpl
Modem Properties control modem.cpl
Mouse Properties control main.cpl
Multimedia Properties control mmsys.cpl
Network Properties control netcpl.cpl or ncpa.cpl
Password Properties control password.cpl
PC Card control main.cpl pc card (PCMCIA)
Power Management (Windows 95) control main.cpl power
Power Management (Windows 98) control powercfg.cpl
Printers Properties control main.cpl printers
Regional Settings control intl.cpl
Scanners and Cameras control sticpl.cpl
Sound Properties control mmsys.cpl sounds
System Properties control sysdm.cpl

Wednesday, September 28, 2011

PsTools with Powershell - Remote Execution

So I was tasked to remote execute an exe file on a server.

I wanted to use PowerShell to do the whole thing but ended up using PsTools due to lack of time to explore PowerShell Remote.

I ran into few issue. Basically when I was executing the exe file it wasn't displaying anything to the end user. After doing some research I found that exe was running but on the wrong session. For example I wanted to see the Test.exe GUI logged in as a remote user. But when I executed the psexec it ran the Test.exe in console session id 0. My session id was 2. You can see you session by going to taskmanager and go to users tab. There you will see the session id.

In order for me to see Test.exe GUI I had to specify the session on psexec. But problem was that every time I log into remote desktop I would get a new session id.

So I googled it and found the solution for identifying the session id.

So basically psexec runs a command query session and looks for session id of the user where the app should be displayed. i.e the variable $UserSession

=======================================================================
#Make sure you change the location of PsTools exe files below
#Change following variables for your setup
set-alias psexec 'C:\PsTools\PsExec.exe
$UsersSession = 'ijaved' #Username of the user you want the app to show
$UserAdmin = 'admin' #admin user on the remote pc
$AdminPass = 'test' #pass of admin user
$RemotePc = '\\192.168.1.128' #remote pc
$App ='C:\test.exe' # App to run

#No need to change anything below
$results = & psexec '$RemotePC' -u '$UserAdmin' -p '$AdminPass' query session
$id = $results | Select-String "$UsersSession\s+(\w+)" | Foreach {$_.Matches[0].Groups[1].Value}
$delay = ping 127.0.0.1 -n 2
$call =  & psexec '$RemotePC' -u '$UserAdmin' -p '$AdminPass' -i $id -d '$App'
#End Script
=======================================================================

I found a problem where one of the installer.exe won't run even after being called. It would come up and disappear. After trying to figure out something I got my break. I found that when psexec is executing the installer it is doing so from c:\windows\system32 folder and the installer for some stupid reason was looking for its file inside system32. Don't know why but that was the case.

So I made a batch file which called the installer from its own folder. Basically batch file did the following :-

cd \
cd "c:\installerfolder\"
c:\installerfolder\install.exe

Hope it helps anyone out there.

AutoLogin Win 7 - Shortcut for User Accounts Wizard on Win 7

From run write netplwiz to get User Accounts wizard.

  1. Press the Windows key + R on your keyboard to launch the “Run” dialog box.
  2. Type in netpliz or control userpasswords2
  3. Press Enter. The User Accounts window will display.
  4. Uncheck the option “Users must enter a user name and password to use this computer”
  5. Click “OK”
  6. You will then be prompted to enter the current password and confirm it.
  7. After doing so, you will no longer be prompted to enter your password upon login.

If  Checkbox is no there then

1. Press the Windows key + R on your keyboard to launch the “Run” dialog box.
2. Type regedit and hit enter to open the Registry Editor
3. Then browse to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\
4. Set AutoAdminLogon = 1 (create it if doesn't exist its a string variable)
5. Set DefaultUserName = your username (create it if doesn't exist its a string variable)
6. Set DefaultPassword = your password (create it if doesn't exist its a string variable)

Monday, September 26, 2011

Disable & Enable Services for Mailbox

PowerShell commands to Disable mailbox level services for specificed users. Works well for Microsoft 365 Cloud.

Disable Access to Mailbox

#Set $member to username of the user you wan
$member | Set-CASMailbox -OWAEnabled $false -PopEnabled $false -ImapEnabled $false -MAPIEnabled $false -ActiveSyncEnabled $false -EwsEnabled $false
   
Get-CASMailbox $member | Select-Object Name, OWAEnabled, PopEnabled, ImapEnabled, MAPIEnabled, ActiveSyncEnabled, EwsEnabled

==========================

Enable Access to Mailbox

#Set $member to username of the user you wan
$member | Set-CASMailbox -OWAEnabled $true -PopEnabled $true -ImapEnabled $true -MAPIEnabled $true -ActiveSyncEnabled $true -EwsEnabled $true

Get-CASMailbox $member | Select-Object Name, OWAEnabled, PopEnabled, ImapEnabled, MAPIEnabled, ActiveSyncEnabled, EwsEnabled

Friday, September 23, 2011

Enable / Disable Microsoft 365 ActiveSync service for users.

I am currently working on Microsoft 365 cloud exchange. I want to try out different things which will enable and disable the services for users. I found the below post which stats how to enable and disable ActiveSync for users.

Windows Mobiles can be configured for Active Sync. Active Sync is enabled for all users by Default in Exchange 2007 & 2010.

For Security reasons its recommended to disabled all users and enable only for the required users

Below power shell enabled and disabled Active for all the users in the exchange Organization

get-Mailbox -resultsize unlimited | set-CASMailbox -ActiveSyncEnabled:$False

get-Mailbox -resultsize unlimited | set-CASMailbox -ActiveSyncEnabled:$True

Below powershell command to enable and disable active sync for given set of users in the text file

Get-content C:\users.txt | set-CASMailbox -ActiveSyncEnabled:$True

Get-content C:\users.txt| set-CASMailbox -ActiveSyncEnabled:$False

Source : http://powershell.com/cs/forums/p/2619/3506.aspx

Thursday, September 22, 2011

Microsoft 365 Cloud Remote Management

Alright so I been learning how to play with Microsoft 365. In particular management of Exchange server via “Exchange Management Console” and “Exchange Management Shell aka Powershell”.

I found very amazing tutorial on http://technet.microsoft.com/en-us/edge/Video/hh278971 by Naomi Alpern. I watched the whole thing since it was very interesting. But you if you really want to skip it to fun part then skip it to 20 minutes into to tutorial.

First of install "Exchange Management Tools" from Exchange 2010 Sp1 cd. I downloaded mine off microsoft. Extract the files and run the setup from run. Cmd into the folder where exchange 2010 sp1 setup file is located and write "setup /R:MT"

To configure Exchange Management Console do the following steps:-

·         From the “Exchange Management Console” right click on “Microsoft Exchange” and click on “Add Exchange Forest…”

·         You will be prompted with the below dialog box. In “Specify a friendly name for this Exchange forest”. Write whatever is easy to remember for you. I put mine as “Exchange Online”. After that make sure you select “Exchange Online” from the drop down menu of “Specify the FQDN or URL of the server running the Remote PowerShell instance:” Click “OK” and it will ask you for the username and password for your Microsoft 365 account.
·         After you put in your username and password it will refresh the EMC and if it accepts the credentials it will list your exchange forest in the list.

That was the "Exchange Management Console" connection settings. Now for "Exchange Management Shell (PowerShell)"

To connect through PowerShell use the following script
========================================
Set-ExecutionPolicy unrestricted
#Ask for credentials
$cred = Get-Credential
#Setup a powershell session to the Exhcange online server
$O365 = New-PSSession -ConfigurationName Microsoft.Exchange –ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic –AllowRedirection
#Import the cmdlets to your local computer
$importcmd = Import-PSSession $O365
=============================================

Update : Someone asked me to automate the username and password. So here's the script with username & password already added :-

=============================================
Set-ExecutionPolicy unrestricted
#Change to your username of microsoft 360 below
$userName = "username@domain.onmicrosoft.com"
#Change yourpasswordhere with your password
$passWord = ConvertTo-SecureString "yourpasswordhere" -Force -AsPlainText
$cred = New-Object System.Management.Automation.PSCredential($userName, $passWord)
$O365 = New-PSSession -ConfigurationName Microsoft.Exchange –ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic –AllowRedirection
$importcmd = Import-PSSession $O365
========================================
The above will connect you to your online cloud exchange server. You can test it out by running exchange commands. get-mailbox or anything else.

That pretty much sums it up. Not much different from your local exchange server. Do keep in mind there are few settings not visible on cloud exchange server since its running multiple clients setup (hosted exchange setup).

Windows Registry

*-*-*-*-*-*-*-*-*-*-*-*-*-*Warning*-*-*-*-*-*-*-*-*-*-*-*-*-*

Don’t ever change a value in the registry. Ever. We know we just told you to do that, but would you jump off a cliff if we told you to? Don’t ever change a value in the registry. Don’t even say the word registry. We know a guy once who said the word registry, and three days later he was hit by a bus. True story. As a matter of fact, you shouldn’t even have a registry on your computer. If you suspect that you do have a registry on your computer, please call us and a trained professional will be dispatched to your office to remove the registry immediately. If you accidentally touch the registry, wash your hands with soap and water and call a doctor. Do not swallow the registry or get it in your eyes!

Wednesday, September 21, 2011

Windows 7 Shortcut

Windows 7
The → symbol stands for the right arrow key, ← for the left arrow key, etc.


Win+ Maximize the current window
Win+ If the current window is maximized, restore it; if the current window is restored, minimize it
Win+ Dock the current window to the left half of the screen
*If it is already docked left, it is moved to the right half of the screen
*If it is already docked right, it is restored to its original size
Win+ Dock the current window to the right half of the screen
*If it is already docked right, it is moved to the left half of the screen
*If it is already docked left, it is restored to its original size
Win+Shift+ Move current window to the left monitor (with dual monitors)
Win+Shift+ Move current window to the right monitor (with dual monitors)
Win+Home Minimize all but the current window
Win+Space Peek at the desktop
Win+[Plus sign] Zoom in
Win+[Minus sign] Zoom out
Win+P Open the projection menu (generally used for laptops connected to projectors)
Alt+P In Explorer, show/hide the preview pane


Taskbar Modifiers (New in Windows 7)



Shift+Click Open a new instance of the program
Ctrl+Click Cycle between windows in a group
Middle Click Open a new instance of the program
Ctrl+Shift+Click Open a new instance of the program as Administrator
Shift+Right-Click Show window menu


Managing Windows



Alt+F4 Close the active window
Alt+Tab Switch to previous active window
Alt+Esc Cycle through all open windows
Win+Tab Flip 3D [more info]
Ctrl+Win+Tab Persistent Flip 3D
Win+T Cycle through applications on taskbar (showing its live preview)
Win+M Minimize all open windows
Win+Shift+M Undo all window minimization
Win+D Toggle showing the desktop
Win+ Maximize the current window
Win+ If the current window is maximized, restore it; if the current window is restored, minimize it
Win+ Dock the current window to the left half of the screen
*If it is already docked left, it is moved to the right half of the screen
*If it is already docked right, it is restored to its original size
Win+ Dock the current window to the right half of the screen
*If it is already docked right, it is moved to the left half of the screen
*If it is already docked left, it is restored to its original size
Win+Shift+ Move current window to the left monitor (with dual monitors)
Win+Shift+ Move current window to the right monitor (with dual monitors)
Win+Home Minimize all but the current window
Win+Space Peek at the desktop
Win+[Plus sign] Zoom in
Win+[Minus sign] Zoom out


Starting Programs



Win+1 Open the first program on your Quick Launch bar
Win+2 Open the second program on your Quick Launch bar
Win+n Open the nth program on your Quick Launch bar
Win+U Open the ease of access center
Win+F Open the search window
Win+X Open the Mobility Center
Win+E Open Explorer
Win+R Open the Run window [more info]
Win+B Move focus to notification tray (the right-most portion of the taskbar)
Win+P Open the projection menu (generally used for laptops connected to projectors)
Win+Pause Open the System Properties portion from the Control Panel
Ctrl+Shift+Esc Open Windows Task Manager


Logging In And Out


While the below shortcuts seem unwieldy because of their length, they're quite easy to remember once you try them out a few times.


Win, , Enter Shutdown
Win, →, →, R Restart
Win, →, →, S Sleep
Win, →, →, W Switch Users
Win+L Locks computer


Viewing Folders With Explorer



Alt+ Go back
Alt+ Go forward
Alt+ Go up a directory
Alt+D Move focus to address bar
Alt+D, Tab Move focus to search bar
Alt+Enter Open the Properties window of the current selection
Ctrl+Mousewheel Change the view type (extra large, small, list view, detail, etc.)
Alt+P Show/hide the preview pane

Tuesday, September 13, 2011

Useful Net commands - Don`t need admin rights to run these.

I just love using Net commands to get list of users or password expiry dates for users.

Run the following command to get all the data for that specific user on domain

  • net user username /domain

Result :-

C:\Users\ijaved>net user ijaved /domainThe request will be processed at a domain controller for domain test.local.
User name                    ijaved
Full Name                    i Javed
Comment
User's comment
Country code                 000 (System Default)
Account active               Yes
Account expires              Never
Password last set            04/07/2011 9:14:48 AM
Password expires             02/10/2011 9:14:48 AM
Password changeable          04/07/2011 9:14:48 AM
Password required            Yes
User may change password     Yes
Workstations allowed         All
Logon script
User profile
Home directory
Last logon                   13/09/2011 5:03:59 PM
Logon hours allowed          All
Local Group Memberships
Global Group memberships     *Employees            *Domain Users
The command completed successfully.

  • net group /domain
This will list all the groups in your domain.

  • net group "groupname" /domain
This will list users inside specified group name.

* I love these commands because they do not require admin rights. You can run them as normal users and still get the useful information you probably didn`t have access to :)

Additional Commands can be found at : http://www.petri.co.il/list_all_users_and_groups_in_domain.htm

Friday, September 9, 2011

Windows 7 / 2008 shortcut for settings

I hate clicking my way to network settings so found the shortcut.. from run write ncpa.cpl that will open network connections.

Also you can open firewall settings by opening firewall.cpl from run.

So here's the quick list :-

Network Connections = ncpa.cpl
Firewall Settings = firewall.cpl
Device Management = devmgmt.msc
Disk Management = diskmgmt.msc
Services = services.msc
Remote Desktop client = mstsc

 If you know any good ones please leave a comment and I will add it up in ths list :)

Export GAL details to CSV

CSVDE -f GalDump.csv -r objectCategory=person -l "displayName, title, telephoneNumber, department, mail"

Works on Windows 2008 R2 Server with AD. Might come in handy to make SharePoint Contact list by importing this csv.

It exports to the same folder you are in on cmd. Filename will be GalDump.csv

Source: http://smtp25.blogspot.com/2010/05/how-to-dumpexport-gal-to-csv-file.html

Wednesday, August 31, 2011

Changing authentication mode for Sql Server express edition

One way of doing it is through sql server management studio explained over here

http://msdn.microsoft.com/en-us/library/ms188670.aspx

But if you haven’t installed the management studio than in that case you need to make following change in the registry

HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Microsoft SQL server / MSSQL.1/ MSSQLSERVER/ LoginMode

Click on it change it’s value from 1 to 2.

Then Restart your sql server service !!!

After you have done this you need to enable you sa account for sql server authentication for this follow these steps

1) Open SQL Server Management Studio Express and Login
2) In Object Explorer, click Security followed by Logins
3) Right click sa user and select Properties.
4) Uncheck Enforce password policy
5) Select Status. Click the Grant and Enabled radio buttons. Click OK
6) Restart your database server and select restart.

That’s it

Source : http://nishantrana.wordpress.com/2009/01/07/changing-authentication-mode-for-sql-server-express-edtion/

Tuesday, August 30, 2011

PsTools - Executing Program on a remote windows 7 machine.

I could execute the program but it was running in the background. After troubleshooting figured out that you need to put the sessionid to make sure it displays for the user.

psexec -s -d -i 2 \\win7vm -u "ijaved" -p "***"  "calc.exe"

The number 2 above identified my session which was RDP. You can find the sessionid via taskmanager.

WMIC - Usefull Commands



Update static IP address wmic nicconfig where index=9 call enablestatic("192.168.16.4"), ("255.255.255.0")

Change network gateway wmic nicconfig where index=9 call setgateways("192.168.16.4", "192.168.16.5"),(1,2)

Enable DHCP wmic nicconfig where index=9 call enabledhcp

Service Management wmic service where caption="DHCP Client" call changestartmode "Disabled"

Start an application wmic process call create "calc.exe"

Source : http://blogs.technet.com/b/jhoward/archive/2005/02/23/378726.aspx

Thursday, August 25, 2011

Disable IPv6 on Win 7 / Windows Server 2008 via cli (cmd)

Run the following command in cmd and that will do the trick. Make sure you open cmd with "Run As Administrator".

reg add hklm\system\currentcontrolset\services\tcpip6\parameters /v DisabledComponents /t REG_DWORD /d 255

Wednesday, August 24, 2011

VirtualBox - Physical to Virtual Machine - P2V

Usually I use Windows System Image Backup on Windows 7 to make a *.vhd of the physical machine and move it to VirtualBox and fire it up. That works fine.

Life is never easy. So I was given a task to migrate Xp Physical machine to VirtualBox. Xp doesn't have Windows System Image option so I was stuck.

I found Disk2Vhd which did the trick. All I had to do is boot the xp machine up and run the software and it created a vhd. Took few hours but end result was awesome.

All I had to on VirtualBox was to create new machine select the existing hard drive and point it to vhd(vhd created by Disk2Vhd) and boot it up.

Gotcha : Only works for Windows OS
Source : http://www.sysprobs.com/virtualbox-p2v-disk2vhd-errors-fix

Update :

Alrite I wanted to share problem i faced when running virtualbox vm(p2v) on optiplex 960. Xp won’t boot and kept on giving me bluescreens.

I ran the same VM on optiplex 780 and it worked fine and booted without a problem. So it was hardware based issue with 960 model.

After wasting 2 hours toggling with options and google i found the solution :-

1- Make sure in VM Settings (System / Processor – The option for Extended Features: Enable PAE/NX) is enabled.

2- From XP Safe Mode (Yes VM boots into Safe Mode) run this command from CLI “sc config intelppm start= disabled”

Tuesday, August 23, 2011

Increase Virtualbox Hard Drive Space

You can increase VirtualBox Version 4+ hard drive size by using command line.

Use the following command from Program Files folder:-

"VBoxManage.exe modifyhd "location of virtual drive.vdi" --resize 25000(new size in mb)

Example :-

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "C:\VM\Windows 7 x64\Windows 7 x64.vdi" --resize 25000
Result will look like the following :-

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

That should expand the drive size but you have to increase the partition size from the OS.

Note: If you have snapshots then you have to delete them otherwise this won't work. I am trying to figure out if we can do without deleting the snapshots. I got some very clean snapshots which I don't want to lose.
Source : http://www.my-guides.net/en/content/view/122/26/

Monday, August 22, 2011

Enable Remote Desktop via WMIC CLI

Got a call from employee who called in sick and wanted to remote desktop to his machine. He did not enable the "allow remote desktop to this machine" and could not remote desktop to his machine. One of the request was "do not log me out cause I have unsaved document opened".

Had two solution.
  1. Log him off and say tough luck
  2. Reset his password to a default one and login as him/her and enable it. (Good solution if you ask me)
  3. Find a better solution! and I did and WMIC came to the rescue.
Source : http://www.vedivi.com/support/blog/71-how-to-enable-remote-desktop-programmatically.html
I had some experience with WMIC and I knew it probably had something which can do just that and finally found the above post explaing different ways to run WMIC command to enable Remtoe Desktop. I am only interested in enabling remote desktop access to remote pc. So here's the command I have to play around with :-
  • To verify if its enable or disabled use :-
wmic /node:"RemoteServer" /user:"domain\AdminUser" /password:"password"
RDToggle where servername="RemoteServer" get AllowTSConnections

  • To enable Remote Desktop Access
wmic /node:"RemoteServer" /user:"domain\AdminUser" /password:"password"
RDToggle where servername="RemoteServer" call SetAllowTSConnections 1


I used FQDN for 1st RemoteServer and used ComputerName for 2nd RemoteServer.

So before playing with our production server. I fired my test lab which is Win 2008 R2 Sp1 and Client Win 7 Pro.

From the Server I tried :-

C:\Users\Administrator>wmic /node:"testpc.plab.local" /USER:"plab\administrator" RDTOGGLE WHERE ServerName="testpc" CALL SetAllowTSConnections 1
That gives you a prompt to input password for the administrator

Enter the password :********
Executing (\\TESTPC\ROOT\CIMV2\TerminalServices:Win32_TerminalServiceSetting.ServerName="TESTPC")->SetAllowTSConnections()

Method execution successful.


Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 0;
};

In the output above look for "Method execution sucessful". If your Firewall is enabled on the Client PC then you will get RPC Service Unavailable. I turned my off after getting the error.
So basically this script works successfully on Win 2k8 R2 (Server) and Win7 (Client).

Thursday, August 18, 2011

SharePoint Document Library - Hyperlink

Sometimes you have external content that you would like to make available from your document library without uploading a file. Examples include documents in other SharePoint sites or libraries, and even links to other web pages including SharePoint pages and external web sites.

Turns out SharePoint already has this built-in, just well hidden. There is a built-in Content Type called "Link to a Document". Just add this to your library and then just click the "New" dropdown and select "Link to a Document"! It will simply ask you for a document name and url. You can supply a URL to anything that starts with "http://", including both SharePoint documents and external web pages. It does not support a link to a network share such as "\\myfileserver\folder1\somedoc.doc".
  1. Display your library (Example: Shared Documents)
  2. Click Settings and Library Settings
  3. Click Advanced Settings
  4. Check "Allow management of content types" and then OK
  5. In the Settings page scroll down to Content Types and click "Add from existing site content types"
  6. Select "Link to a Document", click Add and then Click OK
  7. Go back to your library and click the New dropdown and select "Link to a Document"
  8. Enter a display name (Document Name) and the URL (must start with http://) and click OK
Source : http://techtrainingnotes.blogspot.com/2007/08/sharepoint-adding-hyperlinks-to-doc.html

    Tuesday, August 16, 2011

    Manage Virtual Machines Remotely With Hyper-V Manager and Windows 7


    Download the above files and make a folder on Server with a Share (UNC Path i.e. \\pcname\share\) and add the required files hvremote.wsf and the Windows6.1-KB958830-x64-RefreshPkg.msu or Windows6.1-KB958830-x86-RefreshPkg.msu to the shared folder. Make two batch files :-
    1-) HyperVbatchClient.bat

    With following commands with-in :-
    cscript "\\pcname\shared\hvremote.wsf" /mmc:enable

    DISM.exe /Online /NoRestart /Enable-Feature /FeatureName:"RemoteServerAdministrationTools-Roles" /FeatureName:"RemoteServerAdministrationTools" /FeatureName:"RemoteServerAdministrationTools-Roles-HyperV" 

    2-) HyperVbatchServer.batWith following commands with-in :-
    @echo off
    echo
    \\\\\\\\\\\\\\\\---------->Enter Details<----------////////////////
    echo Domain Name or PC Name:
    set /p Domain=
    echo Username:
    set /p UserName=
    cscript "\\pcname\shared\hvremote.wsf" /add:%Domain%\%UserName%


    Now run HyperVbatchClient on client after installing the msu file.
    And then on Server run

    HyperVbatchServer.bat which will ask you for domain or pc name of the server hosting hyper-v and username of the user you want to give access to.

    Hope this helps someone out there.


    Source: http://technet.microsoft.com/fr-fr/library/ee256062(WS.10).aspx

    Oracle VM Virtualbox - Remote Administration

    Been looking for a solution to remote manage Virtualbox vm's. After searching found the right solution :) phpVirtualBox - http://code.google.com/p/phpvirtualbox/

    Easy to install & configure. Had few issues with console window being greyed out and to fix that had to install virtualbox extension pack.

    Steps :-
    1- Download install Xamp
    2- Download and unzip phpVirtualbox in c:\Xamp\htdocs\ (I dumped mine in virtualbox folder)
    3-Change config.php-example to config.php and edit following:-
    • /* Username / Password for system user that runs VirtualBox */
      • Here put in username for the user which is logged into Virtualbox Host Machine. Since I was on domain I tried putting username as "domain\ijaved". However, that does not work so just strip the domain keep username only. i.e. ijaved
        Put password in the password field.
    • /* SOAP URL of vboxwebsrv (not phpVirtualBox's URL) */
      • Here you put the ip address of the VirtualBox host server. You have to run VboxWebSrv.exe on that server in able to connect to the server.
    • // Host / ip to use for console connections
      • Here give the ip address of the VirtualBox host server.
    Install VirtualBox extension pack on the VirtualBox host server to make sure you can use the console. Restart both VirtualBox host and Xamp server just to make sure.. mine didnt work without restart.

    Now you should point to the Xamp server ip address with /virtualbox (should be same folder name you used to unzip)

    Default username and password is admin / admin. You can change it if you want in the config.php file.

    You should be able to see your host and virtual machines once you log in.

    I haven't tried multiple server configuration yet. But when I do I will let you guys know.

    JI