Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

Saturday, July 10, 2010

SCCM Client : Reassign Sitecode

Hi Friends,

The below is the script which can be used to assign the sitecode for the SCCM Client PC remotely. There will be a scenario of changing the sitecode in the client computers after implementation of new SCCM server with different sitecode, or may be moving all the users from the earlier SMS to SCCM2007 environment of different sitecode. In this case, we can make use of the below VBScript to change the sitecode in the configuration client (SCCM Client) in all the clients remotely. The below scripts can be deployed using the GPO via Logon Script or using the remote execution of the scripts or even use remote script execution tools. The permission for the execution of the script in the client PC is obvious, for better practice can make use of the same SCCM admin account, which in turn will have the appropriate permission for the script execution.

#######

'replace with your Site Code
sSiteCode = "NEWSITECODE"
sMachine = "."
set oCCMNamespace = GetObject("winmgmts://" & sMachine & "/root/ccm")
Set oInstance = oCCMNamespace.Get("SMS_Client")
set oParams = oInstance.Methods_("SetAssignedSite").inParameters.SpawnInstance_()
oParams.sSiteCode = sSiteCode
oCCMNamespace.ExecMethod "SMS_Client", "SetAssignedSite", oParams

#######

Save the above file with the extension .vbs and replace "NEWSITECODE" with your sitecode accordingly.

Thanks

Logan
logu_microsoft@hotmail.com





Sunday, December 27, 2009

Script for Event log backup and clearing:

The below is the simple script for backing up and clearing the event logs.

###########################################################################################
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Backup, Security)}!\\" _
& strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='Security'")
For Each objLogfile in colLogFiles
OutputFile = "c:\eventlog\" & "Security "
OutputFile = OutputFile & Day(Now) & "-" & month(now) & "-" & year(now)
OutputFile = OutputFile & ".evt"
errBackupLog = objLogFile.BackupEventLog(OutputFile)
If errBackupLog = 0 Or errBackupLog = 183 Then
objLogFile.ClearEventLog()
Else
Wscript.Echo "The Security event log could not be backed up."
End If
Next
###########################################################################################

In the above, you can specify the log file type accordingly and also specify the location where the event log .evt file will be stored. After taking the backup of the event log, it will clear the event log.

Thanks

Logan

971552596187 | logu_microsoft@hotmail.com

Saturday, August 15, 2009

To list the DB size in all mailbox server

This script can be used to list the each database size in the exchange org. This can be easily modified as per your need.

###############################################

# Script for finding all the database size in GB present in the organization.
# please use redirect '<' for reporting# Eg, .\Tofinddbsize.ps1 > report.txt

$exchangeservers = Get-ExchangeServer where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }

foreach ($server in $exchangeservers)
{
$db = Get-MailboxDatabase -server $server
foreach ($objItem in $db)
{
$edbfilepath = $objItem.edbfilepath

$path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)

$dbsize = Get-ChildItem $path $ReturnedObj = New-Object PSObject

$ReturnedObj Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity

$ReturnedObj Add-Member NoteProperty -Name "Size (GB)" -Value ("{0:n2}" -f ($dbsize.Length/1024MB))

Write-Output $ReturnedObj
}
}

###############################################

Thanks

LOGAN

logu_microsoft@hotmail.com 971552596187

To find the disconnected mailbox in the mailbox servers.

This script can be used to find the disconnected mailbox in your exhange organisation by just giving display name as input. This will be helpful if you have many mailbox servers in your org. The below script has been tested and works fine.

###################################################

Write-Host
$search = read-host "Type part of DisplayName Ex Tom* *sson *middle* , searching mailbox servers one by one... "

Write-Host
Write "Press ctrl-C to stop search once you found your mailbox"

$exchangeservers = Get-ExchangeServer where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }

foreach ($server in $exchangeservers)
{

Write-Host
Write "Searching $server"

Get-MailboxStatistics -Server $server where { $_.DisconnectDate -ne $null } where { $_.DisplayName -like "$search" } fl

}

Write-Host
Write "Finished"

################################################

Thanks

Logan

logu_microsoft@hotmail.com 971552596187

Wednesday, August 12, 2009

Find the mailbox count per db in a server

This script can be used to find the mailbox count per database by giving the mailbox server name. This can be modified easily as per your need.

#####################################################

# script for finding the no of mailbox's per mailboxdatabase
write-host $server = read-host "Type the server name:"
foreach ($db in get-mailboxdatabase -server $server)
{
if ($db.getType().fullname -like "*PublicFolderDatabase")
{
$dbType = "Public"
}
else
{
$dbType = "Private"
$dbUserCount = (get-mailbox -database $db -erroraction silentlycontinue).count
}
$retObj = new-object psobject
$retObj add-member noteproperty -name "Server" -value $db.Server
$retObj add-member noteproperty -name "Name" -value $db.Identity
$retObj add-member noteproperty -name "Users" -value $dbUserCount
$retObj
}

#################################################

Please let me know if you have any queastions.

Thanks

Logan
logu_microsoft@hotmail.com 971552596187

Find the mailbox which exceeds the quota limit

The below is the script to find the mailbox in which the mailbox size limit has been exceeded.

##################################################

#Script to find the mailbox which exceeds the quota limit
#in the mailbox server.
Write-host
$server = read-host "Please Enter the Mailbox server name:"
get-MailboxStatistics -server $server where {"IssueWarning","ProhibitSend","MailboxDisabled" -contains $_.StorageLimitStatus} format-Table DisplayName,database,storagelimitstatus,Totaldeleteditemsize,TotalItemSize

###################################################

Thanks

Logan
971552596187