1. Create an AD Universal Group, "Import Export Admins" for example.
2. Add the account that will run the shell command to this group.
3. New-ManagementRoleAssignment -Name "Import Export Admins" -SecurityGroup Import Export Admins" -Role "Mailbox Import Export"
4. Get-mailbox -server "SERVERNAME" | Search-Mailbox -SearchQuery 'Subject: "INSERT SUBJECT HERE"',"Received:11/13/2014" -targetmailbox "RecoveryMailbox" -targetfolder "SearchResults" -logonly -loglevel full
TargetMailbox is any mailbox that you want the log results to go into.
TargetFolder is the folder that will be created in the mailbox with the results.
The above command will only output the log to the mailbox with an attached CSV file. Nothing is deleted yet. Review the file and proceed with the next step if all results are acceptable.
5. Get-mailbox -server "SERVERNAME" | Search-Mailbox -SearchQuery 'Subject: "INSERT SUBJECT HERE"',"Received:11/13/2014" -targetmailbox "RecoveryMailbox" -targetfolder "SearchResults" -loglevel full -DeleteContent
The above command will create a "User, Name - Date" subfolder under the TargetFolder for every mailbox it accessed to delete the file. It will also leave a copy of the deleted message in these folders for review. Make sure if doing this that the mailbox has sufficient size. If the size of the mailbox is exceeded, the command will fail with an error about exceeding a condition.
If having a copy is not necessary, the following command can be run instead:
Get-mailbox -server "SERVERNAME" | Search-Mailbox -SearchQuery 'Subject: "INSERT SUBJECT HERE"',"Received:11/13/2014" -DeleteContent
Thursday, 13 November 2014
Thursday, 16 August 2012
Useful little script for querying uptime of list of servers
Combine with Microsoft's uptime.exe (http://support.microsoft.com/kb/232243)
for /f "tokens=* delims= " %%a in (server.txt) do (
uptime.exe %%a >> results.txt
)
Friday, 29 June 2012
Convert KMS Host to Client
Converting KMS Host to Client
Windows 7 & Server 2008 R2 volume license copies both come with KMS Client keys installed by default. These are also obtainable from here: http://technet.microsoft.com/en-us/library/ff793421.aspx
If a server is accidentally activated with the KMS host key, it can be changed back via:
slmgr.vbs -ipk xxxx-xxxx-xxxx-xxxx-xxxx (replace x's with the OS specific KMS key from the above site)
To check the status of the existing key on the server, run: slmgr.vbs -dlv
The "Description" should list VOLUME_KMSCLIENT channel. If the server was activated with a KMS host key, it will show VOLUME_KMS_B channel and below will also state "Key Management Service is enabled on this machine"
Windows 7 & Server 2008 R2 volume license copies both come with KMS Client keys installed by default. These are also obtainable from here: http://technet.microsoft.com/en-us/library/ff793421.aspx
If a server is accidentally activated with the KMS host key, it can be changed back via:
slmgr.vbs -ipk xxxx-xxxx-xxxx-xxxx-xxxx (replace x's with the OS specific KMS key from the above site)
To check the status of the existing key on the server, run: slmgr.vbs -dlv
The "Description" should list VOLUME_KMSCLIENT channel. If the server was activated with a KMS host key, it will show VOLUME_KMS_B channel and below will also state "Key Management Service is enabled on this machine"
Tuesday, 22 November 2011
Server 2008 - Remotely adding/removing users from Groups
runas /user:domain\username "psexec \\server net localgroup test domain\username {/add or /delete}"
Monday, 14 November 2011
Remotely installing SNMP on Server 2008
1. On one server, install SNMP 2008 (C:\ocsetup SNMP), configure the service and export HKLM\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ to C:\snmp.reg
2. Create a batch file that will a). import the key exported from step 1. b). delete the 1 value which needs to be removed to allow 'Any host' to connect to the SNMP service.
reg import C:\snmp\snmp.reg
reg delete HKLM\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers /v 1 /f
3. Copy these files to all of the servers via this script (make sure to create the C:\computers.txt and populate):
Const ForReading = 1
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\computers.txt")
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
strRemoteFile = "\\" & strComputer & "\C$\snmp.reg"
objFSO.CopyFile "C:\snmp\snmp.reg", strRemoteFile, OverwriteExisting
Loop
4. Use psexec to execute the snmp.bat on each server via:
C:\runas /user:domain\username "psexec \\server\ C:\snmp.bat"
5. Use snmpwalk from this page and run
Steps 4 & 6 can be improved by getting the @file command with psexec, but since it's paired with runas it might be tricky to get that to work.
2. Create a batch file that will a). import the key exported from step 1. b). delete the 1 value which needs to be removed to allow 'Any host' to connect to the SNMP service.
reg import C:\snmp\snmp.reg
reg delete HKLM\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers /v 1 /f
3. Copy these files to all of the servers via this script (make sure to create the C:\computers.txt and populate):
Const ForReading = 1
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\computers.txt")
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
strRemoteFile = "\\" & strComputer & "\C$\snmp.reg"
objFSO.CopyFile "C:\snmp\snmp.reg", strRemoteFile, OverwriteExisting
Loop
4. Use psexec to execute the snmp.bat on each server via:
C:\runas /user:domain\username "psexec \\server\ C:\snmp.bat"
5. Use snmpwalk from this page and run
snmpwalk -v 1 -c community-here 127.0.0.1
6. Remove all of the files using:
Const ForReading = 1
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\computers.txt")
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
strRemoteFile = "\\" & strComputer & "\C$\snmp.reg"
objFSO.DeleteFile strRemoteFile
Loop
Steps 4 & 6 can be improved by getting the @file command with psexec, but since it's paired with runas it might be tricky to get that to work.
Thursday, 27 October 2011
Replacing Mailbox Display Name with Simple Display Name
Set-RemoteDomain "Default" -UseSimpleDisplayName $true
Requires SP1 RU4
Requires SP1 RU4
Subscribe to:
Posts (Atom)