User Tools

Site Tools


wiki:microsoft-os-and-applications


Wiki

Microsoft OS and Applications

Typical commands and tasks helpfull using Microsoft systems and applications.

Exchange 2007

Default Email Address Policy

Set-EmailAddressPolicy -EnabledEmailAddressTemplates 'smtp:%m@domain.local','SMTP:%g.%s@domain.com','smtp:%g.%s@domain2.com' -identity 'Default Policy'
Update-EmailAddressPolicy -Identity "Default Policy"

domain.com is the default address.

Global Address List

Update the list:

Update-GlobalAddressList -Identity "Default Global Address List"

SMTP relay

Configure a dedicated SMTP connector and allow relay on that using:

Get-ReceiveConnector "%NAMEOFCONNECTOR%" | Add-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "ms-Exch-SMTP-Accept-Any-Recipient"

French version:

Get-ReceiveConnector "%NAMEOFCONNECTOR%" | Add-ADPermission -User "AUTORITE NT\ANONYMOUS LOGON" -ExtendedRights "Ms-Exch-SMTP-Accept-Any-Recipient"

Exchange 2010

Enable Administrator Mailbox

Since you’re not able to see Administrators mailbox in EMC. You can try from EMS running

Get-Mailbox –Identity <AdministratorsAlias> | fl

and see if you have exchange attributes for administrator account such as ProxyAddress, homeMDB, mail, mailNickname etc..

Disable-Mailbox -Identity %ADMINISTRATORALIAS%
Clean-MailboxDatabase %MAILBOXDBNAME%

Now try to enable or create mailbox for administrator account you will be able to see the administrator account in Existing users Add list.

Mailbox Size

Get-MailboxDatabase "%MAILBOXDBNAME%" | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, itemcount

Move Exchange 2003 Public Folders to Exchange 2010

From the Exchange 2010 server:

.\AddReplicaToPFRecursive.ps1 -server "%EXCHANGE2010SERVER%" -TopPublicFolder "\" -ServerToAdd "%EXCHANGE2010SERVER%"
.\MoveAllReplicas.ps1 -Server "%EXCHANGE2003SERVER%" -NewServer "%EXCHANGE2010SERVER%"

Debugging:
To view a list of the replicas in the public folder hierarchy:

Get-PublicFolder -recurse |fl name,replicas

For System Folders:

Get-PublicFolder -recurse \non_ipm_subtree |fl name, replicas

To compare content replicated between the source and destination servers:

Get-PublicFolderStatistics

MSSQL

Backup Database With Script

sqlcmd  -S %SERVER%\%INSTANCENAME% -Q "BACKUP DATABASE [%DBNAME%] TO  DISK = N'%PATHANDFILENAME%.bak' WITH NOFORMAT, NOINIT, NAME = N'%DBNAME Full Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"

Backup Database With SQL Command

BACKUP DATABASE %DBNAME% TO DISK = '%PATHANDFILENAME.bak'

Change DB File Location

use master
go
Alter database %DBNAME% modify file (name = tempdev, filename = '%FILELOCATION%\%DBNAME%.mdf')
go
Alter database %DBNAME% modify file (name = templog, filename = '%FILELOCATION%\%DBNAME%.ldf')
go

CleanCheck

dbcc checkdb ('%DBNAME%') WITH ALL_ERRORMSGS

Get all current connections

sp_who;

Get all Databases Informations

SQL SERVER 2005:

EXEC Sp_dtabases;
EXEC Sp_helpdb;

SQL SERVER 2000 - still works in SQL Server 2005:

SELECT name FROM sys.databases
SELECT name FROM sys.sysdatabases

SQL Unofficial:

EXEC sp_msForEachDB 'PRINT "?"'

Get all Tables Size

exec sp_MSforeachtable @command1="print '?' exec sp_spaceused '?'"
SELECT 
    t.NAME AS TableName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, p.Rows
ORDER BY 
    UsedSpaceKB

Get variables

select * from sys.dm_exec_sessions where session_id = @@SPID

Informations about databases

sp_helpdb;

Kill a current connection

kill <spid>;

List databases

select name from sys.databases;

Recovery database from "Restoring" status

RESTORE DATABASE %DBNAME% WITH RECOVERY

Repair Database

