@windows powershell
35 TopicsHow can I return all AD Groups with a specific SID HISTORY value?
Hello how can I return all AD Groups with a specific SID HISTORY value? I have tried something like this $SID = "SID VALUE Here" Get-ADGroup -Filter * | where{$_.sidhistory -eq $SID} But it just returns blank. Thanks597Views1like2CommentsPowerShell Script Failing with Auth Header and 500 Internal Server Error for REST API
Hi everyone, I'm encountering multiple issues with the PowerShell script that interacts with a REST API to execute batch jobs in FDMEE. The script is supposed to send an HTTP request with a Basic Authorization header, but I'm facing the following problems: "Invalid or Missing Authorization Header" Error: When I visit the API URL directly in the browser, I get: { "links": [], "status": 9, "details": "EPMFDM-ERROR: Invalid or Missing Authorization Header in request" } 2."Internal Server Error (500)": When running the script, it often goes to the catch block and displays a 500 Internal Server Error. Here's the error message I receive in PowerShell: PS>TerminatingError(Invoke-RestMethod): "Request failed." Error encountered in PowerShell Script. Here is the script I'm using: #HTTP Basic Authorization. Contains encrypted username and password encoded to base64 string. $headers = @{Authorization = 'Basic encryptedpassword';} # Set parameter values $jobName = $args[0] $uri = http://server.comm.iocs.address.com:0000/aif/rest/V1/jobs # Monitor status of current batch run Write-Output "Checking Job Status..." Start-Sleep -Seconds 5 $restResponse = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers -ContentType "application/json" $lastJobID = $restResponse.items[0].jobID $payload = @{ jobType = "BATCH" jobName = $jobName } | ConvertTo-Json # Establish REST connection and execute batch job using REST API $restResponse = Invoke-RestMethod -Uri $uri -Method Post -Body $payload -Headers $headers -ContentType "application/json" $uri = $restResponse.links[0].href # Display initial status of batch Write-Output "See below status of batch run..." $restResponse = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers -ContentType "application/json" $currentJobID = $restResponse.jobID Write-Output "Last Job ID: $lastJobID" Write-Output "Current Job ID: $currentJobID" } catch { Write-Output "Error encountered in PowerShell Script.." Write-Output $_.Exception.Message if ($_.InvocationInfo) { Write-Output "Error in script: $($_.InvocationInfo.ScriptName)" Write-Output "Error on line: $($_.InvocationInfo.ScriptLineNumber)" Write-Output "Error in command: $($_.InvocationInfo.Line)" } if ($_.Exception.Response) { Write-Output "HTTP Status Code: $($_.Exception.Response.StatusCode.Value__)" Write-Output "Status Description: $($_.Exception.Response.StatusDescription)" Write-Output "Response Content: $($_.Exception.Response.Content)" } exit 1 } Despite my efforts, the request still fails with the "Invalid or Missing Authorization Header" error and occasionally hits a 500 Internal Server Error. Here are the steps I've taken to debug the issues: Checked Base64 Encoding: Confirmed that the credentials are correctly encoded in Base64. Verified Header Format: Ensured that the Authorization header is correctly formed and included in the request. Tested with Postman: Manually tested the API request with Postman using the same Authorization header, and I'm getting the same header authorization error. Added Detailed Error Logging: Included more detailed error logging in the catch block to capture HTTP status codes and response content. I'm looking for advice on what might be causing these issues in the PowerShell script and how I can resolve them. Any insights or suggestions would be greatly appreciated!2.2KViews0likes4CommentsNeed advise on the below powershell script to deploy on intune devices
Hi Champs, Not sure if below script is correct. Looks like it is working if we run powershell as administrator but otherwise throwing errors. I want to deploy below script to endpoint devices via intune. Please assist. I want to set the below location path at word, options, save, Default personal templates location ForEach ($user in (Get-ChildItem "C:\Users" -Exclude Public)) { $location = "C:\Users\$($user.Name)\Documents\Custom Office Templates" $IsPresent = Get-ItemProperty 'HKCU:\SOFTWARE\Microsoft\Office\16.0\Word\Options' | ForEach-Object {If($_ -like '*PersonalTemplates*'){ Return 'True' }} if(-Not($IsPresent -eq 'True')) { New-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Office\16.0\Word\Options' -Name 'PersonalTemplates' -Value $location -PropertyType ExpandString -Force New-Item -ItemType Directory -Force -Path $location } $existingValue= Get-ItemPropertyValue -Path 'HKCU:\SOFTWARE\Microsoft\Office\16.0\Word\Options' -Name 'PersonalTemplates' if([string]::IsNullOrWhiteSpace($existingValue)){ Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Office\16.0\Word\Options' -Name 'PersonalTemplates' -Value $location } else{ $location=$existingValue if(!(test-path $existingValue)) { New-Item -ItemType Directory -Force -Path $existingValue } } } Regards, Ram480Views0likes2CommentsPowershell JEA - WMI Queries
Hi, I'm looking at using PowerShell JEA to run some WMI queries aimed at monitoring servers. Is this possible? An example of the query is below. The objective is to prevent the service account used by the monitoring application from having local administrator access. SELECT Name,VolumeName,FileSystem from Win32_LogicalDisk WHERE DriveType='3' SELECT Name from Win32_PerfRawData_PerfDisk_LogicalDisk SELECT Name from Win32_PerfRawData_PerfDisk_PhysicalDisk736Views0likes4CommentsGet-aduser is not working in PS7 if i am trying to filter user using attribute Whencreated.
below code is working in PS 5.1 but Not in PS 7.4.2 $when = $(Get-Date).AddDays(-3).date $data = Get-ADUser -Filter {whenCreated -ge $When} $data.count Error: Get-ADObject: Error parsing query: 'whenChanged -gt 05/06/2024 00:00:00' Error Message: 'Operator Not supported: ' at position: '19'.Solved1.1KViews0likes5CommentsHow save the img from "[void][Reflection.Assembly] ....... "
Hello, pls how i save the image from ..... the scripte: [void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void][Reflection.Assembly]::LoadWithPartialName("System.Drawing") $frmMain = New-Object Windows.Forms.Form $xString = @(` ) $imageBytes = [System.Convert]::FromBase64String($xString) $ms = [System.IO.MemoryStream]::new($imageBytes, 0, $imageBytes.Length) $ms.Write($imageBytes, 0, $imageBytes.Length) $pic = [System.Drawing.Image]::FromStream($ms, $true) $picArea = New-Object Windows.Forms.PictureBox $picArea.Dock = "Fill" $picArea.Image = $pic $picArea.SizeMode = "StretchImage" $frmMain.Controls.AddRange(@($picArea)) [void]$frmMain.ShowDialog() Thank for your help Arnold273Views0likes0CommentsObtaining SQL VM Edition from azure
I'm in the process of gathering information about our SQL VMs on Azure, and I'm specifically looking for the location of the editions. However, I seem to be having trouble finding them. Any insights on where to locate this information would be great.471Views0likes2CommentsUsing Powershell to Install Python
Hi all A while ago I created a script in powershell to install python and it worked if I was running the script but then I automated it in Jenkins so it ran remotely on the machine. It installs Python Launcher but Control Panel does not show the actual Python inatall, yet regiatry believes it exists. Seems the install is corrupted. Today I did a new script to run via GPO on reatart to install python direct on server and the same issue happens. Python does not package as an msi and thus I need powershell to install it and this needs to be done without human intervention but no matter what I try it always corrupts/fails to fully install (no errors) Does anybody have a solution guaranteed to install? It's doing my head in Prior to install I also run some uninstall commands and registry clearing of old version if that is crucial info though that shouldn't cause issue Thanks for your responses2.1KViews0likes2Comments