az account list-locations -o table
Get location names from Azure
Reply
az account list-locations -o table
net user /add [username] [password] net localgroup administrators [username] /add
$startDate = Get-Date $endDate = $startDate.AddYears(80) $ObjectID = "132645645-d39e-4658-ab92-306cbb637421" $Name = "SecretName" Connect-AzureAD $aadAppsecret01 = New-AzureADApplicationPasswordCredential -ObjectId $ObjectID -CustomKeyIdentifier $Name -StartDate $startDate -EndDate $endDate $aadAppsecret01.value
set wsc = CreateObject("WScript.Shell")
Do
wsc.SendKeys("{F13}")
WScript.Sleep(1*60*1000)
Loop
# Elevate to adm
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
# Find OS
$OS = (Get-WMIObject win32_operatingsystem).Caption
if ($OS.Length -lt 2) { Write-host -ForegroundColor Yellow "Unable to determine OS"; Break}
Else { Write-host -ForegroundColor Green "$OS"}
# Find domain and check DNS
$Domain = (Get-WmiObject win32_computersystem).Domain
$DnsOutPUT = Resolve-DnsName -Name _vlmcs._tcp.$domain -Type SRV -ErrorAction SilentlyContinue
if ($DnsOutPUT.Length -lt 2) { Write-host -ForegroundColor Yellow "Unable to determine DNS records for KMS"; Break}
Else { Write-host -ForegroundColor Green "KMS server(s): " $DnsOutPUT.NameTarget}
# Test connectivity to KMS servers
foreach ( $KMSserver in $DnsOutPUT.NameTarget ) {
if ((Test-NetConnection -ComputerName $KMSserver -Port 1688 -ErrorAction SilentlyContinue).TcpTestSucceeded) { Write-host -ForegroundColor Green "Succesfully connected to:" $KMSserver}
}
# Build Array of KMS keys - https://docs.microsoft.com/en-us/windows-server/get-started/kms-client-activation-keys
$kmsKeys = @()
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2022 Datacenter";'Key'="WX4NM-KYWYW-QJJR4-XV3QB-6VM33" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2022 Standard";'Key'="VDYBN-27WPP-V4HQT-9VMD4-VMK7H" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2019 Datacenter";'Key'="WMDGN-G9PQG-XVVXX-R3X43-63DFG" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2019 Standard";'Key'="N69G4-B89J2-4G8F4-WWYCC-J464C" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2019 Essentials";'Key'="WVDHN-86M7X-466P6-VHXV7-YY726" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2016 Datacenter";'Key'="CB7KF-BWN84-R7R2Y-793K2-8XDDG" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2016 Standard";'Key'="WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2016 Essentials";'Key'="JCKRF-N37P4-C2D82-9YXRT-4M63B" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2012 R2 Standard";'Key'="D2N9P-3P6X9-2R39C-7RTCD-MDVJX" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2012 R2 Datacenter";'Key'="W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2012 R2 Essentials";'Key'="KNC87-3J2TX-XB4WP-VCPJV-M4FWM" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2008 R2 Standard";'Key'="YC6KT-GKW9T-YTKYR-T4X34-R7VHC" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2008 R2 Enterprise";'Key'="489J6-VHDMP-X63PK-3K798-CPX3Y" })
$kmsKeys += New-Object –TypeName PSObject –Prop ([ordered]@{'OS'="Microsoft Windows Server 2008 R2 Datacenter";'Key'="74YFP-3QFB3-KQT8W-PMXWJ-7M648" })
# Set KMS Key
$SetKeyOutPut = cscript c:\windows\system32\slmgr.vbs /ipk $kmsKeys[$kmsKeys.os.IndexOf($OS)].key
$SetKeyOutClean = $SetKeyOutPut | select -last 2 | select -First 1
if ($SetKeyOutClean.Contains("successfully")) { Write-host -ForegroundColor Green "Set key succesfully"}
Else { Write-host -ForegroundColor Yellow $SetKeyOutClean ; break }
# Activate KMS
$ActivateOutPut = cscript c:\windows\system32\slmgr.vbs /ato
$ActivateOutClean = $ActivateOutPut | select -last 2 | select -First 1
if ($ActivateOutClean.Contains("successfully")) { Write-host -ForegroundColor Green "Activated succesfully"}
Else { Write-host -ForegroundColor Yellow $ActivateOutClean ; break }
SELECT DP1.name AS DatabaseRoleName, isnull (DP2.name, 'No members') AS DatabaseUserName FROM sys.database_role_members AS DRM RIGHT OUTER JOIN sys.database_principals AS DP1 ON DRM.role_principal_id = DP1.principal_id LEFT OUTER JOIN sys.database_principals AS DP2 ON DRM.member_principal_id = DP2.principal_id WHERE DP1.type = 'R' ORDER BY DP1.name;

https://pwx.michaelthessel.com/
Great system for sending password.
You can limit if the password only can be seen once, and for how low the link with password will be valid
[int]$retentionDays = 90
$folders = "downloads", "OneDrive\Microsoft Teams-chatfiles"
$filesForDeletion = @()
$users = (Get-ChildItem "c:\users").name
foreach ($user in $users) {
foreach ($folder in $folders) {
$path = "C:\users\"+$user+"\"+$folder
if (Test-Path $path) {
$files = Get-ChildItem $path
foreach ($file in $files) {
if ($file.CreationTime -lt (Get-Date).AddDays(-$retentionDays)) {
$filesForDeletion += $file
}}}}}
rm $filesForDeletion.fullname -Confirm:$false -Force -Recurse