User Profile
Manfred101
Iron Contributor
Joined 7 years ago
User Widgets
Recent Discussions
Re: Bulk update Azure AD with user attributes from CSV
mesuhaib this script is not going to work. On line 16 you are starting a try{} block, but you are missing the catch {} part. A try always needs a catch! Check out this video: https://www.youtube.com/watch?v=smGXaPlW9j0 . You need to resolve that. Whene you ar done fixing the try block, you can troubleshoot line 17 by commenting out the options one-by-one: (see below, in this line you only set the jobtitle and department value. Try to find where things are going wrong) $user | Set-AzureADUser -jobTitle $CSVrecord.jobTitle -Department $CSVrecord.Department #-state $CSVrecord.state -country $CSVrecord.country -officeLocation $CSVrecord.officeLocation -city $CSVrecord.city -postalCode $CSVrecord.postalCode -TelephoneNumber $CSVrecord.TelephoneNumber -mobilePhone $CSVrecord.mobilePhone Good luck! Grtz, Manfred de Laat22KViews0likes0CommentsRe: Bulk update Azure AD with user attributes from CSV
cevatcekli Please include the script you try to run together with your csv (example data). Also make sure you are using the latest module. # Get My Module verion Get-Module AzureAD | Select Version # Get latest PSGallery version Find-Module AzureAd | Select Version # Update Module Get-Module AzureAD | Update-Module22KViews0likes3CommentsRe: Bulk update Azure AD with user attributes from CSV
Srini1987 The UPN of a guest users is a bit different from normal users. Make sure you can map them from your csv file. Should look like this: m.delaat_mycompany.nl#EXT#@yourTenantname.onmicrosoft.com Good luck! Manfred de Laat150KViews1like6CommentsRe: Script Optimization
beno_low Hello beno_low, You didn’t attach a example input file, so I was not able to test the script below. But I think you can speedup your script al lot by using your RAM instead of reading and writing to disk in each loop. Try something like the code below. I moved the Get-Content $args[1] in line 25 and load that into the $cmdb_content var. The Out-file at line 94 is also moved outside your primairy loop. WARNING: You are using $env in your script, this is not a best practice since Powershell is also using $Env to store enviroment variables! More info: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7 ############################################################################## # Filename : gen_host_env.ps1 # Usage : .\gen_host_env CS_host CMDB_host # Both input files must be in text format # Output : $Final_Result = @() #$Header = 'CMDB_Host,CMDB_Env,CS_Host,CS_Env,CS_FQDN,L1_Domain,L2_Domain'+"`r`n" #Write-Host $Header 'CMDB_Host,CMDB_Env,CS_Host,CS_Env,CS_FQDN,L1_Domain,L2_Domain' | Out-File -Encoding ascii -Append .\crowdstrike_host.txt $cmdb_content = Get-Content $args[1] $output = @() foreach ($fqdn in (Get-Content $args[0])){ $comp = $fqdn.Split(".") $hname = $comp[0] $l1 = $comp[1] $l2 = $comp[2] $l3 = $comp[3] $l4 = $comp[4] $l5 = $comp[5] $l6 = $comp[6] foreach ($cmdb_entry in $cmdb_content) { $cmdb_split = $cmdb_entry.Split(",") $cmdb_host = $cmdb_split[0] $cmdb_env = $cmdb_split[1] #Write-Host $cmdb_host if ($hname -imatch $cmdb_host) { $env_frm_cmdb = $cmdb_env break } else { $cmdb_host = 'NO match' $env_frm_cmdb = 'undetermined' } } #Write-Host $hname #Write-Host $l1 #### First Part of FQDN match criteria hostname.prod|pat|dev|.xyz########### if ($l1 -match 'prod'){ $env = 'prod' } elseif ($l1 -match 'splunk'){ $env = 'prod' } elseif ($l1 -match 'corp'){ $env = 'prod' } elseif ($l1 -match 'dev') { $env = 'dev'} elseif ($l1 -match 'englab') { $env = 'dev'} elseif ($l1 -match 'sit') { $env = 'sit'} elseif ($l1 -match 'pat') { $env = 'pat'} #### Second Part of FQDN match criteria hostname.abc.prod|pat|dev|.xyz########### elseif ($l2 -match 'prod'){ $env = 'prod' } elseif ($l2 -match 'dev') { $env = 'dev'} elseif ($l2 -match 'sit') { $env = 'sit'} elseif ($l2 -match 'pat') { $env = 'pat'} ############ Hadoop Server match env starts here ##################### elseif ($l2 -match 'hadoop') { if ($l1 -match 'c01') { $env = 'prod' } elseif ($l1 -match 'c02') { $env = 'dev' } elseif ($l1 -match 'c03') { $env = 'pat' } elseif ($l1 -match 'c2#') { $env = 'sit' } elseif ($l1 -match 'c5#') { $env = 'sit' } } else { $env = 'undetermine'} $Final_Result += $cmdb_host+","+$env_frm_cmdb+","+$hname+","+$env+","+$fqdn+","+$l1+","+$l2+"`r`n" #Write-Host $Final_Result $output += $cmdb_host+","+$env_frm_cmdb+","+$hname+","+$env+","+$fqdn+","+$l1+","+$l2 } $output | Out-File -Encoding ascii -Append .\crowdstrike_host.txt Good luck! Grtz, Manfred de Laat929Views0likes1CommentRe: Powershell Scripts
Schulzi Hello Schulzi, I am not aware of a cmdlet, but it’s quit easy to create the string you need by using string formatting. Take a look at this code: $SID = (New-Object System.Security.Principal.NTAccount($env:Username)).Translate([System.Security.Principal.SecurityIdentifier]).Value $RegPath = '"HKEY_USERS"{0}_Classes-CLSID-018D5C66-4533-4307-9B53-224DE2ED1FE6"' -f $SID More info is here: https://devblogs.microsoft.com/scripting/understanding-powershell-and-basic-string-formatting/ Good luck! Manfred de Laat1.5KViews1like1CommentRe: Create meeting Using PowerShell, Graph API and CSV File
AwaisKhalid Try to use this body: $bodyy = @" { "subject": "Let's go for lunch", "body": { "contentType": "HTML", "content": "Does noon work for you?" }, "start": { "dateTime": $($_.StartTime), "timeZone": "Pakistan Standard Time" }, "end": { "dateTime": $($_.EndTime), "timeZone": "Pakistan Standard Time" }, "location":{ "displayName":$($_.DisplayName) }, "attendees": [ { "emailAddress": { "address":$($_.UPN), #Want to use csv data here "name": "Awais Khalid" }, "type": "required" } ], "allowNewTimeProposals": true, "isOnlineMeeting": true, "onlineMeetingProvider": "teamsForBusiness" } "@ Manfred de Laat10KViews1like2CommentsRe: How can I convert a parsed json file from json then back to json?
__Martin__ Hello Martin, Please check my response at your earlier post: https://techcommunity.microsoft.com/t5/windows-powershell/why-does-my-generated-json-have-too-many-quot-quot/m-p/1592234 This is the exact reason why! Grt, Manfred849Views0likes0CommentsRe: Why does my generated JSON have too many "\\"?
__Martin__ Hello Martin, What you are doing is quit dangerous. You are breaking your JSON file and will receive an error when you import your JSON file. A backslash is reserved by the JSON and so when you want to use a backslash inside your data you NEED to escape your backslash whit a backslash. Doesn’t look to well but it has to be that way. The convertfrom-json cmdlet will deal whit the double backslash. Grtz, Manfred9.2KViews0likes0CommentsRe: The posh-git.psd1 file not loaded error
Rod-F Looks like you have an entry in one of your Powershell profile files. Check out $Profile variable in Powershell to get your profile file location. Open that file and remove the posh-git entry. Hope it helps! Grtz, Manfred de Laat8.3KViews1like1CommentRe: Variable not appearing in Function
pra4ash This is because of Powershell scopes. You can read about scopes here: https://ss64.com/ps/syntax-scopes.html In your case you have to use $global:Cred = Get-Credential to make the $Cred available outside your function! Grtz, Manfred de Laat715Views0likes0CommentsRe: powershell create a catalog file
goodywp Hi William, I don’t know why you want it like this but it is possible. In the snippet below you’ll find a way to do this. $Path = "c:\temp" $Outputfile = "c:\temp\output.txt" $allitems = Get-ChildItem -path $Path -Recurse $groups = $allitems | Group-Object -Property PSParentPath $lines = @() foreach($group in $groups){ $lines += $group.name.replace("Microsoft.PowerShell.Core\FileSystem::", "----") + "----" $items = $group.Group foreach($item in $items){ if(-NOT $item.PSIsContainer){ $lines += $item.name } } } $lines | out-file -FilePath $Outputfile It’s also possible to export to data to a XML file for later analysis (in powershell). You can import this data later (also on a different device). You will keep all properties like size (Length), dates (Create, LastAccessTime, LastWritetime etc) and many more. Disadvantage is that the output XML file is bigger. See the snippet below: # Get and export data $allitems = Get-ChildItem -path $Path -Recurse $allitems | Export-Clixml "c:\temp\output.xml" # Import data $importedItems = Import-Clixml "c:\temp\output.xml" I hope it works out for you William! Good luck! Grtz, Manfred de Laat1.8KViews0likes1CommentRe: unable to use inputobject in get-printjob
Jamal1245 It looks like the documentation is not up-to-date. Inputobject is not a valid parameter anymore. You need to replace it with -PrinterObject. See the snippet below: $printer = Get-Printer "Canon MP550 series Printer" Get-PrintJob -PrinterObject $printer Good Luck! Manfred de Laat1KViews0likes1CommentRe: Invoke-webrequest cmdlet query
Sreesreekanthop As far as I know, HTTP status of 101 is a serverside error. How does the same request works out from for example Postman? I Use invoke-webrequest all the time (Azure RM API and Microsoft Graph) but I always make sure my request are working from Postman before using them inside powershell.2KViews0likes0CommentsRe: Bulk update Azure AD with user attributes from CSV
Jacob John Just add this line below line 17: $user | Set-AzureADUserExtension -ExtensionName "employeeId" -ExtensionValue $CSVrecord.employeeId And make sure you add the "employeeId" records are present in your CSV file. Good Luck! Grtz, Manfred de Laat153KViews3likes24CommentsRe: Powershell to confirm onedrive geolocation
John Reece I don’t have a multi-geo tenant so I was unable to check the output, but I think the script below is showing the data where you looking for. Goodluck! Grtz, Manfred de Laat $cred = Get-Credential $url = "https://xxxxxxxxx-admin.sharepoint.com/" Connect-SPOService $url -Credential $cred Connect-MsolService -Credential $cred $Users = Get-MsolUser $UsersMoveState = @() $UsersOneDriveLocation = @() foreach($User in $Users){ $UsersMoveState += Get-SPOUserAndContentMoveState -UserPrincipalName $user.UserPrincipalName $UsersOneDriveLocation += Get-SPOUserOneDriveLocation -UserPrincipalName $user.UserPrincipalName } write-host $UsersMoveState,$UserOneDriveLocation2.6KViews0likes0CommentsRe: Custom Role definition not showing in Azure Portal
PhilRiceUoS I think you have used the New-AzRoleAssignment cmdlet. This is creating a custom role for Azure resources. I think you need to use New-AzureADMSRoleDefinition cmdlet to create a Azure AD role and that shows up in the "Roles and administrators" blade. Not 100% sure, but you can check it out!9.7KViews0likes1Comment
Recent Blog Articles
No content to show