@Windows PowerShell
35 TopicsExport 365 Users last logon time using powershell
I have created a PowerShell command that is supposed to export every users last logon time that is greater than 1 day. But it continues to create a blank document. Below is the command. Get-Mailbox -RecipientType 'UserMailbox' |%{ Get-MailboxStatistics $_.UserPrincipalName | Sort-Object LastLogonTime | Where {$_.LastLogonTime -lt ([System.DateTime]::Now).AddDays(-1) } | Export-Csv "C:\Logs\O365MAILBOXSTATS_REPORT1.CSV" -NoTypeInformation -Append}13KViews0likes2CommentsSet-ACL "Attempted to Perform an Unauthorized Operation"
Hi Folks, I'm currently working on automating security changes on Azure File Shares. As part of this process, I'd like to use Get-ACL and Set-ACL as the easiest ways to copy over a base set of permissions - icacls doesn't have as good functionality for this as it only allows restoring permissions to a file of the same name. However, whenever I use Set-ACL, I immediately get: Set-Acl : Attempted to perform an unauthorized operation. At line:1 char:55 + ... ath | Set-Acl -Path $concatPath + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: () [Set-Acl], UnauthorizedAccessException + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetAclCommand As a note I have removed path names. The account I'm using is a domain admin and has NTFS permission to the file. It can edit these permissions using the GUI with no issues. It also has an Elevated Contributor role in Azure AD, so it should be able to edit these ACLs. I've also tried the NTFSSecurity module, which has the same issues. Similarly, I have tried to mount the fileshare to a drive with New-PSDrive, in case that helped, but no luck there either. I'm pretty out of ideas here, and icacls will require a lot more logic work to strip back the inherited permissions to what I want them to be. If anyone has any other ideas, I'd love to hear them. Thanks in advance!9KViews0likes6CommentsGet-AzureADUserManager : Cannot bind argument to parameter 'ObjectId' because it is null.
Hi All, I am trying to fetch the Manager's Manager using the "Get-AzureADUserManager" function by passing ObjectId of manager. However while passing the manager's object to get his/her manager , getting an error below : Please help at the earliest. Code : foreach($user in $users) { $row = $Datatable.NewRow() $manager=Get-AzureADUserManager -ObjectId $user.ObjectId $seniorM=Get-AzureADUserManager -ObjectId $manager.ObjectId $row.Name=$user.GivenName $row.Surname=$user.Surname $row.manager=$manager.DisplayName $row.seniorM=$seniorM.DisplayName $Datatable.Rows.Add($row) } Error Message : Get-AzureADUserManager : Cannot bind argument to parameter 'ObjectId' because it is null. At line:29 char:43 + $seniorM=Get-AzureADUserManager -ObjectId $manager.ObjectId + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-AzureADUserManager], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Open.AzureAD16.PowerShell.GetUserManagerSolved8.7KViews0likes2CommentsShould I delete Windows Terminal or Administrator: Powershell?
I have had a major problem with hackers and cyber stalking for nearly a year. I just had the hard drive replaced for the second time in five months on my Dell Inspiron 7706 because of this. Today I discovered that my hacker has created a spoofed PowerShell Administrator ID, which allows her (them) to remotely access my laptop and insert viruses. Can I safely delete the "Administrator: PowerShell" or Windows Terminal without damaging my new hard drive? Thank you. @Windows PowerShell8KViews0likes2CommentsGet users from CSV, foreach user, get country, name, etc., then Export
Hi! I have a problem with PS query. I have a CSV file with +1000 userprincipalname. Id like to export that UPN and for each user get info like userprincipalname, title, country, department, enabled, then export to excel. My example queries: $csv = gc "C:\New folder\Users.csv" $Users=@() $csv | Foreach{ $elements=$_ -split(";") $Users+= ,@($elements[0]) } ForEach ($User in $Users) { Get-ADUser -filter "userPrincipalName -eq '$User'" -Properties * | Select-Object userprincipalname, title, country, department, enabled } OR $Users = Get-contect -path "C:\New folder\Users.csv" ForEach ($User in $Users) { Get-ADUser -filter "userPrincipalName -eq '$User'" -Properties * | Select-Object userprincipalname, title, country, department, enabled } OR $Users = Get-contect -path "C:\New folder\Users.csv" ForEach ($User in $Users) { Get-ADUser -filter $User -Properties * | Select-Object userprincipalname, title, country, department, enabled } My excel has UPN only, like: mailto:email address removed for privacy reasons mailto:email address removed for privacy reasons etc. No headers. Someone will help? 😞7.6KViews0likes2CommentsPowershell script to add new Network Location for multiple storage volumes?
Hello, Under the "Network Locations" section within "This PC", it is possible to add an infinite(?) amount of network locations using the Add Network Location Wizard. I'm having trouble finding a Powershell script that accomplishes the same thing as this wizard. At my workplace, all 26 drive letters are full and we would like to switch over to network locations to have easy access to more storage volumes. We will need the location to show within the "Network Locations" section within "This PC" and to appear in the left hand column under "This PC", similar to how mounted drives display this way. Thanks!4.7KViews0likes3CommentsHelp with Watcher
Hey guys, some of you can help me to check what is wrong with this script? thank you in advance! # Cartella da monitorare (stessa cartella) $cartellaDaMonitorare = "C:\TEST" # Crea un registro per i file già rinominati $registroFileRinominati = "C:\TEST\registro.txt" # Funzione per rinominare i file MSG con data e ora function Rinomina-FileMSG { param ( [string]$file ) if ($file -match "\.msg$" -and -not $registroFileRinominati.ContainsKey($file)) { $now = Get-Date -Format "yyyyMMddHHmm" $nomeFile = [System.IO.Path]::GetFileNameWithoutExtension($file) $estensione = [System.IO.Path]::GetExtension($file) $nuovoNome = "${now}_${nomeFile}${estensione}" Rename-Item -Path $file -NewName $nuovoNome Write-Host "Rinominato $file in $nuovoNome" $registroFileRinominati[$file] = $true } } # Crea un oggetto FileSystemWatcher per monitorare la cartella $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = $cartellaDaMonitorare $watcher.Filter = "*.msg" $watcher.IncludeSubdirectories = $true $watcher.EnableRaisingEvents = $true # Azione da intraprendere quando viene rilevato un nuovo file $action = { $changeType = $Event.SourceEventArgs.ChangeType $file = $Event.SourceEventArgs.FullPath if ($changeType -eq "Created" -or $changeType -eq "Renamed") { Rinomina-FileMSG -file $file } } # Associa l'azione all'evento Created e Renamed Register-ObjectEvent -InputObject $watcher -EventName Created -Action $action Register-ObjectEvent -InputObject $watcher -EventName Renamed -Action $action # Attendi che lo script venga interrotto Write-Host "Waiting for new MSG files..." while ($true) { Start-Sleep -Seconds 30 }Solved4.1KViews0likes28CommentsDownload Specific Files From Link
https://www.fbi.gov/wanted/topten/alejandro-castillo/download.pdf Hi here is the link i need to download the file , between the /topten and /download.pdf is the person name. And the website will update everyday so if i want download all the file how can i write. Cuz if i just use the link https://www.fbi.gov/wanted/topten is will jump out the message:Content-Disposition header not found for URL: https://www.fbi.gov/wanted/toptenSolved3.1KViews0likes20CommentsError using Remove-AdminPowerApp in the Microsoft.PowerApps.Administration.PowerShell module
I am trying to use `Remove-AdminPowerApp`. I am a PowerPlatform admin, and I am running PowerShell in Administrator mode. The error says: "InvokeApi : The term 'Test-PowerAppsAccount' is not recognized as the name of a cmdlet, function, script file, or operable program." When I try to `Install-Module -name Microsoft.PowerApps.Administration.PowerShell`, the error says, "The following commands are already available on this system:'Add-PowerAppsAccount, Get-JwtToken, Get-TenantDetailsFromGraph, Get-UsersOrGroupsFromGraph, InvokeApi, Remove-PowerAppsAccount, ReplaceMacro, Select-CurrentEnvironment, Test-PowerAppsAccount'." The ISE shows:  Solved2.8KViews0likes8CommentsHow to remove ".." in csv
Hello I am pretty green at this so please forgive me if this is a real stupid question... I need to run a SQLCMD on a server 2019 machine and export results to a CSV. I have tried to format the output file in the SQLCMD and while it almost works I Have had some issues with the formatting. It was suggested that I use PowerShell and the export-CSV command and I can tell the results are better and almost have it working but the export-csv command puts ".." around the data as you see below. the top line are headers and that is OK but I need to find a way to strip the quotes. If I open it in excel, excel strips the quotes but I do not use excel, it needs to be directly imported into another program and the quotes are causing a problem. I found an article on stackoverflow, but to be honest I get a little intimidated when I try to look at Stackoverflow because I am so green and when I have tried to ask a newbie question, they get frustrated at me. Below you will find the full PowerShell script I am trying to run... I tried to adopt the syntax from an example of the export-csv command from a stackoverflow post, but I had some confusion since they were talking about things that work and do not work on PowerShell version 7. and based on the error I am getting; I do not think this command is complete... invoke-sqlcmd -server 192.168.0.4 -Username PAReadonly2 -password <password> -database lc_V3_acephoto_net -inputfile "C:\Users\Amber\Documents\SQL Server Management Studio\MPNsimple.sql" | export-csv -NOTYPEINFORMATION | -path c:\junk\test.csv Select-Object -Skip 1 | ForEach-Object { $_ -replace '"' } | Set-Content $NewCSV I am running windows server 2019 PowerShell 5.1.14463 As FYI.. I have tried to install PowerShell 7 but I got some kind of error when I run my script because SQLCMD would not run. any help or guidance (even a little pity) would be appreciated. thanks Gary2.1KViews0likes4Comments