USE master;
GO
ALTER DATABASE OLFWeb
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
dbcc checkdb ('OLFWeb', REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS
ALTER DATABASE OLFWeb
SET MULTI_USER;
GO

Restore database

RESTORE FILELISTONLY FROM DISK = 'd:\backupfile.bak'
RESTORE DATABASE %DBNAME% FROM DISK = 'drive:\backupfile.bak' 
with MOVE '%ORIGINALDBDATANAME%' to 'drive:\dbfile.mdf', 
MOVE '%ORIGINALDBLOGNAME%' to 'drive:\dblogfile.ldf', replace

Update logical name:

alter database %DATABASE% MODIFY FILE (NAME=%OLDLOGICALFILENAME%",NEWNAME=%NEWLOGICALFILENAME%")

Trunkate logs mssql database

use <dbname> DUMP TRANSACTION <dbname> WITH TRUNCATE_ONLY DBCC SHRINKFILE (2, 10);

On MSSQL 2k8:

USE %DBNAME%;
DBCC SHRINKFILE(%DBLOGLOGICALNAME%,1);

To get %DBLOGLOGICALNAME%:

USE %DBNAME%;
select name from sys.database_files;

If Full recovery model:

USE %DBNAME%;
GO
ALTER DATABASE %DBNAME%
SET RECOVERY SIMPLE;
GO

DBCC SHRINKFILE (%DBLOGLOGICALNAME%, 1);

ALTER DATABASE %DBNAME%
SET RECOVERY FULL;
GO

Trunkate tempdb database files

Start in single-user mode:

Stop MSSQL server service and run it in single mode:

sqlservr -c -f

Set the file size:

ALTER DATABASE tempdb MODIFY FILE
   (NAME = 'tempdev', SIZE = %NEWSIZE%) 
ALTER DATABASE tempdb MODIFY FILE
   (NAME = 'templog', SIZE = %NEWSIZE%)

Exit single-user mode and restart the MSSQL service

Outlook

Diag Connection To Exchange

outlook /rpcdiag

Reset Default Folders Language

outlook /resetfoldernames

Windows

Tools alias

Users Management

netplwiz

General

Disable Hibernation

powercfg -h off

Interrupts Statistics

kernrate -s 10

Hardware Management

Delete Disconnected Hardware

Go in command prompt and do the following:

set devmgr_show_nonpresent_devices=1
devmgmt.msc

Select View > Show Hidden Devices
Expand the Network Adapters tree
Right-click the dimmed network adapter, and then select Uninstall

Manage Hardware From Prompt

Use the DevCon tool from Microsoft Knowledge Base: 311272 (http://support.microsoft.com/kb/311272/en-us)

Installation Folder Cleanup

msizap.exe G!

msizap.exe is in bin directory of Windows SDK or Platform SDK

Power management

To full disable hibernate function:

powercfg.exe /h off

Scripting

Allow PowerShell Scripts

Get-ExecutionPolicy
Set-ExecutionPolicy unrestricted

Delete old files

forfiles /p "%DELPATH%" /s /m *.* /d -%DAYS% /c "cmd /c del @path"

Remplace Slash by Backslash

set tmp=%*
set tmp=%tmp:/=\%
echo %tmp

Test tcp connection with powershell

Test-NetConnection -Port %PORT% -computer %HOSTNAME%

ServicePack cleanup manager

To delete unnecessary SP files after install of SP1:

cd c:\Windows\System32\
compcln.exe

To delete recovery of updates:

compcln.exe

Terminal Server Install/Execute mode

change user /INSTALL
change user /EXECUTE

Windows Update svchost CPU usage

net stop "Windows update"
DISM.exe /Online /Cleanup-image /Restorehealth
net start "Windows update"

ToDo

W32tm /config /manualpeerlist:peers /syncfromflags:manual /reliable:yes /update 
net stop w32time
net start w32time

Check synchro:

w32tm /stripchart /computer:%HOSTNAME%

Service tag dell

wmic bios get serialnumber

Reset attributes attrib -s -h -r “C:\Users\exampleusername”

Display open files:

Openfiles /Query

WSUS: Purge / Delete corrupted or Un-needed patches on WSUS Server WSUSDebugtool /tool:purgeunneededfiles

New-RoutingGroupConnector -Name “2010-2003” -SourceTransportServers “Ex2010Hub1.contoso.com” -TargetTransportServers “Ex2003BH1.contoso.com” -Cost 1 -Bidirectional $false -PublicFolderReferralsEnabled $true New-RoutingGroupConnector -Name “2010-2003” -SourceTransportServers “Ex2003BH1.contoso.com” -TargetTransportServers “Ex2010Hub1.contoso.com” -Cost 1 -Bidirectional $false -PublicFolderReferralsEnabled $true

Get-RoutingGroupConnector| FL

pstools \ psexec

for /f "eol=; tokens=1" %%N in (directories.txt) do cacls.exe "d:\data\users\%%N" /T /E /G DOMAIN\%%N:F >> c:\temp\subinacllog.txt
ROBOCOPY.exe \\SERVER\f$\PATH D:\LOCALPATH /e /zb /copyall /r:1 /w:1 /purge /LOG:c:\temp\robocopy.txt

http://www.sqldbpros.com/2010/11/sql-server-rebuild-indexes-the-fastest-way/

web.config connectionStrings encryption:

cd c:\windows\Microsoft.Net\framework\v4.0.XXXX

Encrypt

aspnet_regiis -pef "connectionStrings" "D:\webistes\leDossierDuSiteContenantLeFichierACrypter"

Decrypt

aspnet_regiis -pdf "connectionStrings" "D:\webistes\leDossierDuSiteContenantLeFichierADérypter"

Display IIS worker processes PID %windir%\system32\inetsrv\appcmd list wp

Dump disk or pen drive:

dd.exe --progress if=\\.\Volume{0b1a0cbe-11da-11c0-ab53-003045c00008} of=pendrive.img bs=4096

Check IOPS and accessed files: resmon.exe

wiki/microsoft-os-and-applications.txt · Last modified: 2024/01/15 14:43 by ach