Skip to content

Instantly share code, notes, and snippets.

@OmerMicrosoft
OmerMicrosoft / WVD_AddRdsUsers.ps1
Created Apr 23, 2019
Display the RDS users of a specific hostpool in a Windows Virtual Desktop tenant. Let you add additional RDS users to a hostpool if required.
View WVD_AddRdsUsers.ps1
#Get Azure admin credentials
Write-Host "Getting Azure credentials... "
$Credentials = Get-Credential -Message "Enter your Azure admin credentials"
#Add RDS Account in order to be able to change WVD configuration
$BrokerURL = "https://rdbroker.wvd.microsoft.com"
Write-Host "Adding the RDS account... " -NoNewline
Try {
Add-RdsAccount -DeploymentUrl $BrokerURL -Credential $Credentials -ErrorAction Stop | Out-Null
}
Catch {
@OmerMicrosoft
OmerMicrosoft / WVD_AssignTenantCreatorRoleAndCreatingWVDTenant.ps1
Last active Apr 29, 2019
Initialize the setup of Windows Virtual Desktop in Azure by assigning the 'TenantCreator' role to a selected user and creating the WVD tenant
View WVD_AssignTenantCreatorRoleAndCreatingWVDTenant.ps1
<#Script Summary:
This PowerShell script initialize the setup of Windows Virtual Desktop in Azure.
The script include:
1.Assign the “TenantCreator” role to a user account.
2.Create a Windows Virtual Desktop tenant.
Before running this script, you should allow the Windows Virtual Desktop service to access Azure AD on the following link: https://rdweb.wvd.microsoft.com/
#>
###Install and import Required Modules###
#Install-Module Az,AzureAD,Microsoft.RDInfra.RDPowerShell -AllowClobber -Force #Remove remark if the required modules have not been installed yet.
@OmerMicrosoft
OmerMicrosoft / WVD_CreateNewRDSTenant.ps1
Created Apr 13, 2019
Create a new WVD (Windows Virtual Desktop) tenant
View WVD_CreateNewRDSTenant.ps1
$BrokerURL = "https://rdbroker.wvd.microsoft.com"
Add-RdsAccount -DeploymentUrl $BrokerURL -Credential $Credentials
$RDSTenantName = Read-Host "Enter RDS tenant name"
$NewRDSTenant = New-RdsTenant -Name $RDSTenantName -AadTenantId $SelectedAzureSubscription.TenantId -AzureSubscriptionId $SelectedAzureSubscription.SubscriptionId
if ($NewRDSTenant) {
Write-Host "A new RDS tenant was created with the name $($NewRDSTenant.TenantName)" -ForegroundColor Green
}
else {
Write-Host "The creation of a new RDS tenant was failed." -ForegroundColor Red
}
@OmerMicrosoft
OmerMicrosoft / WVD_AssignTenantCreatorRoleToUser.ps1
Created Apr 13, 2019
Assign the 'TenantCreator' role to a selected user for WVD (Windows Virtual Desktop)
View WVD_AssignTenantCreatorRoleToUser.ps1
$WVDApplication = Get-AzureADServicePrincipal -Filter "displayName eq 'Windows Virtual Desktop'"
$ApplicationRole = $WVDApplication.AppRoles | Where-Object { $_.DisplayName -eq 'TenantCreator'}
$UserAccount = Get-AzureADUser -ObjectId $AzureAccount.Id
New-AzureADUserAppRoleAssignment -ObjectId $UserAccount.ObjectId -PrincipalId $UserAccount.ObjectId -ResourceId $WVDApplication.ObjectId -Id $ApplicationRole.Id
@OmerMicrosoft
OmerMicrosoft / gist:796661fd6cc58c0ab4060a1e9e718473
Created Apr 13, 2019
WVD_AssignTenantCreatorRoleToUser.ps1
View gist:796661fd6cc58c0ab4060a1e9e718473
$WVDApplication = Get-AzureADServicePrincipal -Filter "displayName eq 'Windows Virtual Desktop'"
$ApplicationRole = $WVDApplication.AppRoles | Where-Object { $_.DisplayName -eq 'TenantCreator'}
$UserAccount = Get-AzureADUser -ObjectId $AzureAccount.Id
New-AzureADUserAppRoleAssignment -ObjectId $UserAccount.ObjectId -PrincipalId $UserAccount.ObjectId -ResourceId $WVDApplication.ObjectId -Id $ApplicationRole.Id
@OmerMicrosoft
OmerMicrosoft / Create-ClientsWithNoAssociatedSiteReport.ps1
Last active Jul 31, 2021
Create Clients With No Associated Site Report
View Create-ClientsWithNoAssociatedSiteReport.ps1
#Get Domain Controllers for current domain
$DCs = Get-ADGroupMember "Domain Controllers"
#Initiate the clients array
$Clients = @()
Foreach ($DC in $DCs) {
#Define the netlogon.log path
$NetLogonFilePath = "\\" + $DC.Name + "\C$\Windows\debug\netlogon.log"
#Reading the content of the netlogon.log file
try {$NetLogonFile = Get-Content -Path $NetLogonFilePath -ErrorAction Stop}
catch {"Error reading $NetLogonFilePath"}
@OmerMicrosoft
OmerMicrosoft / Create-DomainControllersRolesReport.ps1
Last active Jan 27, 2019
Get Installed Windows Roles on each Domain Controller
View Create-DomainControllersRolesReport.ps1
#Get Installed Roles on each Domain Controller
$DCsInForest = (Get-ADForest).Domains | % {Get-ADDomainController -Filter * -Server $_}
$DCsRolesArray = @()
foreach ($DC in $DCsInForest) {
$DCRoles=""
$Roles = Get-WindowsFeature -ComputerName $DC.HostName | Where-Object {$_.Installed -like "True" -and $_.FeatureType -like "Role"} | Select DisplayName
foreach ($Role in $Roles) {
$DCRoles += $Role.DisplayName +","
}
try {$DCRoles = $DCRoles.Substring(0,$DCRoles.Length-1)}
View ChangeForestAndDomainFunctionalLevels.ps1
#Changing The Forest Level
$CurrentForest = Get-ADForest
Set-ADForestMode -Identity $CurrentForest -Server $CurrentForest.SchemaMaster -ForestMode Windows2008R2Forest
#Changing The Domain Level
$CurrentDomain = Get-ADDomain
Set-ADDomainMode -Identity $CurrentDomain.Name -Server $CurrentDomain.PDCEmulator -DomainMode Windows2008R2Domain
@OmerMicrosoft
OmerMicrosoft / Create-DNSScavengingRecordsReport.ps1
Last active Sep 26, 2019
Creates a report with DNS records stale data
View Create-DNSScavengingRecordsReport.ps1
Function Create-DNSScavengingRecordsReport
{
<#The script checks any Dynamic DNS Record and decided whether it’s:
1)A stale record which responded to ping.
2)stale record which doesn’t responded to ping.
3)An updated record (not stale).#>
$DC = (Get-ADDomainController).Name
$DNSRoot = (Get-ADDomain).DNSRoot
$DNSRecords = Get-DnsServerResourceRecord -ComputerName $DC -ZoneName $DNSRoot
$DateThershold = (Get-Date).AddDays(-14)
@OmerMicrosoft
OmerMicrosoft / Create-DNSScavengingRecordsReport.ps1
Last active Jan 8, 2019
Creates a report with DNS records stale data
View Create-DNSScavengingRecordsReport.ps1
Function Create-DNSScavengingRecordsReport
{
<#Creates a report with DNS records stale data.
For any record, checks if:
1)Stale record, responding to ping.
2)Stale record, NOT responding to ping.
3)Valid record, timestamp is updated (not stale).#>
$DC = (Get-ADDomainController).Name
$DNSRoot = (Get-ADDomain).DNSRoot
$DNSRecords = Get-DnsServerResourceRecord -ComputerName $DC -ZoneName $DNSRoot