sharepoint
131 TopicsWARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/.....' is not valid
Hello, I was trying install the PowerShell Module to a server and getting error message with not valid url. Debug log attached. PS C:\windows\system32> Install-Module SharePointPnPPowerShellOnline -Force -Debug DEBUG: 00:00:00.0000002 Calling New() : MethodName = 'GetDynamicOptions' Confirm Continue with this operation? [Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): a DEBUG: 00:00:00.0000300 Force: True DEBUG: 00:00:00.0000445 Debug: True DEBUG: 00:00:00.0000573 Name: SharePointPnPPowerShellOnline DEBUG: 00:00:00.0011177 INVOKING PowerShell Fn Get-DynamicOptions with args Provider that has length 1 DEBUG: 00:00:00.0019006 In PowerShellGet Provider - 'Get-DynamicOptions'. DEBUG: 00:00:00.0039875 Done calling powershell «Get-DynamicOptions» «PSModule» DEBUG: 00:00:00.0100688 Calling New() : MethodName = 'GetDynamicOptions' DEBUG: 00:00:00.0100914 Force: True DEBUG: 00:00:00.0101568 Debug: True DEBUG: 00:00:00.0101735 Name: SharePointPnPPowerShellOnline DEBUG: 00:00:00.0109507 INVOKING PowerShell Fn Get-DynamicOptions with args Source that has length 1 DEBUG: 00:00:00.0115616 In PowerShellGet Provider - 'Get-DynamicOptions'. DEBUG: 00:00:00.0144311 Done calling powershell «Get-DynamicOptions» «PSModule» DEBUG: 00:00:00.0181073 Calling New() : MethodName = 'GetDynamicOptions' DEBUG: 00:00:00.0181315 Force: True DEBUG: 00:00:00.0181464 Debug: True DEBUG: 00:00:00.0181607 Name: SharePointPnPPowerShellOnline DEBUG: 00:00:00.0188111 INVOKING PowerShell Fn Get-DynamicOptions with args Package that has length 1 DEBUG: 00:00:00.0194829 In PowerShellGet Provider - 'Get-DynamicOptions'. DEBUG: 00:00:00.0243662 Done calling powershell «Get-DynamicOptions» «PSModule» DEBUG: 00:00:00.0276450 Calling New() : MethodName = 'GetDynamicOptions' DEBUG: 00:00:00.0276668 Force: True DEBUG: 00:00:00.0276801 Debug: True DEBUG: 00:00:00.0276931 Name: SharePointPnPPowerShellOnline DEBUG: 00:00:00.0284428 INVOKING PowerShell Fn Get-DynamicOptions with args Install that has length 1 DEBUG: 00:00:00.0290814 In PowerShellGet Provider - 'Get-DynamicOptions'. DEBUG: 00:00:00.0338093 Done calling powershell «Get-DynamicOptions» «PSModule» DEBUG: 00:00:02.4736146 Calling SearchForPackages. Name='SharePointPnPPowerShellOnline' VERBOSE: Using the provider 'PowerShellGet' for searching packages. Confirm Continue with this operation? [Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): a DEBUG: 00:00:02.4747220 PackageProvider::FindPackage with name SharePointPnPPowerShellOnline DEBUG: 00:00:02.4749508 Calling SearchForPackages After Select 1 DEBUG: 00:00:07.4799484 Calling New() : MethodName = 'FindPackage' DEBUG: 00:00:07.4800187 ProviderName: PowerShellGet DEBUG: 00:00:07.4800527 Type: Module DEBUG: 00:00:07.4800683 MessageResolver: Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString DEBUG: 00:00:07.4801181 Force: True DEBUG: 00:00:07.4801320 Debug: True DEBUG: 00:00:07.4801456 Scope: AllUsers DEBUG: 00:00:07.4801619 Name: SharePointPnPPowerShellOnline DEBUG: 00:00:07.4810098 INVOKING PowerShell Fn Find-Package with args System.String[], , , that has length 4 DEBUG: 00:00:07.4832297 In PowerShellGet Provider - 'Find-Package'. DEBUG: 00:00:07.4839335 OPTION: ProviderName => PowerShellGet DEBUG: 00:00:07.4841374 OPTION: Type => Module DEBUG: 00:00:07.4843299 OPTION: MessageResolver => Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString DEBUG: 00:00:07.4848048 OPTION: Force => True DEBUG: 00:00:07.4849908 OPTION: Debug => True DEBUG: 00:00:07.4851678 OPTION: Scope => AllUsers DEBUG: 00:00:07.4853432 OPTION: Name => SharePointPnPPowerShellOnline VERBOSE: The -Repository parameter was not specified. PowerShellGet will use all of the registered repositories. VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'. VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'. DEBUG: 00:00:07.4907353 PackageProvider::FindPackage with name SharePointPnPPowerShellOnline DEBUG: 00:00:07.4932458 Calling 'NuGet'::'FindPackage' - name='SharePointPnPPowerShellOnline', requiredVersion='',minimumVersion='', maximumVersion='''. DEBUG: 00:00:07.4932826 Iterating 'SharePointPnPPowerShellOnline'. DEBUG: 00:00:07.4935582 There are '0' registered sources in 'NuGet' provider. DEBUG: 00:00:07.4936600 Source 'https://www.powershellgallery.com/api/v2' is not one of the registered sources in 'NuGet' provider. DEBUG: 00:00:09.6490403 Source 'https://www.powershellgallery.com/api/v2' is validated. DEBUG: 00:00:09.6491100 Calling 'NuGetRequest'::'GetPackageById', 'SharePointPnPPowerShellOnline'. DEBUG: 00:00:10.9249696 Calling 'HttpClientPackageRepository'::'FindPackagesById', 'SharePointPnPPowerShellOnline'. DEBUG: 00:00:10.9250551 Calling 'NuGetClient'::'FindPackage'. VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'' for ''. DEBUG: 00:00:10.9253313 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=0&$top=40'. DEBUG: 00:00:12.6410092 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=0&$top=40'. DEBUG: 00:00:12.6506047 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=80&$top=40'. DEBUG: 00:00:12.6506065 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=40&$top=40'. DEBUG: 00:00:12.6506379 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=120&$top=40'. DEBUG: 00:00:12.6508283 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=160&$top=40'. DEBUG: 00:00:13.9261883 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=120&$top=40'. DEBUG: 00:00:13.9265741 '0' packages received in the last request. DEBUG: 00:00:14.6035386 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=80&$top=40'. DEBUG: 00:00:14.6036603 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=160&$top=40'. DEBUG: 00:00:14.6038273 '0' packages received in the last request. DEBUG: 00:00:14.6039490 '0' packages received in the last request. DEBUG: 00:00:15.6130985 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=40&$top=40'. DEBUG: 00:00:15.6178721 '30' packages received in the last request. VERBOSE: Total package yield:'1' for the specified package 'SharePointPnPPowerShellOnline'. DEBUG: 00:00:15.6207643 Completed iterating for 'SharePointPnPPowerShellOnline'. DEBUG: 00:00:15.6470655 Done calling powershell «Find-Package» «PSModule» DEBUG: 00:00:15.6537227 Calling New() : MethodName = 'GetInstalledPackages' DEBUG: 00:00:15.6537527 ProviderName: PowerShellGet DEBUG: 00:00:15.6537681 Type: Module DEBUG: 00:00:15.6537823 MessageResolver: Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString DEBUG: 00:00:15.6537965 Force: True DEBUG: 00:00:15.6538090 Debug: True DEBUG: 00:00:15.6538215 Scope: AllUsers DEBUG: 00:00:15.6538346 Name: SharePointPnPPowerShellOnline DEBUG: 00:00:15.6543655 INVOKING PowerShell Fn Get-InstalledPackage with args SharePointPnPPowerShellOnline, 3.19.2003.0, , that has length 4 DEBUG: 00:00:15.6550981 In PowerShellGet Provider - 'Get-InstalledPackage'. DEBUG: 00:00:15.6553113 OPTION: ProviderName => PowerShellGet DEBUG: 00:00:15.6554848 OPTION: Type => Module DEBUG: 00:00:15.6556921 OPTION: MessageResolver => Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString DEBUG: 00:00:15.6558915 OPTION: Force => True DEBUG: 00:00:15.6560733 OPTION: Debug => True DEBUG: 00:00:15.6562478 OPTION: Scope => AllUsers DEBUG: 00:00:15.6564270 OPTION: Name => SharePointPnPPowerShellOnline DEBUG: 00:00:17.6364439 PowerShell Script 'PSModule' Function 'Get-InstalledPackage' returns null. DEBUG: 00:00:17.6372045 Done calling powershell «Get-InstalledPackage» «PSModule» Confirm Are you sure you want to perform this action? Performing the operation "Install Package" on target "Package 'SharePointPnPPowerShellOnline' version '3.19.2003.0' from 'PSGallery'.". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): a DEBUG: 00:00:42.9836594 Calling New() : MethodName = 'InstallPackage' DEBUG: 00:00:42.9836941 ProviderName: PowerShellGet DEBUG: 00:00:42.9837229 Type: Module DEBUG: 00:00:42.9837425 MessageResolver: Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString DEBUG: 00:00:42.9837575 Force: True DEBUG: 00:00:42.9837714 Debug: True DEBUG: 00:00:42.9837853 Scope: AllUsers DEBUG: 00:00:42.9837996 Name: SharePointPnPPowerShellOnline DEBUG: 00:00:42.9845292 INVOKING PowerShell Fn Install-Package with args NuGet|SharePointPnPPowerShellOnline|3.19.2003.0|https://www.powershellgallery.com/api/v2|Module that has length 1 DEBUG: 00:00:42.9862372 In PowerShellGet Provider - 'Install-Package'. DEBUG: 00:00:42.9869454 In PowerShellGet Provider - 'Install-PackageUtility'. DEBUG: 00:00:42.9871604 The FastPackageReference is 'NuGet|SharePointPnPPowerShellOnline|3.19.2003.0|https://www.powershellgallery.com/api/v2|Module'. DEBUG: 00:00:42.9875296 OPTION: ProviderName => PowerShellGet DEBUG: 00:00:42.9878200 OPTION: Type => Module DEBUG: 00:00:42.9880217 OPTION: MessageResolver => Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString DEBUG: 00:00:42.9882389 OPTION: Force => True DEBUG: 00:00:42.9884634 OPTION: Debug => True DEBUG: 00:00:42.9887816 OPTION: Scope => AllUsers DEBUG: 00:00:42.9889883 OPTION: Name => SharePointPnPPowerShellOnline VERBOSE: The installation scope is specified to be 'AllUsers'. VERBOSE: The specified module will be installed in 'C:\Program Files\WindowsPowerShell\Modules'. DEBUG: 00:00:42.9903760 ArtfactType is Module VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'. VERBOSE: Downloading module 'SharePointPnPPowerShellOnline' with version '3.19.2003.0' from the repository 'https://www.powershellgallery.com/api/v2'. DEBUG: 00:00:44.6681094 Calling 'NuGet'::'InstallPackage', '$aHR0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\U2hhcmVQb2ludFBuUFBvd2VyU2hlbGxPbmxpbmU=\My4xOS4yMDAzLjA=\aH R0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\cG93ZXJzaGVsbGdldA=='. DEBUG: 00:00:44.6683081 Calling 'NuGetRequest'::'GetPackageByFastpath', '$aHR0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\U2hhcmVQb2ludFBuUFBvd2VyU2hlbGxPbmxpbmU=\My4xOS4yMDAzLjA=\aH R0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\cG93ZXJzaGVsbGdldA=='. DEBUG: 00:00:44.6684489 Calling 'NuGetRequest'::'ResolvePackageSource', 'https://www.powershellgallery.com/api/v2'. DEBUG: 00:00:44.6684779 Calling 'NuGetRequest'::'FindRegisteredSource', 'https://www.powershellgallery.com/api/v2'. DEBUG: 00:00:44.6685047 Source 'https://www.powershellgallery.com/api/v2' is not one of the registered sources in 'NuGet' provider. DEBUG: 00:00:48.8501172 Calling 'HttpClientPackageRepository'::'FindPackage', 'SharePointPnPPowerShellOnline'. DEBUG: 00:00:48.8501805 Calling 'NuGetClient'::'FindPackage'. VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'' for ''. DEBUG: 00:00:48.8502893 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=0&$top=40'. DEBUG: 00:00:52.1960762 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=0&$top=40'. DEBUG: 00:00:52.2099144 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=40&$top=40'. DEBUG: 00:00:52.2100909 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=120&$top=40'. DEBUG: 00:00:52.2100942 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=80&$top=40'. DEBUG: 00:00:52.2101002 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=160&$top=40'. DEBUG: 00:00:53.6597300 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=80&$top=40'. DEBUG: 00:00:53.6599788 '0' packages received in the last request. DEBUG: 00:00:54.1614418 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=120&$top=40'. DEBUG: 00:00:54.1614464 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=160&$top=40'. DEBUG: 00:00:54.1616464 '0' packages received in the last request. DEBUG: 00:00:54.1618585 '0' packages received in the last request. DEBUG: 00:00:55.6163522 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='SharePointPnPPowerShellOnline'&$skip=40&$top=40'. DEBUG: 00:00:55.6251832 '30' packages received in the last request. DEBUG: 00:00:55.6271792 'Package version' is '3.19.2003.0'. DEBUG: 00:00:55.6272337 'Request's Destination' is 'C:\Users\kvanoop\AppData\Local\Temp\398316225'. DEBUG: 00:00:55.6272632 Calling 'NuGetClient'::'GetPackageDependencies'. DEBUG: 00:00:55.6273996 Returning the call 'NuGetClient'::'GetPackageDependencies'. DEBUG: 00:00:55.6275763 Calling 'NuGetClient'::'InstallPackage'. VERBOSE: InstallPackage' - name='SharePointPnPPowerShellOnline', version='3.19.2003.0',destination='C:\Users\kvanoop\AppData\Local\Temp\398316225' VERBOSE: DownloadPackage' - name='SharePointPnPPowerShellOnline', version='3.19.2003.0',destination='C:\Users\kvanoop\AppData\Local\Temp\398316225\SharePointPnPPowerShellOnline\SharePoi ntPnPPowerShellOnline.nupkg', uri='https://www.powershellgallery.com/api/v2/package/SharePointPnPPowerShellOnline/3.19.2003' VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/SharePointPnPPowerShellOnline/3.19.2003'. VERBOSE: An error occurred while sending the request. DEBUG: 00:00:57.0212206 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.PackageManagement.NuGetProvider.NuGetClient.<DownloadDataToFileAsync>d__15.MoveNext() VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/SharePointPnPPowerShellOnline/3.19.2003' for '2' more times VERBOSE: An error occurred while sending the request. DEBUG: 00:00:57.8874097 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.PackageManagement.NuGetProvider.NuGetClient.<DownloadDataToFileAsync>d__15.MoveNext() VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/SharePointPnPPowerShellOnline/3.19.2003' for '1' more times VERBOSE: An error occurred while sending the request. DEBUG: 00:00:58.7402606 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.PackageManagement.NuGetProvider.NuGetClient.<DownloadDataToFileAsync>d__15.MoveNext() VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/SharePointPnPPowerShellOnline/3.19.2003' for '0' more times VERBOSE: Downloading package 'SharePointPnPPowerShellOnline' failed, please make sure 'https://www.powershellgallery.com/api/v2/package/SharePointPnPPowerShellOnline/3.19.2003' is accessable. WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/SharePointPnPPowerShellOnline/3.19.2003' is not valid. Confirm Continue with this operation? [Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): a PS C:\windows\system32>Solved152KViews0likes13CommentsThreat Hunting with PowerShell - Security even with a small budget - there is no excuse!
Dear Threat Hunter, Lack of IT security is often excused by little or no available money. In my view, this is a very poor excuse. In this article I will try to give you a jump start on how to investigate threats with PowerShell. Is this a comprehensive and conclusive list of how you can find or detect threats/threats? NO, absolutely not. But it is meant to provide you with the support that you need to move forward on your own. Let's talk about the "general conditions": 1. If you use the PowerShell scripts I show/explain in this article, this is entirely your responsibility. I use the scripts in different situations, they are not dangerous, but you should already know what you are doing. 2. Written permission! If you are not sure if you are allowed to do an investigation, organize a written permission from your supervisor. 3. In the different scripts I sometimes (for this article deliberately) use standard search words like "malware", "malicious", "hacker" etc. Such search patterns/search words need to be customized, of course. These simply serve as an example. 4. The last part of the article examines some Microsoft cloud services. I am absolutely aware that there are a huge number of tools for hunting in the Microsoft cloud services. It starts with Azure Sentinel and continues with Cloud App Security. Since the focus is on a small budget, I'll leave those tools on the side. Introduction: So first, why should you use PowerShell for threat hunting? PowerShell is a useful threat hunting tool because it is a powerful scripting language and a platform for automating tools and accessing data across any Windows environment. It allows you to quickly gather information from various sources such as event logs, registries, files, and processes. Additionally, it can also be easily integrated with other tools and technologies making it a flexible and efficient tool for threat hunting. Some common use cases for PowerShell in the threat hunting environment include automated collection of log data, identification of unusual behavior anomalies in the system, the discovery of malware or malicious activity by known signatures or patterns or behaviors. These are just a few examples of how PowerShell can be used in a threat hunting capacity. Its versatility and ability to access and manipulate data from across the Windows environment make it a very valuable tool for any security professional. Threat Hunting in PowerShell - Use Cases: All right. So now that we understand where PowerShell can benefit an organization from a threat hunting perspective. Let's take a deeper look at some of the actual use cases you might encounter on a day to day basis, first being identify malicious processor files. So specifically, you can conduct raw file analysis to sift through different data shares to look for particular files in question whether that be a signature or even an extension of a certain file being able to quickly search and triage through files is an extreme benefit of using PowerShell for threat hunting. But how exactly do we start, what can we use as a guide? For example, the MITRE ATT&CK Framework. Here are a few examples: Indicator Removal: Clear Windows Event Logs https://attack.mitre.org/techniques/T1070/001/ Event Triggered Execution: Installer Packages https://attack.mitre.org/techniques/T1546/016/ Hide Artifacts: NTFS File Attributes https://attack.mitre.org/techniques/T1564/004/ Command and Scripting Interpreter: PowerShell https://attack.mitre.org/techniques/T1059/001/ Command and Scripting Interpreter: Windows Command Shell https://attack.mitre.org/techniques/T1059/003/ Event Triggered Execution: Windows Management Instrumentation Event Subscription https://attack.mitre.org/techniques/T1546/003/ Credentials from Password Stores: Windows Credential Manager https://attack.mitre.org/techniques/T1555/004/ Abuse Elevation Control Mechanism: Bypass User Account Control https://attack.mitre.org/techniques/T1548/002/ The MITRE ATT@CK framework provides a comprehensive and regularly updated overview of tactics, techniques, and procedures (TTPs) used by various threat actors. We can locate these TTPs using PowerShell, here are a few examples: Indicator Removal: Clear Windows Event Logs https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/06_Account_Events.ps1 Event Triggered Execution: Installer Packages https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/08_Get-ItemProperty_Software.ps1 Hide Artifacts: NTFS File Attributes https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/08_Get-ItemProperty_Software.ps1 Windows Installer Service is running https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/01_WIS_is_running.ps1 Search Alternate Data Streams on NTFS File Systems https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/02_Search_ADS_on_NTFS%20_(specific%20file).ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/03_Search_ADS_on_NTFS_file_systems.ps1 Read the Contents of a File https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/06_Read_the_contents_file.ps1 Locating Data Patterns within a File https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/05_locating_data_patterns_within_file.ps1 Search for Encoding with Regex https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/07_Search_encoding_with_regex.ps1 Search for Command and Scripting Interpreter: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/04_Searching_for_PIDs.ps1 Threat hunting in different environments with PowerShell: Coming examples are about collecting information in very different environments. Also here a few examples as a kind => as first starting points: Hunt for Threats in Active Directory: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/01_Resetting_Password_Unlocking_Accounts.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/02_Search_stale_accounts.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/03_Users_without_Manager.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/04_Password_Expiration.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/05_Group_Membership_Report.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/06_Account_Events.ps1 https://github.com/tomwechsler/Active_Directory_Advanced_Threat_Hunting/blob/main/PowerShell/Tracking_the_Source_of_Account_Lock_Outs_and_Bad_Passwords.ps1 https://github.com/tomwechsler/Active_Directory_Advanced_Threat_Hunting/blob/main/PowerShell/Finding_Unused_Group_Policy_Objects.ps1 Some of the scripts are structured in such a way that they must be executed block by block/line by line. So do not execute the whole script at once. Pay attention to the different information that is collected. With some investigations in the Active Directory accounts can be indicated like "guest" or "krbtgt", there must be clear of course how this information is to be estimated. Depending on how and what information is searched. Hunt for Threats in Exchange Online: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Exchange_Online/Exchange_Mailbox_LastLogin.ps1 Find mailboxes with the last login. Hunt for Threats in Azure: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Azure/Collect_vms_subscription.ps1 We search Azure for all virtual machines in a subscription. https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Azure/02_Graph_Create_Time_Last_Password.ps1 When was the last password change and when were the accounts created? Hunt for Threats in SharePoint: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_SharePoint_Online/SharePoint_Online_specific_files.ps1 With this script we search for files with the extension .ps1 in a SharePoint Online page. Summary: Is this the best tactic to hunt for threats? No! There are many different tactics/techniques to search for threats. First of all, there are a huge number of different tools that can be used, for example SIEM/SOAR (Security Information and Event Management/Security Orchestration, Automation and Response). These tools are really great, sometimes cost a lot and often it takes a lot of knowledge to use such tools. But what is the use of such tools if the information generated by these tools cannot be understood properly, not very much. For this reason, I have tried in this article with simple tools to generate information that hopefully can be interpreted. Is finished here at this point. NO, the journey continues. The examples in this article are neither exhaustive nor complete, but they should give you a starting point. I hope you can build on this foundation. I hope that this information is helpful to you and that you have received a good "little" foundation. But I still hope that this information is helpful for you. Thank you for taking the time to read the article. Happy Hunting, Tom Wechsler P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler63KViews5likes0CommentsThreat Hunting with PowerShell - Security even with a small budget - there is no excuse!
Dear Threat Hunter, Lack of IT security is often excused by little or no available money. In my view, this is a very poor excuse. In this article I will try to give you a jump start on how to investigate threats with PowerShell. Is this a comprehensive and conclusive list of how you can find or detect threats/threats? NO, absolutely not. But it is meant to provide you with the support that you need to move forward on your own. Let's talk about the "general conditions": 1. If you use the PowerShell scripts I show/explain in this article, this is entirely your responsibility. I use the scripts in different situations, they are not dangerous, but you should already know what you are doing. 2. Written permission! If you are not sure if you are allowed to do an investigation, organize a written permission from your supervisor. 3. In the different scripts I sometimes (for this article deliberately) use standard search words like "malware", "malicious", "hacker" etc. Such search patterns/search words need to be customized, of course. These simply serve as an example. 4. The last part of the article examines some Microsoft cloud services. I am absolutely aware that there are a huge number of tools for hunting in the Microsoft cloud services. It starts with Azure Sentinel and continues with Cloud App Security. Since the focus is on a small budget, I'll leave those tools on the side. Introduction: So first, why should you use PowerShell for threat hunting? PowerShell is a useful threat hunting tool because it is a powerful scripting language and a platform for automating tools and accessing data across any Windows environment. It allows you to quickly gather information from various sources such as event logs, registries, files, and processes. Additionally, it can also be easily integrated with other tools and technologies making it a flexible and efficient tool for threat hunting. Some common use cases for PowerShell in the threat hunting environment include automated collection of log data, identification of unusual behavior anomalies in the system, the discovery of malware or malicious activity by known signatures or patterns or behaviors. These are just a few examples of how PowerShell can be used in a threat hunting capacity. Its versatility and ability to access and manipulate data from across the Windows environment make it a very valuable tool for any security professional. Threat Hunting in PowerShell - Use Cases: All right. So now that we understand where PowerShell can benefit an organization from a threat hunting perspective. Let's take a deeper look at some of the actual use cases you might encounter on a day to day basis, first being identify malicious processor files. So specifically, you can conduct raw file analysis to sift through different data shares to look for particular files in question whether that be a signature or even an extension of a certain file being able to quickly search and triage through files is an extreme benefit of using PowerShell for threat hunting. But how exactly do we start, what can we use as a guide? For example, the MITRE ATT&CK Framework. Here are a few examples: Indicator Removal: Clear Windows Event Logs https://attack.mitre.org/techniques/T1070/001/ Event Triggered Execution: Installer Packages https://attack.mitre.org/techniques/T1546/016/ Hide Artifacts: NTFS File Attributes https://attack.mitre.org/techniques/T1564/004/ Command and Scripting Interpreter: PowerShell https://attack.mitre.org/techniques/T1059/001/ Command and Scripting Interpreter: Windows Command Shell https://attack.mitre.org/techniques/T1059/003/ Event Triggered Execution: Windows Management Instrumentation Event Subscription https://attack.mitre.org/techniques/T1546/003/ Credentials from Password Stores: Windows Credential Manager https://attack.mitre.org/techniques/T1555/004/ Abuse Elevation Control Mechanism: Bypass User Account Control https://attack.mitre.org/techniques/T1548/002/ The MITRE ATT@CK framework provides a comprehensive and regularly updated overview of tactics, techniques, and procedures (TTPs) used by various threat actors. We can locate these TTPs using PowerShell, here are a few examples: Indicator Removal: Clear Windows Event Logs https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/06_Account_Events.ps1 Event Triggered Execution: Installer Packages https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/08_Get-ItemProperty_Software.ps1 Hide Artifacts: NTFS File Attributes https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/08_Get-ItemProperty_Software.ps1 Windows Installer Service is running https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/01_WIS_is_running.ps1 Search Alternate Data Streams on NTFS File Systems https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/02_Search_ADS_on_NTFS%20_(specific%20file).ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/03_Search_ADS_on_NTFS_file_systems.ps1 Read the Contents of a File https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/06_Read_the_contents_file.ps1 Locating Data Patterns within a File https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/05_locating_data_patterns_within_file.ps1 Search for Encoding with Regex https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/07_Search_encoding_with_regex.ps1 Search for Command and Scripting Interpreter: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Tactics_Techniques_Procedures_(TTPs)/04_Searching_for_PIDs.ps1 Threat hunting in different environments with PowerShell: Coming examples are about collecting information in very different environments. Also here a few examples as a kind => as first starting points: Hunt for Threats in Active Directory: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/01_Resetting_Password_Unlocking_Accounts.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/02_Search_stale_accounts.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/03_Users_without_Manager.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/04_Password_Expiration.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/05_Group_Membership_Report.ps1 https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Active_Directory/06_Account_Events.ps1 Some of the scripts are structured in such a way that they must be executed block by block/line by line. So do not execute the whole script at once. Pay attention to the different information that is collected. With some investigations in the Active Directory accounts can be indicated like "guest" or "krbtgt", there must be clear of course how this information is to be estimated. Depending on how and what information is searched. Hunt for Threats in Exchange Online: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Exchange_Online/Exchange_Mailbox_LastLogin.ps1 Find mailboxes with the last login. Hunt for Threats in Azure: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Azure/Collect_vms_subscription.ps1 We search Azure for all virtual machines in a subscription. https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_Azure/02_Graph_Create_Time_Last_Password.ps1 When was the last password change and when were the accounts created? Hunt for Threats in SharePoint: https://github.com/tomwechsler/Threat_Hunting_with_PowerShell/blob/main/Hunting_SharePoint_Online/SharePoint_Online_specific_files.ps1 With this script we search for files with the extension .ps1 in a SharePoint Online page. Summary: Is this the best tactic to hunt for threats? No! There are many different tactics/techniques to search for threats. First of all, there are a huge number of different tools that can be used, for example SIEM/SOAR (Security Information and Event Management/Security Orchestration, Automation and Response). These tools are really great, sometimes cost a lot and often it takes a lot of knowledge to use such tools. But what is the use of such tools if the information generated by these tools cannot be understood properly, not very much. For this reason, I have tried in this article with simple tools to generate information that hopefully can be interpreted. Is finished here at this point. NO, the journey continues. The examples in this article are neither exhaustive nor complete, but they should give you a starting point. I hope you can build on this foundation. I hope that this information is helpful to you and that you have received a good "little" foundation. But I still hope that this information is helpful for you. Thank you for taking the time to read the article. Happy Hunting, Tom Wechsler P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler47KViews0likes0CommentsConnect-SPOService not working in PowerShell 7
Hi all, I'm having some issues getting Connect-SPOService working in PowerShell 7 (7.2.4). It works fine in Windows PowerShell (5.1.22), however it will always generate errors when trying to us it in PS 7 which I've listed below. Firstly if I open Windows PS, I can use it straight away, however if I open PS 7, I have to import the module in order to use it. I guess I can fix this with a profile adjustment, but is there a reason why this would be the case? Secondly even when it's been imported, if I try to connect with the following, I get an error: Connect-SPOService -Url https://***-admin.sharepoint.com Connect-SPOService: No valid OAuth 2.0 authentication session exists Never seen this before in Windows PS and I'm not sure how to resolve it so I tried connecting with this instead. Still got an error but a different one this time: Connect-SPOService -Url https://***-admin.sharepoint.com -Credential ***@***.com Connect-SPOService: The sign-in name or password does not match one in the Microsoft account system. I know these are the right credientials as again they work fine in Windows PS. This lead me to think that something still wasn't being imported correctly into PS 7, so I had a look at the modes, and I noticed that the ExportedCommands don't appear when Get-Module is run in PS 7, but again they do in Windows PS. I'm guessing this could be part of the issue but I'm not sure how to resolve it. From what I can see everything appears fine, but I'm sure I'm missing something here. I've tried setting my ExecutionPolicy to unrestricted in case that was the problem, however it didn't appear to change anything. If anyone has seen this before or could provide any help it would be greatly appreciated. I realise that I could just use Windows PS, but it feels like PS 7 is the way forward and it would be nice to better understand why this is happening. Many thanks in advance.Solved43KViews0likes9CommentsFacing issue in installing the Pnp PowerShell Module for SharePoint 2013/Online
Hi All, I am facing issue in installing the PnP PowerShell module for SharePoint 2013/online. Please let me know if anyone has faced such issue Chendrayan Venkatesan . Error Description: PS C:\WINDOWS\system32> Install-Module SharePointPnPPowerShell2013 PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'SharePointPnPPowerShell2013'. Try Get-PSRepository to see all available registered module repositories. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21 + ... $null = PackageManagement\Install-Package @PSBoundParameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage PS C:\WINDOWS\system32> Install-Module SharePointPnPPowerShellOnline PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'SharePointPnPPowerShellOnline'. Try Get-PSRepository to see all available registered module repositories. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21 + ... $null = PackageManagement\Install-Package @PSBoundParameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage PS C:\WINDOWS\system32> $PSVersionTable.PSVersion Major Minor Build Revision ----- ----- ----- -------- 5 1 17134 407 Thanks, Prabhu36KViews0likes5CommentsGet SharePoint Site URL of an individual Microsoft Team
I found the https://office365itpros.com/2019/03/27/finding-sharepoint-urls-teams/. I want to use the same concept but only return one SP site URL so I can use the URL to create a folder in that Team. $Teams = (Get-Team |Select GroupId, DisplayName) ForEach ($T in $Teams) { $SPOURl = (Get-UnifiedGroup -Identity $T.GroupId | Select -ExpandProperty SharePointSiteURL) Write-Host "URL for the" $T.DisplayName "team is" $SPOURL } It would be easiest to start with getting the Team by displayname then taking the group ID and using that. All the individual versions of -expandproperty SharePointURL have not worked for me yet. Any advice? Get-Team -DisplayName $Team | Select GroupId22KViews0likes9CommentsScript for Teams-Chat backup
Sometimes it is necessary to save the chat history of a Teams-Channel. I wrote a simple script, where you can select the needed Team(s) and outputting the Chat-Content to a html File. If there are any comments, I'm open for suggestions. Here is the Script: #Install-Module -Name SharePointPnPPowerShellOnline $SecurityScope = @("Group.Read.All") Connect-PnPOnline -Scopes $SecurityScope $PnPGraphAccessToken = Get-PnPGraphAccessToken ,$Headers = @{ "Content-Type" = "application/json" Authorization = "Bearer $PnPGraphAccessToken" } $Date = Get-Date -Format "dd.MM.yyyy, HH:mm" $DOCTYPE = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns='http://www.w3.org/1999/xhtml'>" $Style ="<style>table {border-collapse: collapse; width:100%;} table th {text-align:left; background-color: #004C99; color:#fff; padding: 4px 30px 4px 8px;} table td {border: 1px solid #004C99; padding: 4px 8px;} td {background-color: #DDE5FF}</style>" $Head = "<head><title>Backup: Teams-Chat</title></head>" $Body = "<body><div style='width: 100%;'><table><tr><th style='text-align:center'><h1>Backup: Teams-Chat from $Date</h1></th></tr></table>" $Table_body = "<div style='width: 100%;'><table><tr><th>TimeStamp</th><th>User Name</th><th>Message</th></tr>" $Content ="" $Footer = "</body>" $response_teams = Invoke-RestMethod -Uri "https://graph.microsoft.com/beta/groups" -Method Get -Headers $Headers -UseBasicParsing $response_teams.value | Where-Object {$_.groupTypes -eq "Unified"} | Select-Object -Property displayName, ID | Out-GridView -PassThru -Title 'Which Team-Chat do you want to backup?' | ForEach-Object { $Team_ID = $_.ID $Team_displayName = $_.displayName Write-Progress -Activity "Bckup Team Chat Mesasages" -Status "Get Team: $($Team_displayName)" Start-Sleep -Milliseconds 50 $Content += "</br></br><hr><h2>Team: " + $Team_displayName + "</h2>" $response_channels = Invoke-RestMethod -Uri "https://graph.microsoft.com/beta/teams/$Team_ID/channels" -Method Get -Headers $Headers -UseBasicParsing $response_channels.value | Select-Object -Property ID, displayName | ForEach-Object { $Channel_ID = $_.ID $Channel_displayName = $_.displayName Write-Progress -Activity "Bckup Team Chat Mesasages" -Status "Get Channel: $($Channel_displayName)" Start-Sleep -Milliseconds 50 $Content += "<h3>Channel: " + $Channel_displayName + "</h3>" $response_messages = Invoke-RestMethod -Uri "https://graph.microsoft.com/beta/teams/$Team_ID/channels/$Channel_ID/messages" -Method Get -Headers $Headers -UseBasicParsing $response_messages.value | Select-Object -Property ID, createdDateTime, from | ForEach-Object { $Message_ID = $_.ID $Message_TimeStamp = $_.createdDateTime $Message_from = $_.from $response_content = Invoke-RestMethod -Uri "https://graph.microsoft.com/beta/teams/$Team_ID/channels/$Channel_ID/messages/$Message_ID" -Method Get -Headers $Headers -UseBasicParsing Write-Progress -Activity "Bckup Team Chat Mesasages" -Status "Get Team: $($Team_displayName), Gett Message-ID: $($Message_ID), from Channel: $($Channel_displayName)" Start-Sleep -Milliseconds 50 $Content += $Table_body + "<td>" + $Message_TimeStamp + "</td><td style='width: 10%;'>" + $Message_from.user.displayName + "</td><td style='width: 75%;'>" + $response_content.body.content + $response_content.attachments.id + "</td></table></div>" $response_Reply = Invoke-RestMethod -Uri "https://graph.microsoft.com/beta/teams/$Team_ID/channels/$Channel_ID/messages/$Message_ID/replies" -Method Get -Headers $Headers -UseBasicParsing $response_Reply.value | Select-Object -Property ID, createdDateTime, from | ForEach-Object { $Reply_ID = $_.ID $Reply_TimeStamp= $_.createdDateTime $Reply_from = $_.from $response_Reply = Invoke-RestMethod -Uri "https://graph.microsoft.com/beta/teams/$Team_ID/channels/$Channel_ID/messages/$Message_ID/replies/$Reply_ID" -Method Get -Headers $Headers -UseBasicParsing Write-Progress -Activity "Bckup Team Chat Mesasages" -Status "Gett Reply-Message-ID: $($Reply_ID)" Start-Sleep -Milliseconds 50 ForEach-Object { $Content += $Table_body + "<td>" + $Reply_TimeStamp + "</td><td style='width: 10%;'>" + $Reply_from.user.displayName + "</td><td style='width: 75%;'>" + $response_Reply.body.content + $response_Reply.attachments.id + $response_Reply.attachments.name + "</td></table></div>" } } } } } $DOCTYPE + $Style + $Head + $Body + $Content + $Footer | Out-File -FilePath "C:\Backup.html" & "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" "C:\Backup.html"18KViews1like4CommentsConnect to SharePoint Online with MFA using CSOM
I have the CSOM code below for trying to connect to SharePoint Online with MFA enabled: $SiteUrl = "http://our-tenant.sharepoint.com" #Setup Authentication Manager $AuthenticationManager = new-object OfficeDevPnP.Core.AuthenticationManager $Ctx = $AuthenticationManager.GetWebLoginClientContext($SiteUrl) $Ctx.Load($Ctx.Web) $Ctx.ExecuteQuery() I am encountering the following error: Error: Cannot find type [OfficeDevPnP.Core.AuthenticationManager]: verify that the assembly containing this type is loaded I already have PnP SharePoint installed via "Install-Module PnP.PowerShell" so I am not sure what is wrong. For reasons, I cannot use the Connect-PnPOnline cmdlet. How do I connect to SharePoint Online with CSOM if my account has MFA?15KViews0likes3CommentsHow to use PowerShell to remove nonempty folder in OneDrive
PSVersion:7.1.3 OS:Microsoft Windows 10.0.19042 OneDrive Version:21.052.0314.0001 (Office 365 A1) Descriptions Cannot remove nonempty folder in OneDrive directory Step to reproduce 1. Launch PowerShell in OneDrive directory PS C:\Users\MyUserName\OneDrive> 2. Try to use Remove-Item cmdlet to remove a nonempty folder in this directory, for example: the .\test\ folder PS C:\Users\MyUserName\OneDrive> Remove-Item .\test\ Expected result Without the -Recurse parameter, PowerShell should return a confirm message, such as Confirm The item at C:\Users\MyUserName\OneDrive\test\ has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Actual result PowerShell return a error message Remove-Item: Cannot remove item C:\Users\MyUserName\OneDrive\test\: The directory is not empty. : 'C:\Users\MyUserName\OneDrive\test\' Note 1. PowerShell and Administrator:PowerShell get the same result; 2. If I exit OneDrive process and create a new nonempty folder under OneDrive directory, PowerShell can remove it as normal; 3. CMD can remove the folder successfully, which means I can use cmd.exe /C "rd /s test" in PowerShell to remove the folder too. But I want to accomplish this just by PowerShell cmdlet; 4. Get-ChildItem cmdlet shows that the mode of normal folders (not synced by OneDrive) is 'd'(directory), but the mode of synced folders is 'l'(link). However, "dir" command in CMD shows that both of them are <DIR> type. Is this the keypoint?14KViews0likes1CommentExport sharepoint group and users to cvs using poweshell in a particular format
Hi All, I have been able to export Groups and users in this format Groups Users GroupA User A; User A1 GroupB UserB; User B1 Using this code below #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -UseWebLogin #Get All Groups from Site - Exclude system Groups $Groups = Get-PnPGroup | Where-Object {$_.OwnerTitle -ne "System Account"} $GroupData=@() #Get Group Details ForEach($Group in $Groups) { #Get Group data $GroupData += New-Object PSObject -Property ([ordered]@{ "Group Name" = $Group.Title "Users" = $Group.Users.Title -join "; " }) } $GroupData #Export Users data to CSV file $GroupData | Export-Csv -NoTypeInformation $CSVFile But what i'm after is Groups Users GroupA User A GroupA User A1 GroupB UserB GroupB User B1 Is this achievable and if yes how can i do that in powershell? Thanks in advance13KViews0likes2Comments