Skip to content

Instantly share code, notes, and snippets.

@Spartan-196
Spartan-196 / MailboxRestoreRequest.md
Last active July 26, 2021 19:41
Restore Mailbox request and get stats

From time to time you must fix a GUID or ImmutableID issue when migrating between AD domains, Tenants, and or federating services. When this happens and you end up with a soft delted mailbox for a specific user and you wish to restore it to their new mailbox you can initate a restore request in O365

$Alias = "<mailbox alias>"
$OldMailbox = Get-Mailbox -SoftDeletedMailbox  -Identity $alias | Select-Object Name,Alias,ExchangeGuid,ExternalDirectoryObjectID,LagacyExchangeDN
$NewMailbox = Get-Mailbox -Identity $alias | Select Name,Alias,ExchangeGUID,ExtenralDirectoryObjectID,LegacyExchangeDN
New-MailboxRestoreRequest -SourceMailbox $OldMailbox.ExchangeGuid.toString() -TargetMailbox $NewMailbox.ExchangeGUID.toString() -AllowLegacyDNMismatch
@Spartan-196
Spartan-196 / InstallNugetPackageProvider.md
Created October 5, 2020 15:08
Install NuGet Package Provider

When trying to install powershell modules from the repository you may be prompted to install NuGet.

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories

If it fails to continue the install after accepting with two warnings below you need to downgrade the TLS inuse for the session.

@Spartan-196
Spartan-196 / FillTo20gbfree.md
Created September 3, 2019 17:27
Create Large Files Powershell

Below can create a large dummy file for whatever purpose you may need, this one creates one that will fill the disk to only having 20GB free space when it is done.

Non administrative powershell will work.

Suggested on stackoverflow.
Verified on Windows 7 SP1 with PowerShell v2 and Windows 10 1903 PowerShell V5.1
PowerShell Version 7 does not support Get-WmiObject and has to use Get-CimInstance

#PowerShell 2-5.1
@Spartan-196
Spartan-196 / shadowcopy.md
Created February 11, 2019 17:25
ShadowCopyUserProfile

Write up for doing this remotely through pssession, can be adapted to doing locally on a pc as well

Enter remote session: enter-pssession [computer]

Create system restore snapshot: cmd /C 'Wmic.exe /Namespace:\\root\default Path SystemRestoreCall CreateRestorePoint "%DATE%", 100, 1'

List shadow copies: vssadmin list shadows

Sample output:

@Spartan-196
Spartan-196 / Get-Bitlockerkey.md
Last active July 22, 2023 16:40
Get bitlocker key from powershell on running system

From an elevated Windows PowerShell console, use the Get-BitlockerVolume function, mount point is needed for which drive you are getting the key for

(Get-BitLockerVolume -MountPoint C).KeyProtector

https://blogs.technet.microsoft.com/heyscriptingguy/2013/08/24/powertip-use-powershell-to-get-bitlocker-recovery-key/

As mentioned in the comments it can be done in windoows 7 via WMI, though no code was supplied in the comments PowerShellWithPassion hammered out the WMI code for getting the Numerical Password (Recovery key) from WMI.

@Spartan-196
Spartan-196 / O365Channel.md
Last active March 25, 2024 17:30
O365 Channel SCCM Collection Query

Query language for SCCM machine collections based on what O365 Channel is configured on a PC.

Supplemental to the pretty graphs shown in managment console Software Library > Overview >Office 365 Client Management As SCCM's Office overview shows lovely graphs of how many of each channel you have installed but not actually which machines those are these querys can be used to make a collection to do that.

Monthly Channel

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_OFFICE365PROPLUSCONFIGURATIONS on SMS_R_System.ResourceID = SMS_G_System_OFFICE365PROPLUSCONFIGURATIONS.ResourceID where SMS_G_System_OFFICE365PROPLUSCONFIGURATIONS.CDNBaseUrl = 'http://officecdn.microsoft.com/pr/492350f6-3a01-4f97-b9c0-c7c6ddf67d60'
@Spartan-196
Spartan-196 / installRsat.ps1
Last active August 28, 2020 01:29
RSAT 1809 and above Managed environment
# RSAT 1809 in Managed WSUS environment
# Set variables
$wsusSetting = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\"
$name = "UseWUServer"
$value = "0"
$service = "wuauserv"
If (Test-Path $wsusSetting$name) {
# Get Current WSUS Settings
$currentReg = Get-ItemPropertyValue -Name $name -Path $wsusSetting -ErrorAction SilentlyContinue
@Spartan-196
Spartan-196 / ScriptExectionTimeout.md
Last active March 18, 2019 20:26
ScriptExecution timeout SCCM
$CCMAgent = Get-WmiObject -Namespace root\ccm\policy\machine\actualconfig -class CCM_ConfigurationManagementClientConfig
$CCMAgent.get()
#default time out is 60 seconds
$CCMAgent.ScriptExecutionTimeOut = 60
$CCMAgent.Put() 

Credit to @PowerShellWithPassion

@Spartan-196
Spartan-196 / key.md
Created November 6, 2018 15:18
IBM iAccess Solutions EULA Registry
  • Global acceptance (you set this key and every user auto-accept eula): Path: HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs\com\ibm\iaccess\base Value: eula_g_accepted REG_SZ 1

  • User acceptance (you set this key if you want to deploy it per user profile): Path: HKEY_CURRENT_USER\SOFTWARE\JavaSoft\Prefs\com\ibm\iaccess\base Value: eula_g_accepted REG_SZ 1

@Spartan-196
Spartan-196 / SendEmail.md
Last active March 14, 2022 19:02
Anonymously Send to Internal SMTP

This can be used as part of a reporting mechnisizm on scheduled scripts to generate an email under defined conditions such as error results.

Utilises Send-MailMessage

#Setup Anon Credentials
$Username = "anonymous"
$Pass = ConvertTo-SecureString -String "anonymous" -AsPlainText -Force 
$Creds = New-Object System.Management.Automation.PSCredential($Username, $Pass)