Advertisements

New-PSDrive -Name FK -PSProvider Filesystem -Root D:\PowerShell\ebooks\Workshop1\Files

PS FK:\> ls * -Exclude *.tmp | sort-object length -des | Select-Object -First 10 name,length

Name                                                                                                             Length
—-                                                                                                             ——
hilfe.txt                                                                                                       2578212
Scripting with PowerShell.pptx                                                                                  1589414
Picking a Store Location.doc                                                                                     194560
Manager-Employee Conduct.doc                                                                                     194560
Managing Your Store.doc                                                                                          193024
Reviewing Employees.doc                                                                                          193024
AW Administration Best Practices.doc                                                                             192512
Corporate Management Guidelines.doc                                                                              192000
Mentoring New Managers.doc                                                                                       185344
Equipment Acquisition Training.ppt                                                                               169472

 

PS FK:\> ls * -Exclude *.tmp | sort-object name | Select-Object -First 10 name,length

Name                                                                                                             Length
—-                                                                                                             ——
Annual Meeting – Finance.ppt                                                                                     108032
Annual Meeting – Keynote.ppt                                                                                      65024
Annual Meeting – Travel.ppt                                                                                       43520
Annual Revenue Report.xls                                                                                         32768
arrow 0.png                                                                                                        1806
arrow 1.png                                                                                                        1946
arrow 2.png                                                                                                        2180
arrow 3.png                                                                                                        2371
arrow 4.png                                                                                                        2604
arrow 5.png                                                                                                        2756

PS FK:\> Get-ChildItem | Group-Object extension | Sort-Object count

