All posts by Sysop

Update Profile Path for filtered users

$users = Get-aduser -filter 'profilepath -like "*oldservername*"'
foreach ($user in $users) {
# The line below returns the profilepath as a STRING with no headers
$profilepath = get-aduser $user -properties profilepath | foreach {$_.ProfilePath}
$newprofilepath = $profilepath -replace "oldservername", "domain.local\Data"
set-aduser $user -profilepath $newprofilepath

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


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

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.