WMI scripts-stop service

Set objSpoolerSvc =GetObject("WinMgmts:Win32_Service.name='Spooler'")
Set objOutParm = objSpoolerSvc.ExecMethod_("stopService")
If objOutParm.returnValue = 0 Then
WScript.Echo " The Spooler Service has been stopped"
Else
wscript.Echo "Error: " & objOutParm.returnValue
End If

WMI scripts-Put method

'WMI is used for getting information about device,registry etc.Some properties of classes may support "write".this example shows how you can set volume label to C Drive.


Set objSvc=GetObject("WinMgmts:")
Set obj=objSvc.Get("Win32_LogicalDisk.DeviceID='C:'")
obj.VolumeName="System"
obj.Put_

WMI scripts-rename multiple files in a folder

This script can rename multiple files in a specific folder.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'You connect to default namespace with moniker method(winmgmt)

Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Logs'} Where " _
& "ResultClass = CIM_DataFile")

'it seems little different.It connects two wmi class in one command.uses Win32_Directory class for retrieving folder ,uses CIM_Datafile for files.Associators of usage connects two class like joining two db table.

For Each objFile In colFileList
strNewName = objFile.Drive & objFile.Path & "ABC-" & _
objFile.FileName & "." & objFile.Extension
errResult = objFile.Rename(strNewName)
Next

'this is very simple you assign new file name to strNewName variable.You can add prefix or suffix in here.

mpio windows core

· As we all know we have only Windows 2008 core installation provides only command
prompt interface. We have to use commands to configure MPIO. First we have to
enable “Multipath I/O” feature and there use MPClaim to clam all applicable
Multipath device. Following are the steps needed for configuring MPIO
o On Core execute “ocsetup MultipathIo /norestart”
o Restart the server
Execute mpclaim -r -i -a “” after reboot. This will reboot the system
automatically. Once the server is back, MPIO will be configured on the server.

Export-Mailbox Command Usage Examples

Export-mailbox -Identity ERKAN_SEZGIN -pstFolderPath D:\PST\

This command will export ERKAN_SEZGIN mail items to the pst file.

Export-mailbox -Identity ERKAN_SEZGIN -TargetMailbox ADMIN -TargetFolder Data

Mail Items will be copied to the Data Folder in another user mailbox

Get-Mailbox -Database DB01 | Export-Mailbox -TargetMailbox ADMIN
-TargetFolder VirusData -SubjectKeywords "mustdelete" -DeleteContent

-StartDate
-EndDate
Note:date parameters depends on your computer regional settings.

-RecipientKeywords erkan.sezgin@contoso.com

Export-Mailbox -Identity contoso\erkan.sezgin -TargetMailbox ADMIN -TargetFolder
MyData -ContentKeywords "bodyContent" -AttachmentFilenames "*FinanceList*" -StartDate
"01/01/2007 00:00:01" -RecipientKeywords userX@contoso.com

This example exports all items from the mailbox user contoso\erkan.sezgin that meet the following criteria:
* Contain the keyword "bodyContent" in the message body or in the content of an
attachments.
* Have an attachments that is named *FinanceList*.
* Are dated later than 01/01/2007 at 00:00:01 A.M.
* Have userX@contoso.com as one of the recipients.

disable DEP permanently

in the boot.ini file

1.Replace the policy_level (for example, "OptOut") with "AlwaysOff” (without the quotes).

Note: Your boot.ini file switch should now read:
/noexecute=AlwaysOff
2.save it and restart your computer

how to filter blank subject mail by using Transport Rule

how to filter blank subject mail by using Transport Rule

1. Click on Transport Rules tab, click button New Transport Rule.

2. Type in the name of the rule, such as "Blank Subject Filter".

3. In the Step 1. Select Condition(s) box, select the when the Subject field
contains text patterns condition. If you want to filter emails with blank subject
or blank body, choose When the Subject field or the body of the message contains
text patterns instead.

4. In the Step 2. Edit the rule description (click an underlined value) box, click
the text patterns blue underlined words. In a pop-up new window, type ^$ and then
click Add. Click OK to close the window and then click Next.

5. In the Step 1. Select Action(s) box, select all the actions that you want to be
applied to this rule.

6. Modify the settings if you want to set Exceptions to this rule in the Exceptions
window. When finished, click OK and click Next. You may choose to exclude internal
emails from this rule.

7. Review the Configuration Summary. If the configuration of the new rule is
correctly set, click New, and then click Finish

Active Directory Tasks by using Powershell

Create OU
$strCL="organizationalUnit"
$strOUName="ou=TestOU"
$objADSI=[ADSI]"LDAP://dc=fabrikam,dc=com"
$objOU=$objADSI.create($strCL,$strOUName)
$objOU.setinfo()

Create User
$strCL="User"
$strName="Cn=Erkan"
$objADSI=[ADSI]"LDAP://ou=TestOU,dc=fabrikam,dc=com"
$objUser=$objADSI.create($strCL,$strName)
$$objUser.Put("sAMAccountName","Erkan")
$objUser.setinfo()

Modify User Properties

$objUser=[ADSI]"LDAP://cn=Erkan,ou=TestOU,dc=fabrikam,dc=com"
$objUser.put("sAMAccountName","Erkan")
$objUser.put("givenName","Sezgin")
$objUser.put("DisplayName","Erkan Sezgin")
$objUser.put("telephoneNumber","216-111-1111")
$objUser.put("mail","erkan.sezgin@fabrikam.com")
$objUser.setinfo()

Other Attributes;
wwwHomePage,description,streetAddress,postOfficeBox,l,st,postalcode,CountryCode
homeDirectory,homeDrive,profilePath,scriptPath,homePhone,title

put what you want,but dont forget the $setinfo() method at the end.

display registry key with Powershell

Get-ItemProperty HKLM:\Software\Microsoft

find last logged on user with Powershell

You can find the last logged on user to any computer

Get-wmiobject Win32_ComputerSystem -Comp "."

If you would,format your result by adding "| Select Name,Username" command.