Getting fields from multiple Powershell Commands

—Single User—
$Mailbox = Get-MailBox "Joe Bloggs"
Get-mailboxstatistics "Joe Bloggs" | ft DisplayName,TotalItemSize,StorageLimitStatus,@{name = 'IssueWarningQuota';expression = {$Mailbox.IssueWarningQuota}},@{name = 'ProhibitSendQuota';expression = {$Mailbox.ProhibitSendQuota}},@{name = 'ProhibitSendRecieveQuote';expression = {$Mailbox.ProhibitSendRecieveQuota}}

—All Users—
$Mailbox = (Get-MailBox *)
foreach ($i in $Mailbox) {Get-mailboxstatistics $i.Name | ft DisplayName,TotalItemSize,StorageLimitStatus,@{name = 'IssueWarningQuota';expression = {$i.IssueWarningQuota}},@{name = 'ProhibitSendQuota';expression = {$i.ProhibitSendQuota}},@{name = 'ProhibitSendRecieveQuote';expression = {$i.ProhibitSendRecieveQuota}} }

—All Users Filtered—
$Mailbox = (Get-MailBox *)
foreach ($i in $Mailbox) {Get-mailboxstatistics $i.SAMAccountName | where {$_.StorageLimitStatus -ne "BelowLimit"} |ft DisplayName,TotalItemSize,StorageLimitStatus,@{name = 'IssueWarningQuota';expression = {$i.IssueWarningQuota}},@{name = 'ProhibitSendQuota';expression = {$i.ProhibitSendQuota}},@{name = 'ProhibitSendRecieveQuota';expression = {$i.ProhibitSendRecieveQuota}} }

—Tidy up formatting—
$Mailbox = (Get-MailBox *)
foreach ($i in $Mailbox) {
$info +=@(Get-mailboxstatistics $i.SAMAccountName | where {$_.StorageLimitStatus -ne "BelowLimit"} |select-object DisplayName,TotalItemSize,StorageLimitStatus,@{name = 'IssueWarningQuota';expression = {$i.IssueWarningQuota}},@{name = 'ProhibitSendQuota';expression = {$i.ProhibitSendQuota}},@{name = 'ProhibitSendRecieveQuota';expression = {$i.ProhibitSendRecieveQuota}} )
}
$info | ft -autosize

Group Policy Preferences – File and Folder Variables

When in Group Policy Preferences and trying to set up a folder or file policy. Press F3 for a list of environmental preferences. Helpfully though one of the most common ones – %DesktopDir%, works fine on Windows 8.1 but not on 7, for Windows 7 user %userprofile%\Desktop\[filename]

Scheduled Reboot

Specific time
at 04:00 shutdown -r -t 60 -f -d p:4:1 -c “Description here”

Day of the Month (eg 23rd)
at 21:40 /next:23 shutdown -r -t 60 -f -d p:4:1 -c “Description here”

Day of the week (M,T,W,Th,F,S,Su)
at 21:40 /next:W shutdown -r -t 60 -f -d p:4:1 -c “Description here”

The reason codes can be found in full by typing shutdown and pressing enter!
In the examples above it is Planned Application Maintenance

-r (Reboot)
-t 60 (in 60 Seconds)
-f (force programs to close)
-d p:4:1 (Planned application Maintenance)
-c “Description here” (write a note of “description here” into the logs)

The AT command has been depreciated but you can create a scheduled task for a reboot from the command line still…

schtasks /create /tn "Reboot" /tr "shutdown.exe -r -f -t 00" /sc ONCE /st 04:00:00 /sd 23/12/2020 /ru DOMAIN\USER /rp PASSWORD

https://support.microsoft.com/en-us/help/814596/how-to-use-schtasks-exe-to-schedule-tasks-in-windows-server-2003

VSS Fix

VSS Fix
Write a batch file containing the following:

cd /d %windir%\system32
Net stop vss
Net stop swprv
regsvr32 ole32.dll
regsvr32 oleaut32.dll
regsvr32 vss_ps.dll
vssvc /register
regsvr32 /i swprv.dll
regsvr32 /i eventcls.dll
regsvr32 es.dll
regsvr32 stdprov.dll
regsvr32 vssui.dll
regsvr32 msxml.dll
regsvr32 msxml3.dll
regsvr32 msxml4.dll
Net start vss
Net start swprv
pause

Kill a stuck Service

sc queryex [servicename]
taskkill /f /pid [PID]

Replace [servicename] with the services registry name. For example: Print Spooler is spooler.
Replace[PID] with the PID returned from the previous command.

Redircmp / Redirusr

Change the default location for new computers and users so that fresh objects can have GPOs applied (you cannot apply GPOs to the default Containers)

redirusr ou=myusers,DC=contoso,dc=com
redircmp ou=mycomputers,DC=contoso,dc=com

Telnet

At an Administrative Command Prompt enter “Telnet 192.168.0.1 389”, where 389 is the port you want to connect to on the host. If you are not sending SMTP you will just get an empty black screen if it works.

Robocopy

http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx

Eg. MOVES a folder and sub-directories without waiting and without retrying, strips off the security.
robocopy \\from\this\dir \\to\this\dir /e /zb /copy:DAT /r:0 /w:0 /mov

robocopy "E:\source\subfolder" "Q:\target\subfolder" /e /zb /copy:DAT /r:0 /w:0 /move

Note: if you are going to save this as a batch file, don’t call the batch file Robocopy.bat!
…and watch your speech marks. Word destroys them!