Count Name                      Group
—– —-                      —–
    1 .xlsx                     {Book1.xlsx}
    1 .pptx                     {Scripting with PowerShell.pptx}
    1 .docx                     {vbscript_to_powershell.docx}
    6 .txt                      {Files1.txt, Files2.txt, get-service-ps1.txt, hilfe.txt…}
    7 .doc                      {AW Administration Best Practices.doc, Corporate Management Guidelines.doc, Manager-…
    9 .ppt                      {Annual Meeting – Finance.ppt, Annual Meeting – Keynote.ppt, Annual Meeting – Travel…
    9 .xls                      {Annual Revenue Report.xls, Customer Base.xls, Employee Birthdays.xls, Equipment Inv…
   40 .tmp                      {~DF45C.tmp, ~DF463.tmp, ~DF4FE9.tmp, ~DF5012.tmp…}
   48 .png                      {arrow 0.png, arrow 1.png, arrow 2.png, arrow 3.png…}

PS FK:\> Get-ChildItem * -include *.tmp,*.temp | Measure-Object length -Maximum -Average -Minimum -sum

Count    : 40
Average  : 43494.4
Sum      : 1739776
Maximum  : 98304
Minimum  : 512
Property : Length

 

Posted by: Preetam | October 17, 2007

Step04-MailboxEnabling

$OUName=read-host “Please enter the OU name in which you need to enable user’s mailboxes”

Write-host “”

Write-host “Below are the Mailbox data base and respective storage group”

Get-MailboxDatabase | Format-List Name,storagegroup

$DBName=read-host “Please enter the SgDB in which you wish to create this mailboxes”

Get-User -OrganizationalUnit $OUName | Enable-Mailbox -Database $DBName

Posted by: Preetam | October 17, 2007

Step03-StorageGroupCreation

$Storagegrp=read-host “Please enter the Storage group name you need to create”

$MBXStorename=$Storagegrp+”MBX”

write-host(“+”*30)

Write-host “”

Write-host “Mailbox store $MBXStorename will be created and automatically mounted for you”

New-storagegroup -name $Storagegrp -server WS03R2EEEXCHLCS | New-MailboxDatabase -Name $MBXStorename

# ============================

$date=get-date

$futdate=$date.addseconds(10)

$towait=$futdate – $date

$waittime=$towait.seconds

while($waittime -gt 0) {

$waittime=$waittime-1

write-host “Warning: Operation is in progress …” -foreground yellow

start-sleep -s 1

#=======================

if($waittime -le 0)

{

if((Get-MailboxDatabase $MBXStorename).databasecreated)

{

write-host “failed to mount database, it is already mounted or was not created” -foreground RED

$waittime=0

}

#=======================

else

{

Mount-Database -Identity $MBXStorename

start-sleep -s 10

Write-Host ” See below if your DB was mounted”

Get-MailboxDatabase -Status | where{$_.mounted -eq $true}

}

}

#=======================

}

Posted by: Preetam | October 17, 2007

Step02-UserCreation

$OUName=read-host “Please enter the OU name in which you wish to create users”

$objUser = [ADSI]”LDAP://localhost:389/dc=contoso,dc=com”

$IndiaOU=[ADSI]”LDAP://localhost:389/ou=$OUName,dc=contoso,dc=com”

if($IndiaOU.true){

$UserDetails=Import-Csv “users.csv”

foreach($UD in $UserDetails) {

$CN=$UD.CN

$SN=$UD.SN

$title=$UD.title

$description=$UD.description

$department=$UD.department

$streetAddress=$UD.streetAddress

$postalcode=$UD.postalcode

$telephoneNumber=$UD.telephoneNumber

$givenName=$UD.givenName

$company=$UD.company

$mail=$UD.mail

$homePhone=$UD.homePhone

$mobile=$UD.mobile

$userPrincipalName=$UD.userPrincipalName

$Samaccountname=$UD.Samaccountname

$Location=$UD.l

$State=$UD.ST

$Indiauser=$IndiaOU.create(“user”,”cn=$cn”)

$Indiauser.Put(“sAMAccountName”,$Samaccountname)

$Indiauser.put(“SN”,$SN)

$Indiauser.put(“Title”,$title)

$Indiauser.put(“Description”,$description)

$Indiauser.put(“department”,$department)

$Indiauser.put(“streetAddress”,$streetAddress)

$Indiauser.put(‘telephoneNumber’,$telephoneNumber)

$Indiauser.put(‘givenName’,$givenName)

$Indiauser.put(‘company’,$company)

$Indiauser.put(‘mail’,$mail)

$Indiauser.put(‘homePhone’,$homePhone)

$Indiauser.put(‘mobile’,$mobile)

$Indiauser.put(‘L’,$Location)

$Indiauser.put(‘ST’,$State)

$Indiauser.put(‘userPrincipalName’,$userPrincipalName)

$Indiauser.setinfo()

$Indiauser.psbase.Invoke(“SetPassword”,”P@ssW0Rd”)

$Indiauser.psbase.InvokeSet(‘Accountdisabled’,$false)

$Indiauser.psbase.CommitChanges()

}

}

else {Write-host “Errr OU doesn’t exist to proceed further, please create one” -foregroundcolor RED}

Posted by: Preetam | October 17, 2007

Step01-OUCreation

$OUName=read-host “Please enter the OU name you wish to create”

$objUser = [ADSI]”LDAP://localhost:389/dc=contoso,dc=com”

$ou=$objUser.create(“organizationalunit”, “ou=$OUName”)

$ou.setinfo()

# ============================

$date=get-date

$futdate=$date.addseconds(5)

$towait=$futdate – $date

$waittime=$towait.seconds

while($waittime -gt 0) {

$waittime=$waittime-1

write-host “Warning: Operation is in progress …” -foreground yellow

start-sleep -s 1

if($waittime -le 0) {

$OUcreated=[ADSI]”LDAP://localhost:389/ou=$OUname,dc=contoso,dc=com”

If($OUcreated.true){

Write-host $OUname OU is created successfully -ForegroundColor “Green”

}

}

}

Posted by: Preetam | May 30, 2007

Cluster KB Article

How to enable User Mode Hang Detection on a server cluster in Windows Server 2003 and in Windows 2000 Server SP4

KB:815267

Listing properties for ‘MUM12PBSEX’:

T  Cluster              Name                           Value

— ——————– —————————— ———————–

M  MUM12PBSEX         AdminExtensions                {4EC90FB0-D0BB-11CF-B5EF-00A0C90AB505}

D  MUM12PBSEX         DefaultNetworkRole             2 (0x2)

S  MUM12PBSEX         Description                    BUM12PBSEXa.Mumbai-group.com – Tuesday, February 27, 2007 : BUM12PBSEXb.Mumbai-group.com – Tuesday, February 27, 2007 :

B  MUM12PBSEX         Security                       01 00 14 80 … (148 bytes)

B  MUM12PBSEX         Security Descriptor            01 00 14 80 … (148 bytes)

M  MUM12PBSEX         Groups\AdminExtensions

M  MUM12PBSEX         Networks\AdminExtensions

M  MUM12PBSEX         NetworkInterfaces\AdminExtensions

M  MUM12PBSEX         Nodes\AdminExtensions

M  MUM12PBSEX         Resources\AdminExtensions

M  MUM12PBSEX         ResourceTypes\AdminExtensions

D  MUM12PBSEX         EnableEventLogReplication      0 (0x0)

D  MUM12PBSEX         QuorumArbitrationTimeMax       120 (0x78)

D  MUM12PBSEX         QuorumArbitrationTimeMin       30 (0x1e)

D  MUM12PBSEX         DisableGroupPreferredOwnerRandomization 0 (0x0)

D  MUM12PBSEX         EnableEventDeltaGeneration     1 (0x1)

D  MUM12PBSEX         EnableResourceDllDeadlockDetection 0 (0x0)

D  MUM12PBSEX         ResourceDllDeadlockTimeout     240 (0xf0)

D  MUM12PBSEX         ResourceDllDeadlockThreshold   3 (0x3)

D  MUM12PBSEX         ResourceDllDeadlockPeriod      1800 (0x708)

D  MUM12PBSEX         ClusSvcHeartbeatTimeout        60 (0x3c)

D  MUM12PBSEX         HangRecoveryAction             3 (0x3)

Posted by: Preetam | May 10, 2007

Disable Automount feature

I came across scenario where I’ve to disable to automount feature of disk available in Windows 2003

There are two option Diskpart (didn’t work for me),mountvol

Just type MountVol at command prompt and see the output
c:\>mountvol
Creates, deletes, or lists a volume mount point.

MOUNTVOL [drive:]path VolumeName
MOUNTVOL [drive:]path /D
MOUNTVOL [drive:]path /L
MOUNTVOL [drive:]path /P
MOUNTVOL /R
MOUNTVOL /N
MOUNTVOL /E

path Specifies the existing NTFS directory where the mount
point will reside.
VolumeName Specifies the volume name that is the target of the mount
point.
/D Removes the volume mount point from the specified directory.
/L Lists the mounted volume name for the specified directory.
/P Removes the volume mount point from the specified directory,
dismounts the volume, and makes the volume not mountable.
You can make the volume mountable again by creating a volume
mount point.
/R Removes volume mount point directories and registry settings
for volumes that are no longer in the system.
/N Disables automatic mounting of new volumes.
/E Re-enables automatic mounting of new volumes.

Possible values for VolumeName along with current mount points are:

\\?\Volume{88491153-c1bd-11db-84b1-806e6f6e6963}\
C:\

\\?\Volume{f2b0b937-c1f7-11db-abb5-000d609d5a44}\
D:\

Lets disable automount

c:\>mountvol /n

Lets check output now, to confirm it has been disabled check the last line

c:\>mountvol
Creates, deletes, or lists a volume mount point.

MOUNTVOL [drive:]path VolumeName
MOUNTVOL [drive:]path /D
MOUNTVOL [drive:]path /L
MOUNTVOL [drive:]path /P
MOUNTVOL /R
MOUNTVOL /N
MOUNTVOL /E

path Specifies the existing NTFS directory where the mount
point will reside.
VolumeName Specifies the volume name that is the target of the mount
point.
/D Removes the volume mount point from the specified directory.
/L Lists the mounted volume name for the specified directory.
/P Removes the volume mount point from the specified directory,
dismounts the volume, and makes the volume not mountable.
You can make the volume mountable again by creating a volume
mount point.
/R Removes volume mount point directories and registry settings
for volumes that are no longer in the system.
/N Disables automatic mounting of new volumes.
/E Re-enables automatic mounting of new volumes.

Possible values for VolumeName along with current mount points are:

\\?\Volume{88491153-c1bd-11db-84b1-806e6f6e6963}\
C:\

\\?\Volume{f2b0b937-c1f7-11db-abb5-000d609d5a44}\
D:\

New volumes are not mounted automatically when added to the system. To mount a
volume, you must create a volume mount point.

« Newer Posts - Older Posts »

Categories