powershell
259 Topics$cred = Get-Credential without asking for prompts in powershell
I am trying to run a script and i wanted to run it silently without asking for credential prompts. Is there a way to get around using "$cred = Get-Credential" without a prompt The script i am trying to use is # Connect to Office 365 # $username = "" $password = ConvertTo-SecureString "mypassword" -AsPlainText -Force #$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force $creds = New-Object System.Management.Automation.PSCredential -ArgumentList ($user, $password) Import-Module MSOnline $cred = Get-Credential Connect-MSolService -credential $cred $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection Import-PSSession $Session -AllowClobber -DisableNameCheckingSolved449KViews0likes10CommentsCan't import SharePoint online Powershell module
when I use Import-Module Microsoft.Online.SharePoint.PowerShell it says PS C:\Windows\system32> Import-Module Microsoft.Online.SharePoint.PowerShell Import-Module : Could not load type 'Microsoft.SharePoint.Administration.DesignPackageType' from assembly 'Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. At line:1 char:1 + Import-Module Microsoft.Online.SharePoint.PowerShell + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Import-Module], TypeLoadException + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand I have this binary module installed: Directory: C:\Program Files\WindowsPowerShell\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 16.0.86... Microsoft.Online.SharePoint.Powe... Binary 16.0.80... Microsoft.Online.SharePoint.Powe... Any clues?172KViews0likes27CommentsHow to uploads files to OneDrive for Business using Powershell
I tried the sample powershell code in below link, getting error as path not found. https://community.spiceworks.com/topic/2001221-powershell-script-to-upload-file-to-onedrive-business Same error with any onedrive folder. Can anyone share any sample and the settings I need to do in my OneDrive account for scripting.133KViews0likes13CommentsLast Logon time
Is there anyway to download via powershell the last login time for all users? Currently I'm using "Get-EXOMailboxStatistics" but this requires you to provide a username and only obtains the stats for this user, the problem being we have over 300,000 users so this takes nearly a week to run!!!!!66KViews0likes8CommentsScript to export to CSV all Mailboxes and SharedMailboxes
Hi, I'm trying to make a new script in Powershell to display (for a report) the following attributes in a CSV table like this: DisplayName UserPrincipalName Licenses RecipientTypeDetails TotalItemSize I need to be displayed the UserMailboxes and SharedMailboxes. I made separated scripts at first but i've to join all information on a unique file and it's a mess. Can anyone help me?54KViews0likes16CommentsPowershell for replacing primary email address and adding current primary to alias email addresses
We use a hybrid O365 environment. On-premise AD, using Azure AD sync, with all O365 mailboxes. We have about 120 mailboxes where we need to change their primary email domain to a new domain and ADD the existing primary email address as an alias, without deleting the existing aliases. We would like to use powershell, importing from a .csv file, but cannot determine the powershell syntax needed to handle both the primary replacement, and the addition of the current primary to the proxyaddresses field, without wiping out the existing proxyaddresses list. We were also considering running two separate powershells to handle this. The first one would replace the existing primary with the new email address, but we read that when you do that, it automatically adds the existing primary as an alias, which is what we want, but deletes the existing aliases, which we definitely do not want. Any help with a single script that would replace the primary, and ADD the existing primary as an alias would be appreciated. If a single script can't do this, is there a way to replace the existing primary with a new email address that does not wipe out the existing proxyaddresses list during the process? We would then run a second powershell to add an alias to the list. Thank you - AprilSolved50KViews0likes2CommentsUnable to Set-MailboxFolderPermission
Unable to Set-MailboxFolderPermission example@test.fi -user Default -accessrights reviewer. Error message says that "There is no existing permission entry found for user".. We think this is because of Finnish language settings that automatically convert value "Default" to "Oletus" in powershell: Error on proxy command 'Set-MailboxFolderPermission -User:'Oletus' -AccessRights:'Reviewer' -Identity:'example@test.fi' -Confirm:$False' to server AM6PR01MB4295.eurprd01.prod.exchangelabs.com: Server version 15.20.1856.00 00, Proxy method PSWS: Cmdlet error with following error message: Microsoft.Exchange.Management.StoreTasks.UserNotFoundInPermissionEntryException: There is no existing permission entry found for user: Oletus. at Microsoft.Exchange.Management.StoreTasks.SetMailboxFolderPermissionBase.ThrowUserNotFoundException() at Microsoft.Exchange.Management.StoreTasks.SetMailboxFolderPermission.InternalProcessPermissions(Folder folder) at Microsoft.Exchange.Management.StoreTasks.SetMailboxFolderPermissionBase.InternalProcessRecord() at Microsoft.Exchange.Configuration.Tasks.Task.<ProcessRecord>b__93_1() at Microsoft.Exchange.Configuration.Tasks.Task.InvokeRetryableFunc(String funcName, Action func, Boolean terminatePi pelineIfFailed). [Server=DB6P190MB0311,RequestId=46a17ea7-9add-47bc-abee-499e5e64e66c,TimeStamp=7.5.2019 8.31.23] . + CategoryInfo : NotSpecified: (:) [Set-MailboxFolderPermission], CmdletProxyException + FullyQualifiedErrorId : Microsoft.Exchange.Configuration.CmdletProxyException,Microsoft.Exchange.Management.Stor eTasks.SetMailboxFolderPermission + PSComputerName : outlook.office365.com Any ideas?Solved36KViews0likes5CommentsPowerShell script to export Audit log search Data based on userID filter
Office 365 Audit Log platform is helping you to monitor and control activities on your tenant. In some case, it's necessary to export some user activity to detect some problematic usage. FROM WEB ADMIN SITE It's possible to do that export from the dedicated Admin site "Security & Compliance": https://protection.office.com/?rfr=AdminCenter#/unifiedauditlog You can select certain filter options to focus on your question based on: Activity type Start & End DateTime UsersID (email or O365 login) File, folder, url or site this filterset will be used: to execute the search and export the resultset (in CSV format) to create an alert You can find a lot of details related to that Audit Log usage: https://docs.microsoft.com/en-us/office365/securitycompliance/search-the-audit-log-in-security-and-compliance#search-the-audit-log But some important restrictions need to be accepted before work with that solution: Number of lines (or Events) is limited to 50’000 max Number of characters exported to the AuditData details is restricted to the first 3’060 chars FROM POWERSHELL Based on many other articles and blogposts, I wrote a dedicated PowerShell script like a toolkit you can use to connect directly Office 365 Audit Log system and send the filters you need to get the result set in memory. Based on that results, the script will directly extract the AuditData field and convert it into a CSV file with many fields (extracted form the JSON Format) The PowerShell command used is: Search-UnifiedAuditLog - https://docs.microsoft.com/en-us/powershell/module/exchange/policy-and-compliance-audit/search-unifiedauditlog?view=exchange-ps Function Split-O365AuditLogs-FromO365 () { #Get the content to process Write-host " -----------------------------------------" -ForegroundColor Green [string]$username = "YourAdminAccount@yourtenant.onmicrosoft.com" [string]$PwdTXTPath = "C:\SECUREDPWD\ExportedPWD-$($username).txt" $secureStringPwd = ConvertTo-SecureString -string (Get-Content $PwdTXTPath) $UserCredential = New-Object System.Management.Automation.PSCredential $username, $secureStringPwd #This will prompt the user for credential # $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-LiveID/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session [DateTime]$startDate = "01/01/2019 00:00" #Format: mm/dd/yyyy hh:MM [DateTime]$endDate = "01/11/2019 23:59" #Format: mm/dd/yyyy hh:MM $SpecifiedUserIDs = "Youremailtoscan@yourtenant.com", "Youremailtoscan2@yourtenant.com" #syntax: "<value1>","<value2>",..."<valueX>". $scriptStart=(get-date) $sessionName = (get-date -Format 'u')+'o365auditlog' # Reset user audit accumulator $aggregateResults = @() $i = 0 # Loop counter Do { Write-host " >> Audit Request Details: StartDate=", $startDate, "- EndDate=", $endDate, "SpecifiedUserIDs=", $SpecifiedUserIDs $currentResults = Search-UnifiedAuditLog -StartDate $startDate -EndDate $enddate -SessionId $sessionName -SessionCommand ReturnLargeSet -ResultSize 1000 -UserIds $SpecifiedUserIDs if ($currentResults.Count -gt 0) { Write-Host (" Finished {3} search #{1}, {2} records: {0} min" -f [math]::Round((New-TimeSpan -Start $scriptStart).TotalMinutes,4), $i, $currentResults.Count, $user.UserPrincipalName ) # Accumulate the data $aggregateResults += $currentResults # No need to do another query if the # recs returned <1k - should save around 5-10 sec per user if ($currentResults.Count -lt 1000) { $currentResults = @() } else { $i++ } } } Until ($currentResults.Count -eq 0) # --- End of Session Search Loop --- # [int]$IntemIndex = 1 $data=@() foreach ($line in $aggregateResults) { Write-host " ItemIndex:", $IntemIndex, "- Creation Date:", $line.CreationDate, "- UserIds:", $line.UserIds, "- Operations:", $line.Operations Write-host " > AuditData:", $line.AuditData $datum = New-Object -TypeName PSObject $Converteddata = convertfrom-json $line.AuditData $datum | Add-Member -MemberType NoteProperty -Name Id -Value $Converteddata.Id $datum | Add-Member -MemberType NoteProperty -Name CreationTimeUTC -Value $Converteddata.CreationTime $datum | Add-Member -MemberType NoteProperty -Name CreationTime -Value $line.CreationDate $datum | Add-Member -MemberType NoteProperty -Name Operation -Value $Converteddata.Operation $datum | Add-Member -MemberType NoteProperty -Name OrganizationId -Value $Converteddata.OrganizationId $datum | Add-Member -MemberType NoteProperty -Name RecordType -Value $Converteddata.RecordType $datum | Add-Member -MemberType NoteProperty -Name ResultStatus -Value $Converteddata.ResultStatus $datum | Add-Member -MemberType NoteProperty -Name UserKey -Value $Converteddata.UserKey $datum | Add-Member -MemberType NoteProperty -Name UserType -Value $Converteddata.UserType $datum | Add-Member -MemberType NoteProperty -Name Version -Value $Converteddata.Version $datum | Add-Member -MemberType NoteProperty -Name Workload -Value $Converteddata.Workload $datum | Add-Member -MemberType NoteProperty -Name UserId -Value $Converteddata.UserId $datum | Add-Member -MemberType NoteProperty -Name ClientIPAddress -Value $Converteddata.ClientIPAddress $datum | Add-Member -MemberType NoteProperty -Name ClientInfoString -Value $Converteddata.ClientInfoString $datum | Add-Member -MemberType NoteProperty -Name ClientProcessName -Value $Converteddata.ClientProcessName $datum | Add-Member -MemberType NoteProperty -Name ClientVersion -Value $Converteddata.ClientVersion $datum | Add-Member -MemberType NoteProperty -Name ExternalAccess -Value $Converteddata.ExternalAccess $datum | Add-Member -MemberType NoteProperty -Name InternalLogonType -Value $Converteddata.InternalLogonType $datum | Add-Member -MemberType NoteProperty -Name LogonType -Value $Converteddata.LogonType $datum | Add-Member -MemberType NoteProperty -Name LogonUserSid -Value $Converteddata.LogonUserSid $datum | Add-Member -MemberType NoteProperty -Name MailboxGuid -Value $Converteddata.MailboxGuid $datum | Add-Member -MemberType NoteProperty -Name MailboxOwnerSid -Value $Converteddata.MailboxOwnerSid $datum | Add-Member -MemberType NoteProperty -Name MailboxOwnerUPN -Value $Converteddata.MailboxOwnerUPN $datum | Add-Member -MemberType NoteProperty -Name OrganizationName -Value $Converteddata.OrganizationName $datum | Add-Member -MemberType NoteProperty -Name OriginatingServer -Value $Converteddata.OriginatingServer $datum | Add-Member -MemberType NoteProperty -Name SessionId -Value $Converteddata.SessionId $data += $datum $IntemIndex += 1 } $datestring = (get-date).ToString("yyyyMMdd-hhmm") $fileName = ("C:\AuditLogs\CSVExport\" + $datestring + ".csv") Write-Host (" >>> writing to file {0}" -f $fileName) $data | Export-csv $fileName -NoTypeInformation Remove-PSSession $Session } Split-O365AuditLogs-FromO365 You can use that script as you want and adapt it with your own needs Attention: AuditData limitation stay into the PowerShell option, but it's a MS Support Bug known as detailed into that following posts, I hope that will be fixed soon: https://techcommunity.microsoft.com/t5/Office-365/Incomplete-data-from-Search-UnifiedAuditLog-cmdlet-for-AzureAD/td-p/240805 https://office365itpros.com/2018/10/22/longer-retention-office365-auditdata/ Additional links: https://angryanalyticsblog.azurewebsites.net/index.php/2018/02/16/power-bi-audit-log-analytics-solution/ https://docs.microsoft.com/en-us/office365/securitycompliance/detailed-properties-in-the-office-365-audit-log https://docs.microsoft.com/en-us/office365/securitycompliance/detailed-properties-in-the-office-365-audit-log https://docs.microsoft.com/en-us/office365/securitycompliance/search-the-audit-log https://www.youtube.com/watch?v=KUyE59E3EFY https://blogs.msdn.microsoft.com/tehnoonr/2018/01/26/retrieving-office-365-audit-data-using-powershell/ https://office365itpros.com/2018/10/22/longer-retention-office365-auditdata/ https://docs.microsoft.com/en-us/powershell/module/exchange/policy-and-compliance-audit/search-unifiedauditlog?view=exchange-ps https://www.sherweb.com/blog/activity-reports-audit-logs-office-365/ http://alexbrassington.com/2016/03/03/splitting-office-365-audit-logs/ https://www.powershellgallery.com/packages/O365_Unified_Auditlog_parser/1.1/Content/O365_Unified_Auditlog_parser.ps1 Fabrice Romelard French version: http://blogs.developpeur.org/fabrice69/archive/2019/01/28/office-365-script-powershell-pour-extraire-les-audit-log-bas-s-sur-des-filtres-fournis.aspx31KViews1like3CommentsConfirm if items(Emails) purged after running New-ComplianceSearchAction in Compliance PowerShell
Hi Tech Community Folks, We have received a request to delete some items(Email Messages] from EXCHANGE. According to this guide, https://docs.microsoft.com/en-us/microsoft-365/compliance/search-for-and-delete-messages-in-your-organization?view=o365-worldwide I created my content search and ran it [ STEP1] It has found 44 items! Then as STEP2: I connected to Compliance & Security Center in PowerShell as Admin, and ran New-ComplianceSearchAction -SearchName "ABC_004_22_2" -Purge -PurgeType SoftDelete [ I ran this command atleast 10 times ] Once I get the status via: Get-ComplianceSearchAction -Identity 'ABC_004_22_2_Purge' | Format-list It shows the task has been completed... Name SearchName Action RunBy JobEndTime Status ---- ---------- ------ ----- ---------- ------ ABC_004_22_2_Purge ABC_004_22_2 Purge Fadavinia, Ali 2021/05/18 9:26:29 PM Completed Now my question is here: When I go to Security & Compliance --> Content Search and query my case again the results are still 44 items. What am I missing? how do I know if they are really deleted? Thanks for your thoughts and input AliSolved26KViews0likes7CommentsHow to get the manager with the get-user?
Hi, I've added managers to a handful of employees with the command line for the purpose of testing Set-User andy.kw -Manager Big.Boss I can see the manager through the graphical interface of Office 365 but when using the get-user cmdlet, nothing is coming. When looking at the https://technet.microsoft.com/en-us/library/aa996896%28v=exchg.160%29.aspx?f=255&MSPPError=-2147217396, nothing is mentioned though. Any ideas? Cheers, AndySolved18KViews0likes7Comments