PoweShell
19 TopicsHow to compare two xml files and display the difference side by side.
$baseServer="C:\Store\PS\referrencexml.xml" $Server2Compare="C:\Store\PS\differencexml.xml" $boutput = Compare-Object -ReferenceObject (Get-Content -Path "$baseServer") -DifferenceObject (Get-Content -Path "$Server2Compare") Above command shows the difference between two files in the below format(Output1), but I need to display the difference in side by side like Output2. So, if someone could help me with an idea or sample code/script to get the output in two different column side by side, it will be very helpful. Output1: Input Object Side Indicator <genre></genre> => <genre>Fantasy</genre> <= Output 2: Reference File Difference File <genre></genre> <genre>Fantasy</genre>53KViews0likes6CommentsConfigure AD FS 2016 and Azure MFA - How do I get the guid for Azure Multi-Factor Auth Client?
Hi All, I am trying to Configure AD FS 2016 and Azure MFA as shown on the Microsoft site: https://docs.microsoft.com/en-us/windows-server/identity/ad-fs/operations/configure-ad-fs-and-azure-mfa#step-1-generate-a-certificate-for-azure-mfa-on-each-ad-fs-server-using-the-new-adfsazuremfatenantcertificate-cmdlet It says "981f26a1-7f43-403b-a875-f8b09b8cd720 is the guid for Azure Multi-Factor Auth Client" but doesn't show how we get this GUID. When I try the command I get an error message I think is related to the GUID. How do I get the guid for Azure Multi-Factor Auth Client? I hope you can help ColinSolved9.4KViews0likes2CommentsUsing powershell get size of folder and subfolders on Windows Server 2012 R2
I created script below and I now want to enhance it as I am getting errors. # Create the filename with the current date $filename = ([string]::Format("\\JHBDSM020000128\QlikView\Elijah\Data\Detailed\128_Detailed_FileSystem_{0}.csv", (Get-Date).toString("yyyyMMdd"))) # Delete the file if exists if([System.IO.File]::Exists($filename)){ # file with path $path exist Remove-Item -path $filename } $Drives = Get-PSDrive -PSProvider 'FileSystem' foreach($Drive in $drives) { # Delete the file if exists Get-ChildItem -Path $Drive.Root -recurse | Select-Object Directory, Name, LastWriteTime, Length | Out-File -Append $filename -NoClobber } Attached is the result set I am getting. If you look at attached you'll notice that only Directory and Name fields are showing but the other fields are not visible. Can someone please assist as I am using the same script on other servers but the servers are Windows Server 2003 R2 and the result set is working perfectly. Please also don't forget adding the script to show Folder path and size.9.2KViews0likes1Commentget-content and foreach loop
Hi I am trying to set permissions to all GPOs names in the file. I got the first PS script working by using -eq to name of a GPO in the file, but i need to set permissions to all GPOs in the file . I cant seems to figure it out . what am i doing wrong? Thanks in advance for your help! First script works just for one GPO $gpos =Get-Content "D:\gpolist1.txt" $gpos | foreach { if ($_ -eq "test") { Set-GPPermission -PermissionLevel GpoEditDeleteModifySecurity -TargetName "GPOAdmins" -TargetType Group $_ } } Not working , need to set permissions for all GPOs in the file $gpos = get-content "d:\gpolist1.txt" Write-Output $gpos foreach ($gpo in $gpos) { #call displayname if ($_ -eq $gpos) {Set-GPPermission -PermissionLevel GpoEditDeleteModifySecurity -TargetName "GPOAdmins" -TargetType Group $_ } else { write-output "no result" } }5.6KViews0likes3CommentsReg: unable to update Windows Virtual Desktop Agent
Hi, I recently created an RDS environment and WVD setup, I have installed Windows Virtual Desktop Agent. and Windows Virtual Desktop Agent Bootloader by following https://docs.microsoft.com/en-us/azure/virtual-desktop/create-host-pools-powershell . after configuring session hosts in the host pool, I was able to see the session host with a status error "Upgrade failed". I have downloaded agent and agent boot loader from docs.microsoft.com only. and I was unable to find how to updated "agent and agent boot loader".2.8KViews0likes2CommentsPS array performance >40K entries
Hi I'm trying to find the fastest way to search a large array (40K entries) for a value. However, I'm struggling with the way in which the array is working. I read in all AD users as shown below $AllADUsers = Get-ADUser -Filter "*" -properties SAMAccountName, DisplayName, UserPrincipalName, Company, Office,Department, Manager, Description, Created, LastLogonDate, EmployeeType,Info -Server $ADServer -Credential $c |select SAMAccountName, DisplayName, UserPrincipalName, Company, Office, Department, Manager, Description, Created, LastLogonDate, EmployeeType,Info Now this is why I have a query If I search the array using the .Contains method it finds the entry in around 2ms $AllADUsers.Contains($SearchID) If I then try to pull the data for the record using the "where" method it takes 1000ms $AllADUsers.Where({$_.UserPrincipalName -eq "$SearchID"}) So why can it find the value in 2ms using "contains" method but takes more than 1000ms to read the actual record using the "where" method. Its as if it's using a different search algorithm in the "where" method. In fact it was faster to use Get-AdUser for each search as this only takes 900ms I've also tried other variations to no avail, such as: $AllADUsers | where-object {$_.UserPrincipalName -eq $SearchID} Any help gratefully received. Thanks blairkeiSolved2.3KViews0likes9CommentsPowershell and filtering results from cmdlest into CSVs
Hi everyone, I need to have a script that outputs a CSV list, to be used for a mail merge, with the last login and the alternative emails (and other useful info for the mail merge), so I can mass mail anyone that has not logged in yet. I have stumbled my way into creating a script, with lots of help and cobbled together from around the internet, now I am just missing a piece, which is to filter out users that have not logged in yet, as in have no data in the LastSignInDateTime field. This is the script: param($path="$PSScriptRoot\reports",$pwdnochangedindays = 480) cd $path Start-transcript $cohort = read-host "Enter cohort to audited" Connect-MgGraph -Scopes "Directory.ReadWrite.All", "Directory.AccessAsUser.All","User.Read.All","AuditLog.Read.All" Select-MgProfile -Name beta $MSGProps = @( 'id' 'displayName' 'CompanyName' 'State' 'OfficeLocation' 'department' 'signInActivity' 'userPrincipalName' 'userType' 'createdDateTime' 'accountEnabled' 'passwordPolicies' 'mail' 'lastPasswordChangeDateTime' 'OtherMails' ) $MSGSplat = @{ Filter = "userType eq 'Member' and AccountEnabled eq true and startsWith(State, '$cohort')" all = $true Property = $MSGProps } $MSGUser = Get-MgUser @MSGSplat $Results = Foreach ($SingleMSG in $MSGUser) { [pscustomobject]@{ Id = $SingleMSG.id DisplayName = $SingleMSG.displayName CompanyName = $SingleMSG.CompanyName State = $SingleMSG.State OfficeLocation = $SingleMSG.OfficeLocation Department = $SingleMSG.department UserPrinciple = $SingleMSG.userPrincipalName UserType = $SingleMSG.userType Created = $SingleMSG.createdDateTime Enabled = $SingleMSG.accountEnabled Mail = $SingleMSG.mail PasswordChange = $SingleMSG.lastPasswordChangeDateTime PasswordPolicy = $SingleMSG.passwordPolicies LastSignInDate = $SingleMSG.signInActivity.LastSignInDateTime LastNonInteractive = $SingleMSG.signInActivity.LastNonInteractiveSignInDateTime OtherMails = $SingleMSG | select-object -expand OtherMails } } $Results | Export-Csv -path "$path\aad_user_report_$((Get-Date -format "dd-MMM-yyyy"))_$cohort.csv" -notypeinformation write-host "Report can be found here $path" Stop-transcript # Based on chadmcox create-AADMGUserReport.ps1 # https://www.reddit.com/r/PowerShell/comments/vlrvca/expandproperty_csv_exporting_and_general_noobness/ # https://www.reddit.com/r/PowerShell/comments/vi8rcv/getting_a_list_of_all_users_last_login_status_and/ It produces a CSV like this: No idea how to do that, I have tried to add $results | where-object {$_.LastSignInDate -ne $null} | Export-Csv -path "$path\aad_user_report_$((Get-Date -format "dd-MMM-yyyy"))_$cohort.csv" -notypeinformation to the export oart of it , but no results from that. Any suggestions on how to get only people with no log-ins included?2.2KViews0likes9Commentsread elements of an array simultaneously
Hi All, I am PS newbie (though have worked on other languages). Is there a way we can read elements of an array simultaneously rather than iterating through a foreach loop. I have an array ("A" , "B" , "C" , "D"), instead of iterating like foreach ($x in $array) { print $x}, is it possible that I pull our all simultaneously2.1KViews0likes8Comments