Windows Server
123 TopicsUsing PowerShell to change the User Principal Name (UPN) for a user in Active Directory!
Dear Windows Active Directory friends, I am absolutely aware that there are probably already a lot of articles on this topic. Nevertheless, I would like to show you my steps how I did this in a small infrastructure. But why would I want to change the User Principal Name (UPN)? Let's say you want to synchronize the local Active Directory with the Azure Active Directory and you use in the local domain the DNS suffix e.g. tomrocks.local, then the accounts in Azure are created with the default DNS suffix e.g. yourcompany.onmicrosoft.com. In my case, I added a custom domain in Azure: tomrocks.ch. In order to create the accounts correctly in Azure, the first step is to adjust the UPN of the users in the local Active Directory. I use the PowerShell ISE for this, but of course you may also work with another editor. Please start with the following steps to begin the "journey" (the Hashtags are comments): #The first two lines have nothing to do with the configuration but make some space at the bottom of the ISE. Set-Location C:\ Clear-Host #Get a list of the UPN suffixes Get-ADForest | Format-List UPNSuffixes #Let’s add the UPN suffix Get-ADForest | Set-ADForest -UPNSuffixes @{add="tomrocks.ch"} #Get a list of the UPN suffixes Get-ADForest | Format-List UPNSuffixes #List of all the AD Users in the organization Get-ADUser -Filter * | Sort-Object Name | Format-Table Name, UserPrincipalName #Change the UPN for all the AD users in the organization $LocalUsers = Get-ADUser -Filter {UserPrincipalName -like '*tomrocks.local'} -Properties UserPrincipalName -ResultSetSize $null $LocalUsers | foreach {$newUpn = $_.UserPrincipalName.Replace("tomrocks.local","tomrocks.ch"); $_ | Set-ADUser -UserPrincipalName $newUpn} #Confirm that the UPN is changed Get-ADUser -Filter * | Sort-Object Name | Format-Table Name, UserPrincipalName I know this is nothing spectacular at all, but I wanted to share my findings and experiences with you. Thank you for your attention. Kind regards, Tom Wechsler P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler52KViews1like5CommentsRe: Enable-RemoteMailbox : The term 'Enable-RemoteMailbox' is not recognized
Hi, We have a VM that is used to create Active Directory users and assign them to groups using RPA (Desktop wer Automate). I'm trying to create a mailbox using P/S and I run into an error for the cmdlet:Enable-RemoteMailbox : The term 'Enable-RemoteMailbox' is not recognized as the name of a cmdlet, function. Do I have to install anything to enable it?Solved26KViews0likes1CommentThe underlying connection was closed: An unexpected error occurred on a send
PowerShell Script connecting to SharePoint online using Connect-PNPOnline as below code sample $credential = Import-Clixml $currfolderPath"\SPOnlineCredential.xml" $credentials = New-Object System.Management.Automation.PSCredential ($credential.UserName, $credential.Password) Write-Host "User Crendtial to Run the script" $credential.UserName $con=Connect-PnPOnline -Url $siteName -Credentials $credentials –ReturnConnection $ctx=Get-PnPContext gives below error: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.ConnectStream.WriteHeaders(Boolean async) --- End of inner exception stack trace --- at PnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord()21KViews0likes5CommentsSecure Way to store lots of credentials using powershell
Dear Community I wanted to ask if there is any way I can store lots of creedentials while still being able to use them in Powershell? I dont want to enter anything in a popup window, because there are way to many credentials to to that by hand. Is it possible that I can just put them in some kind of file and then get the wanted informations (while the file or its contents are somehow encrypted)? Thanks in advance MartinSolved21KViews0likes5CommentsShare & NTFS permissions export
Hi, I need to export a report from my file server for all the share & NTFS permissions to csv file. I found the next script: $FolderPath = dir -Directory -Path "#Requested Folder path" -Recurse -Force $Report = @() Foreach ($Folder in $FolderPath) { $Acl = Get-Acl -Path $Folder.FullName foreach ($Access in $acl.Access) { $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited} $Report += New-Object -TypeName PSObject -Property $Properties } } $Report | Export-Csv -path "#Report Export path" with this script, I got only the NTFS permissions. I need to combine also the share permissions to the same CSV file. thanks for the help.17KViews0likes5CommentsCPU Load Percentage PowerShell Windows Server 2019
Hello friends I want to check the percentage of use of Windows Server 2019 Server processors. I tried to use the query I was doing with Windows Server 2012, but it returns me the empty value. Could anyone know how I can do this in Windows Server 2019?Solved16KViews0likes6CommentsImport-CSV data into to set variables in a script
Good morning all, I don't know much about PowerShell but I am trying to create an script that variable data from each row in CSV file and input data to create the mailbox. For example: CSV: Username, Servername, ServerCode Bob,jane, DC101, 101 Input variable to the following: "Enable-Mailbox -identity "Domianname\User.name" - Database MBDB01-code -PrimarySMTPAddress "User.Name@email.address" -domain controller FQDN_servername" Where User.name = CSV.Username code = CSV.servercode FQDN_servername = CSV.servername Then the result will either out put the Enable-Mailbox line to .txt file or run each Enable-mailbox line RegardsSolved16KViews0likes2CommentsADCS expiring certificates email alerting script
Hi Can someone please help me with a script that sends out email alerts when a security certificate is about to expire in ADCS ? I found a couple on googling but none seems to work properly. There are some errors in that which I am unable to resolve. Any leads would be greatly appreciated. Thanks!Solved12KViews0likes19CommentsSite to Zone Assignment List - Powershell
I need to replicate the steps of adding a list of URLs to the Site to Zone Assignment List of a GPO. Is there a way to edit that GPO via PowerShell, enable Site to Zone Assignment List, and pass the list of URLs to it? - Open the Group Policy Management Editor. Go to User Configuration > Policies > Administrative Templates > Windows Components > Internet Explorer > Internet Control Panel > Security Page. Select the Site to Zone Assignment List. Select Enabled and click Show to edit the list. The zone values are as follows: 1 — intranet, 2 — trusted sites, 3 — internet zone, 4 — restricted sites. Click OK. Click Apply and OK.Solved11KViews0likes1Comment