Posts

Showing posts with the label powershell

Headers in Powershell are incorrect

Headers in Powershell are incorrect After importing a CSV file, I create a hashtable of the variables that will be used in a simple command line. Problem is that when I import the CSV files, the headers are transposed; instead of it being a table with various headers, it is different. My code is: $Import = Import-Csv "Filepathinput.csv" foreach ($user in $import) { $msolparams = @{ UPN = $user.SamAccountName + "@company.com" Title = $user.JobTitle Deparment = $user.DepartmentTitle Displayname = $user.Pname + "," + " " + $user.Plname Location = $user.location} Set-MsolUser -UserPrincipalName $msolparams.UPN -Title $msolparams.Title -Department $msolparams.Department -DisplayName $msolparams.Displayname} After checking the $import variable with the CSV file input, the hashtable headers come out as so: $import SamAccountName : kodak.black Location : Central JobTitle : Title DepartmentTi...

Powershell script to add users to A/D group from .csv using email address only?

Powershell script to add users to A/D group from .csv using email address only? Import-CSV "C:usersBalbahagwdesktoptest1.csv" | Foreach-Object { $aduser = Get-ADUser -Filter { EmailAddress -eq $_.'EmailAddress' } if( $aduser ) { Write-Output "Adding user $($aduser.SamAccountName) to groupname" Add-ADGroupMember -Identity tech-103 -Members $aduser } else { Write-Warning "Could not find user in AD with email address $($_.EmailAddress)" } } Script is working now, however it can't find the user in AD with the email address. The error message tells you precisely what went wrong. – Bill_Stewart Jun 29 at 19:54 You want -Members not -User. At a powershell prompt type: Get-Help Add-ADGroupMember -Detailed – EBGreen ...

powershell find dynamic variables within xml

powershell find dynamic variables within xml I have performed a web request that returns $xml . Write-Host $xml.status.audio.volume outputs 56 as it should. Thus I know the XML is OK. $xml Write-Host $xml.status.audio.volume Then I read a file to determine what XML attributes I need to look at: How do I use that attribute (eg. status.audio.volume ) to output or test if the $xml has the value I expect? status.audio.volume $xml e.g. (pseudocode) If $xstatus.status.audio.volume = 56 Then ... If $xstatus.status.audio.volume = 56 Then ... Have you tried Compare-Object ? – TheMadTechnician Jun 28 at 23:45 Compare-Object I guess I am not explaining correctly. I can hard code something like if $xstatus.status.audio.volume = 56 and that would work, but I need to read the attribute part from a file "status.audio.vo...

Convert XML to CSV not working

Convert XML to CSV not working XML file Content: <?xml version="1.0"?> <servstate> <title>2018-06-11 12:00:01</title> <services> <service> <name>Oracle Weblogic AdminServer 1</name> <state>RUNNING.</state> </service> <service> <name>Oracle WebLogic NodeManager 1</name> <state>RUNNING.</state> </service> <service> <name>OracleProcessManager_1</name> <state>RUNNING.</state> </service> <service> <name>OracleProcessManager_2</name> <state>RUNNING.</state> </service> <service> <name>Oracle WebLogic NodeManager 2</name> <state>RUNNING.</state> </service> <service> <name>Oracle Weblogic AdminServer 2</name> <state>RUNNING.</state> </service> </services> </servstate> I am new to PowerShell and written a script to parse the above ...

How do I store the contents of an array to a json file in powershell

How do I store the contents of an array to a json file in powershell I wanted to save the contents of an array to a .json file.The array has some dictionaries in it. I tried Set-Content -Path 'crl_urls.json' -Value $arrayval -Force The JSON file has stored System.Collections.Hashtable . It hasn't stored the values of the dictionaries. System.Collections.Hashtable So How do I do it? 2 Answers 2 To correctly save the content in a .json file you should first convert the array to the .json format. Try this: ConvertTo-Json -InputObject $arrayval | Out-File -FilePath .crl_urls.json By using the ConvertTo-Json cmdlet I was able to export the contents of the array in the JSON file. Example Code: ConvertTo-Json Set-Content -Path 'crl_urls1.json' -Value ($arrayval|ConvertTo-Json) -Force By clicking "Post Your Answer", you acknowledge t...

How to find a TFS release in progress?

How to find a TFS release in progress? I need to fail a build on TFS 2018 if its pipeline is not fully complete. Batching just the build is not enough; the linked release must be finished as well before another build can begin. My idea is to do this in a PowerShell script via the REST API. I see in the official documentation here that there's a property called TaskStatus . It provides a value of inProgress , presumably for releases that are in progress. This might do the trick, but there's no indication of how to actually use it. TaskStatus inProgress Using the REST API, how can I get the TaskStatus of a given release? TaskStatus I don't understand why you'd want to do this. Can you give some context? A release failing doesn't necessarily mean that the build itself is bad. – Daniel Mann 2 days ago ...

Skip part of script on error

Skip part of script on error I've been banging my head against the wall for awhile on this one. No amount of Googling has yielded me any successful results thus far. Wondering if someone can give me a hand? # Load the PowerShell module for Active Directory Import-Module ActiveDirectory # For each computer in AD that is a member of the target group Get-ADGroupMember -Identity "CN=RenameComputer,CN=Users,DC=int,DC=example,DC=com" | ForEach { # Define the new name as the old one, minus one letter at the end $NewComputerName = $_.Name -replace ".$" # Perform the rename operation Rename-Computer -ComputerName $_.Name -NewName $NewComputerName -Force -PassThru -Restart -WhatIf # Remove the computer from the target group # THIS SHOULD NOT OCCUR IF THE RENAME ABOVE FAILED!!! Remove-ADGroupMember -Identity "CN=RenameComputer,CN=Users,DC=int,DC=example,DC=com" -Members $NewComputerName -WhatIf } TL;DR: Thi...