├── SCSM-Get-SCSMWorkItemRequestOffering ├── Readme.md └── Get-SCSMWorkItemRequestOffering.ps1 ├── _Profiles └── functions │ ├── clx.ps1 │ ├── Launch-ExchangeOnline.ps1 │ ├── Launch-AzurePortal.ps1 │ ├── Launch-Office365Admin.ps1 │ ├── Launch-InternetExplorer.ps1 │ ├── Get-NetAccelerator.ps1 │ ├── Get-UsefulNetMethod.ps1 │ ├── Test-ADCredential.ps1 │ ├── Test-DatePattern.ps1 │ ├── View-Cats.ps1 │ └── Find-Apartment.ps1 ├── AD-GROUP-Monitor_MemberShip └── README.md ├── TOOL-Clean-MacAddress ├── Clean-MacAddress01.png ├── README.md └── Clean-MacAddress.ps1 ├── TOOL-New-DjoinFile ├── media │ └── New-DjoinFile01.png ├── README.md └── New-DjoinFile.ps1 ├── TOOL-Get-ComputerInfo ├── Get-ComputerInfo-001.png ├── Get-ComputerInfo-002.png └── Get-ComputerInfo-003.png ├── TOOL-Read-ExcelFile ├── VIDEOSERVER01-BuildSpecs.xlsx └── Read-ExcelFile-Example_Using_COM.ps1 ├── SCSM-Get-SCSMObjectPrefix └── Get-SCSMObjectPrefix.png ├── TOOL-Disable-RemoteDesktop └── Disable-RemoteDesktop.png ├── TOOL-Enable-RemoteDesktop └── images │ └── Enable-RemoteDesktop.png ├── O365-Get-O365CalendarEvent ├── images │ └── Get-O365CalendarEvent.png └── README.md ├── AD-GPO-Get-ADGPOReplication ├── images │ ├── Get-ADGPOReplication01.png │ └── Get-ADGPOReplication_OutGridView.png └── README.MD ├── SCSM-Get-SCSMWorkItemParent ├── images │ ├── Get-SCSMWorkItemParent01.jpg │ ├── Get-SCSMWorkItemParent02.jpg │ └── Get-SCSMWorkItemParent03.jpg └── README.md ├── AZURE-AppService-Update_RestrictionIP └── source.csv ├── AD-SITE-Add-ADSubnet(ADSI) └── AD-Subnets_template.csv ├── README.md ├── TOOL-Get-ScriptDirectory └── Get-ScriptDirectory.ps1 ├── .gitattributes ├── TOOL-Get-StringCharCount └── Get-StringCharCount.ps1 ├── SCSM-Get-SCSMWorkItemChildItem ├── Get-SCSMWorkItemChildItemRA.ps1 └── Get-SCSMWorkItemChildItem.ps1 ├── TOOL-Get-BatteryStatus └── Get-BatteryStatus.ps1 ├── TOOL-Lock-Computer └── Lock-Computer.ps1 ├── .vscode └── settings.json ├── AZURE-Policy-Invoke-ComplianceEvaluation ├── readme.md └── Invoke-ComplianceEvaluation.ps1 ├── TOOL-Set-PowerShellWindowTitle └── Set-PowerShellWindowTitle.ps1 ├── TOOL-Test-IsLocalAdministrator └── Test-IsLocalAdministrator.ps1 ├── TOOL-Get-HashTableEmptyValue └── Get-HashTableEmptyValue.ps1 ├── TOOL-Get-ImageInformation ├── readme.md └── Get-ImageInformation.ps1 ├── TOOL-Remove-PSObjectProperty └── Remove-PSObjectProperty.ps1 ├── TOOL-Get-HashTableNotEmptyValue └── Get-HashTableNotEmptyOrNullValue.ps1 ├── TOOL-Get-NetFrameworkTypeAccelerator └── Get-NetFrameworkTypeAccelerator.ps1 ├── TOOL-Repair-ScriptFormat └── Repair-ScriptFormat.ps1 ├── TOOL-ConvertTo-Base64 └── ConvertTo-Base64.ps1 ├── TOOL-Remove-PSObjectEmptyOrNullProperty └── Remove-PSObjectEmptyOrNullProperty.ps1 ├── TOOL-Resolve-ShortURL └── Resolve-ShortURL.ps1 ├── LICENSE.md ├── TOOL-Remove-HashTableEmptyValue └── Remove-HashTableEmptyValue.ps1 ├── SCSM-Get-SCSMWorkItemRelatedCI └── Get-SCSMWorkItemRelatedCI.ps1 ├── SCSM-Get-SCSMWorkItemAffectedCI └── Get-SCSMWorkItemAffectedCI.ps1 ├── AZURE-Get-AzToken └── Get-AzToken.ps1 ├── AD-TOOL-Test-ADCredential └── Test-ADCredential.ps1 ├── TOOL-Get-StringLastDigit └── Get-StringLastDigit.ps1 ├── TOOL-ConvertFrom-Base64 └── ConvertFrom-Base64.ps1 ├── TOOL-Get-HelpMessage └── Get-HelpMessage.ps1 ├── TOOL-Test-RemoteDesktopIsEnabled └── Test-RemoteDesktopIsEnabled.ps1 ├── TOOL-Get-NetStat └── Get-NetStat.ps1 ├── _Template └── Get-Something.ps1 ├── tests ├── Add-LocalGroupMember.ps1 ├── AD-TokenGroups_Test.ps1 └── help.tests.ps1 ├── TOOL-Get-ISEShortcut └── Get-ISEShortcut.ps1 ├── TOOL-Set-RDPEnable └── Set-RDPEnable.ps1 ├── TOOL-Get-ProcessForeignAddress └── Get-ProcessForeignAddress.ps1 ├── TOOL-Set-RDPDisable └── Set-RDPDisable.ps1 ├── EXCHANGE-Connect-ExchangeOnPremises └── Connect-ExchangeOnPremises.ps1 ├── TOOL-Get-LocalGroup └── Get-LocalGroup.ps1 ├── TOOL-Get-LocalAdministrator └── Get-LocalAdministrator.ps1 ├── TOOL-Get-PSObjectEmptyOrNullProperty └── Get-PSObjectEmptyOrNullProperty.ps1 ├── TOOL-Set-RemoteDesktop └── Set-RemoteDesktop.ps1 ├── TOOL-New-RandomPassword └── New-RandomPassword.ps1 ├── TOOL-Get-LocalUser └── Get-LocalUser.ps1 ├── SCCM-New-SCCMTSAppVariable └── New-SCCMTSAppVariable.ps1 ├── SCSM-Set-SCSMMAStatus └── SCSM-Set-SCSMMAStatus.ps1 ├── TOOL-Remove-StringDiacritic └── Remove-StringDiacritic.ps1 ├── EXCHANGE-Connect-ExchangeOnline └── Connect-ExchangeOnline.ps1 ├── TOOL-Remove-StringLatinCharacter └── Remove-StringLatinCharacter.ps1 ├── AZURE-Get-PolicyComplianceData └── Get-PolicyComplianceData.ps1 ├── SCSM-Get-SCSMUserManager └── Get-SCSMUserManager.ps1 ├── SCSM-Get-SCSMIRComment └── Get-SCSMIRComment.ps1 ├── SAPIEN-PowerShellStudio-themes └── EditorPresets │ ├── LazyWinAdmin-Dark Theme.preset │ ├── LazyWinAdmin-Dark Theme-2.preset │ └── LazyWinAdmin-Dark Theme-2-Font_AnonymousPro.preset ├── AZURE-APIM-Publish_API_Definitions_Swagger └── AZURE-APIM-Publish_API_Definitions_Swagger.ps1 ├── SCCM-Get-SCCMClientCacheInformation └── Get-SCCMClientCacheInformation.ps1 ├── TOOL-Sync-Wsus-Client └── Sync-WsusClient.ps1 ├── TOOL-Expand-GzipFile └── Expand-GzipFile.ps1 ├── SCSM-Get-SCSMReviewActivityReviewer └── Get-SCSMReviewActivityReviewer.ps1 ├── O365-GROUP-Get-DistributionGroupRecursive └── O365-GROUP-Get-DistributionGroupRecursive.ps1 ├── AD-FSMO-Get-ADFSMORole └── AD-FSMO-Get-ADFSMORole.ps1 ├── TOOL-Get-LocalGroupMember └── Get-LocalGroupMember.ps1 ├── TOOL-Get-LogFast └── Get-LogFast.ps1 ├── TOOL-ConvertTo-StringList └── ConvertTo-StringList.ps1 ├── TOOL-Remove-StringSpecialCharacter └── Remove-StringSpecialCharacter.ps1 ├── SCCM-Add-SCCMUserDeviceAffinity └── Add-SCCMUserDeviceAffinity.ps1 ├── SCSM-Get-SCSMWorkItemAssignedUser └── Get-SCSMWorkItemAssignedUser.ps1 ├── SCSM-Get-SCSMWorkItemCreatedByUser └── Get-SCSMWorkItemCreatedByUser.ps1 ├── TOOL-Get-NetFramework └── Get-NetFramework.ps1 ├── SCSM-Get-SCSMWorkItemUserInput └── Get-SCSMWorkItemUserInput.ps1 ├── SCCM-Set-SCCMClientCacheLocation └── Set-SCCMClientCacheLocation.ps1 ├── SCSM-Get-SCSMWorkItemAffectedUser └── Get-SCSMWorkItemAffectedUser.ps1 ├── SCCM-Add-SCCMGroupDeviceAffinity └── Add-SCCMGroupDeviceAffinity.ps1 ├── SCCM-Set-SCCMClientCacheSize └── Set-SCCMClientCacheSize.ps1 ├── SCSM-Add-SCSMReviewActivityReviewer └── Add-SCSMReviewActivityReviewer.ps1 ├── SCSM-Add-SCSMServiceRequestComment └── Add-SCSMServiceRequestComment.ps1 ├── AD-SITE-Get_Site_and_Subnets └── Get-ADSiteAndSubnet.ps1 ├── TOOL-New-ScriptMessage └── New-ScriptMessage.ps1 ├── TOOL-Get-ScriptAlias └── Get-ScriptAlias.ps1 ├── AD-SITE-Get-ADSIComputerSite └── Get-ADSIComputerSite.ps1 ├── SCSM-Get-SCSMServiceRequestComment └── Get-SCSMServiceRequestComment.ps1 ├── AD-GROUP-Get-ParentGroup └── AD-GROUP-Get-ParentGroup.ps1 ├── SCCM-Remove-SCCMUserDeviceAffinity └── Remove-SCCMUserDeviceAffinity.ps1 ├── TOOL-Start-KeyLogger └── Start-KeyLogger.ps1 ├── TOOL-New-Password └── New-Password.ps1 ├── SCSM-Get-SCSMIncidentRequestComment └── Get-SCSMIncidentRequestComment.ps1 ├── .gitignore ├── TOOL-Out-Excel └── Out-Excel.ps1 ├── AZURE-Get-AzureIPRangesAndServiceTags └── Get-AzureIPRangesAndServiceTags.ps1 └── SCSM-Add-SCSMSRComment └── Add-SCSMSRComment.ps1 /SCSM-Get-SCSMWorkItemRequestOffering/Readme.md: -------------------------------------------------------------------------------- 1 | Test 2 | -------------------------------------------------------------------------------- /_Profiles/functions/clx.ps1: -------------------------------------------------------------------------------- 1 | Function clx { 2 | [System.Console]::SetWindowPosition(0, [System.Console]::CursorTop) 3 | } -------------------------------------------------------------------------------- /AD-GROUP-Monitor_MemberShip/README.md: -------------------------------------------------------------------------------- 1 | # AD-Monitor Group membership 2 | 3 | This script has been moved to its own repository -------------------------------------------------------------------------------- /_Profiles/functions/Launch-ExchangeOnline.ps1: -------------------------------------------------------------------------------- 1 | function Launch-ExchangeOnline { Invoke-Item "https://outlook.office365.com/ecp/" } -------------------------------------------------------------------------------- /_Profiles/functions/Launch-AzurePortal.ps1: -------------------------------------------------------------------------------- 1 | function Launch-AzurePortal { Invoke-Item "https://portal.azure.com/" -Credential (Get-Credential) } -------------------------------------------------------------------------------- /TOOL-Clean-MacAddress/Clean-MacAddress01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/TOOL-Clean-MacAddress/Clean-MacAddress01.png -------------------------------------------------------------------------------- /TOOL-New-DjoinFile/media/New-DjoinFile01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/TOOL-New-DjoinFile/media/New-DjoinFile01.png -------------------------------------------------------------------------------- /_Profiles/functions/Launch-Office365Admin.ps1: -------------------------------------------------------------------------------- 1 | function Launch-Office365Admin { Invoke-Item "https://portal.office.com" -Credential (Get-Credential) } -------------------------------------------------------------------------------- /TOOL-Get-ComputerInfo/Get-ComputerInfo-001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/TOOL-Get-ComputerInfo/Get-ComputerInfo-001.png -------------------------------------------------------------------------------- /TOOL-Get-ComputerInfo/Get-ComputerInfo-002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/TOOL-Get-ComputerInfo/Get-ComputerInfo-002.png -------------------------------------------------------------------------------- /TOOL-Get-ComputerInfo/Get-ComputerInfo-003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/TOOL-Get-ComputerInfo/Get-ComputerInfo-003.png -------------------------------------------------------------------------------- /TOOL-Read-ExcelFile/VIDEOSERVER01-BuildSpecs.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/TOOL-Read-ExcelFile/VIDEOSERVER01-BuildSpecs.xlsx -------------------------------------------------------------------------------- /_Profiles/functions/Launch-InternetExplorer.ps1: -------------------------------------------------------------------------------- 1 | function Launch-InternetExplorer { & 'C:\Program Files (x86)\Internet Explorer\iexplore.exe' "about:blank" } -------------------------------------------------------------------------------- /SCSM-Get-SCSMObjectPrefix/Get-SCSMObjectPrefix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/SCSM-Get-SCSMObjectPrefix/Get-SCSMObjectPrefix.png -------------------------------------------------------------------------------- /TOOL-Disable-RemoteDesktop/Disable-RemoteDesktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/TOOL-Disable-RemoteDesktop/Disable-RemoteDesktop.png -------------------------------------------------------------------------------- /_Profiles/functions/Get-NetAccelerator.ps1: -------------------------------------------------------------------------------- 1 | function Get-Accelerators { 2 | [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::get 3 | } -------------------------------------------------------------------------------- /TOOL-Enable-RemoteDesktop/images/Enable-RemoteDesktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/TOOL-Enable-RemoteDesktop/images/Enable-RemoteDesktop.png -------------------------------------------------------------------------------- /O365-Get-O365CalendarEvent/images/Get-O365CalendarEvent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/O365-Get-O365CalendarEvent/images/Get-O365CalendarEvent.png -------------------------------------------------------------------------------- /AD-GPO-Get-ADGPOReplication/images/Get-ADGPOReplication01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/AD-GPO-Get-ADGPOReplication/images/Get-ADGPOReplication01.png -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent01.jpg -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent02.jpg -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent03.jpg -------------------------------------------------------------------------------- /AD-GPO-Get-ADGPOReplication/images/Get-ADGPOReplication_OutGridView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazywinadmin/PowerShell/HEAD/AD-GPO-Get-ADGPOReplication/images/Get-ADGPOReplication_OutGridView.png -------------------------------------------------------------------------------- /AZURE-AppService-Update_RestrictionIP/source.csv: -------------------------------------------------------------------------------- 1 | "ipAddress","action","priority","name","description","tag" 2 | "120.3.2.0/20","Allow","100","test ip1","test ip1","Default" 3 | "120.3.3.0/20","Allow","100","test ip4","test ip4","Default" -------------------------------------------------------------------------------- /AD-SITE-Add-ADSubnet(ADSI)/AD-Subnets_template.csv: -------------------------------------------------------------------------------- 1 | Name,Location,Site,Description 2 | 192.168.1.0/24,Paris,FX2,PROD Servers VLAN 15 3 | 192.168.2.0/24,London,FX3,PROD Servers VLAN 16 4 | 192.168.3.0/24,Montreal,MTL1,DEV Servers VLAN 101 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PowerShell 2 | 3 | This repository is used for all my public scripts. 4 | Let me know if you have any issues using them, always space for improvement 5 | Feel free to fork 6 | 7 | * [Blog](https://lazywinadmin.com) 8 | * [Twitter @LazyWinAdmin](https://twitter.com/LazyWinAdmin) 9 | -------------------------------------------------------------------------------- /_Profiles/functions/Get-UsefulNetMethod.ps1: -------------------------------------------------------------------------------- 1 | Write-Host "[Math]::Round(7.9)" 2 | 3 | Write-Host "[Convert]::ToString(576255753217, 8)" 4 | 5 | Write-Host "[Guid]::NewGuid()" 6 | 7 | Write-Host "[Net.Dns]::GetHostByName('schulung12')" 8 | 9 | Write-Host "[IO.Path]::GetExtension('c:\test.txt')" 10 | 11 | Write-Host "[IO.Path]::ChangeExtension('c:\test.txt', 'bak')" -------------------------------------------------------------------------------- /TOOL-Get-ScriptDirectory/Get-ScriptDirectory.ps1: -------------------------------------------------------------------------------- 1 | function Get-ScriptDirectory { 2 | <# 3 | .SYNOPSIS 4 | This function retrieve the current folder path 5 | .DESCRIPTION 6 | This function retrieve the current folder path 7 | .EXAMPLE 8 | Get-ScriptDirectory 9 | .LINK 10 | https://github.com/lazywinadmin/PowerShell 11 | #> 12 | if ($null -eq $hostinvocation) { 13 | Split-Path -Path $hostinvocation.MyCommand.path 14 | } 15 | else { 16 | Split-Path -Path $script:MyInvocation.MyCommand.Path 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /_Profiles/functions/Test-ADCredential.ps1: -------------------------------------------------------------------------------- 1 | Function Test-ADCredential { 2 | Param($username, $password, $domain) 3 | Add-Type -AssemblyName System.DirectoryServices.AccountManagement 4 | $ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain 5 | $pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext($ct, $domain) 6 | New-Object -TypeName PSObject -Property @{ 7 | UserName = $username; 8 | IsValid = $pc.ValidateCredentials($username, $password).ToString() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /O365-Get-O365CalendarEvent/README.md: -------------------------------------------------------------------------------- 1 | # Get-O365CalendarEvent 2 | 3 | ## Usage 4 | ``` powershell 5 | Get-O365CalendarEvent ` 6 | -EmailAddress info@lazywinadmin.com ` 7 | -Credential (Get-Credential) ` 8 | -StartDateTime ((Get-Date).adddays(-5)) ` 9 | -EndDateTime (Get-Date) ` 10 | -PageResult 2|Select-Object -Property Subject, StartTimeZone, Start, End 11 | ``` 12 | 13 | ![Alt text](https://raw.githubusercontent.com/lazywinadmin/PowerShell/master/O365-Get-O365CalendarEvent/images/Get-O365CalendarEvent.png?raw=true "Get-O365CalendarEvent Example") 14 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /TOOL-Get-StringCharCount/Get-StringCharCount.ps1: -------------------------------------------------------------------------------- 1 | Function Get-StringCharCount { 2 | <# 3 | .SYNOPSIS 4 | This function will count the number of characters in a string 5 | .DESCRIPTION 6 | This function will count the number of characters in a string 7 | .EXAMPLE 8 | PS C:\> Get-StringCharCount -String "Hello World" 9 | 10 | 11 11 | .NOTES 12 | Francois-Xavier Cat 13 | @lazywinadmin 14 | lazywinadmin.com 15 | .LINK 16 | https://github.com/lazywinadmin/PowerShell 17 | #> 18 | PARAM ([String]$String) 19 | ($String -as [Char[]]).count 20 | } -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemChildItem/Get-SCSMWorkItemChildItemRA.ps1: -------------------------------------------------------------------------------- 1 | # Get the review activity 2 | $childWI_ReviewerActivityHasReviewers_Class_id = '6e05d202-38a4-812e-34b8-b11642001a80' 3 | $childWI_ReviewerActivityHasReviewers_Class_obj = Get-SCSMRelationshipClass -id $childWI_ReviewerActivityHasReviewers_Class_id 4 | 5 | 6 | # Get the reviewer 7 | $childWI_ReviewerisUser_Class_id = '90da7d7c-948b-e16e-f39a-f6e3d1ffc921' 8 | $childWI_ReviewerisUser_Class_obj = Get-SCSMRelationshipClass -id $childWI_ReviewerisUser_Class_id 9 | 10 | $childWI_reviewers = Get-SCSMRelatedObject -SMObject $childWI_obj -Relationship $childWI_ReviewerActivityHasReviewers_Class_obj -------------------------------------------------------------------------------- /TOOL-Get-BatteryStatus/Get-BatteryStatus.ps1: -------------------------------------------------------------------------------- 1 | function Get-BatteryStatus { 2 | <# 3 | .SYNOPSIS 4 | Retrieve battery information 5 | 6 | .DESCRIPTION 7 | Retrieve battery information 8 | 9 | .EXAMPLE 10 | Get-BatteryStatus 11 | 12 | .NOTES 13 | http://www.powershellmagazine.com/2012/10/18/pstip-get-system-power-information/ 14 | 15 | .LINK 16 | https://github.com/lazywinadmin/PowerShell 17 | #> 18 | PARAM() 19 | try { 20 | Add-Type -Assembly System.Windows.Forms 21 | [System.Windows.Forms.SystemInformation]::PowerStatus 22 | } 23 | catch { 24 | $PSCmdlet.ThrowTerminatingError($_) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TOOL-Lock-Computer/Lock-Computer.ps1: -------------------------------------------------------------------------------- 1 | Function Lock-Computer { 2 | <# 3 | .DESCRIPTION 4 | Function to Lock your computer 5 | .SYNOPSIS 6 | Function to Lock your computer. 7 | This is using the win32 user32.dll library. 8 | .EXAMPLE 9 | Lock-Computer 10 | 11 | This will lock the current computer 12 | .LINK 13 | https://github.com/lazywinadmin/PowerShell 14 | #> 15 | 16 | $signature = @" 17 | [DllImport("user32.dll", SetLastError = true)] 18 | public static extern bool LockWorkStation(); 19 | "@ 20 | 21 | $LockComputer = Add-Type -memberDefinition $signature -name "Win32LockWorkStation" -namespace Win32Functions -passthru 22 | $LockComputer::LockWorkStation() | Out-Null 23 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // The number of spaces a tab is equal to. This setting is overriden 3 | // based on the file contents when `editor.detectIndentation` is true. 4 | "editor.tabSize": 4, 5 | // Insert spaces when pressing Tab. This setting is overriden 6 | // based on the file contents when `editor.detectIndentation` is true. 7 | "editor.insertSpaces": true, 8 | // When opening a file, `editor.tabSize` and `editor.insertSpaces` 9 | // will be detected based on the file contents. 10 | "editor.detectIndentation": false, 11 | 12 | "editor.rulers": [ 13 | 80 14 | ], 15 | 16 | "editor.renderWhitespace": "all", 17 | 18 | "files.trimTrailingWhitespace": true 19 | } -------------------------------------------------------------------------------- /AZURE-Policy-Invoke-ComplianceEvaluation/readme.md: -------------------------------------------------------------------------------- 1 | ``` 2 | # The code assume you are already connected to azure 3 | 4 | # Load the function 5 | . ./invoke-complianceevaluation.ps1 6 | 7 | # Trigger Policy Compliance evaluation against current subscription 8 | Invoke-ComplianceEvaluation 9 | 10 | # Trigger Policy Compliance evaluation against specified subscription 11 | Invoke-ComplianceEvaluation -subscriptionid 12 | 13 | # Trigger Policy Compliance evaluation against ResourceGroup specified (in current subscription) 14 | Invoke-ComplianceEvaluation -ResourceGroupName MyRg 15 | 16 | # Trigger Policy Compliance evaluation against ResourceGroup specified (in specified subscription) 17 | Invoke-ComplianceEvaluation -ResourceGroupName MyRg -subscriptionid 18 | 19 | ``` 20 | -------------------------------------------------------------------------------- /TOOL-Set-PowerShellWindowTitle/Set-PowerShellWindowTitle.ps1: -------------------------------------------------------------------------------- 1 | function Set-PowerShellWindowTitle { 2 | <# 3 | .SYNOPSIS 4 | Function to set the title of the PowerShell Window 5 | 6 | .DESCRIPTION 7 | Function to set the title of the PowerShell Window 8 | 9 | .PARAMETER Title 10 | Specifies the Title of the PowerShell Window 11 | 12 | .EXAMPLE 13 | PS C:\> Set-PowerShellWindowTitle -Title LazyWinAdmin.com 14 | 15 | .NOTES 16 | Francois-Xavier Cat 17 | lazywinadmin.com 18 | @lazywinadmin 19 | #> 20 | [CmdletBinding()] 21 | PARAM($Title) 22 | try { 23 | $Host.UI.RawUI.WindowTitle = $Title 24 | } 25 | catch { 26 | $PSCmdlet.ThrowTerminatingError($_) 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /_Profiles/functions/Test-DatePattern.ps1: -------------------------------------------------------------------------------- 1 | function Test-DatePattern { 2 | #http://jdhitsolutions.com/blog/2014/10/powershell-dates-times-and-formats/ 3 | $patterns = "d", "D", "g", "G", "f", "F", "m", "o", "r", "s", "t", "T", "u", "U", "Y", "dd", "MM", "yyyy", "yy", "hh", "mm", "ss", "yyyyMMdd", "yyyyMMddhhmm", "yyyyMMddhhmmss" 4 | 5 | Write-Host "It is now $(Get-Date)" -ForegroundColor Green 6 | 7 | foreach ($pattern in $patterns) { 8 | 9 | #create an Object 10 | [pscustomobject]@{ 11 | Pattern = $pattern 12 | Syntax = "Get-Date -format '$pattern'" 13 | Value = (Get-Date -Format $pattern) 14 | } 15 | 16 | } #foreach 17 | 18 | Write-Host "Most patterns are case sensitive" -ForegroundColor Green 19 | } 20 | -------------------------------------------------------------------------------- /TOOL-Test-IsLocalAdministrator/Test-IsLocalAdministrator.ps1: -------------------------------------------------------------------------------- 1 | function Test-IsLocalAdministrator { 2 | <# 3 | .SYNOPSIS 4 | Function to verify if the current user is a local Administrator on the current system 5 | .DESCRIPTION 6 | Function to verify if the current user is a local Administrator on the current system 7 | .EXAMPLE 8 | Test-IsLocalAdministrator 9 | 10 | True 11 | .NOTES 12 | Francois-Xavier Cat 13 | @lazywinadmin 14 | lazywinadmin.com 15 | github.com/lazywinadmin 16 | #> 17 | [CmdletBinding()] 18 | PARAM() 19 | try { 20 | ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") 21 | } 22 | catch { 23 | $PSCmdlet.ThrowTerminatingError($_) 24 | } 25 | } -------------------------------------------------------------------------------- /_Profiles/functions/View-Cats.ps1: -------------------------------------------------------------------------------- 1 | function View-Cats { 2 | <# 3 | .SYNOPSIS 4 | This will open Internet explorer and show a different cat every 5 seconds 5 | .DESCRIPTION 6 | .NOTES 7 | #http://www.reddit.com/r/PowerShell/comments/2htfog/viewcats/ 8 | #> 9 | Param( 10 | [int]$refreshtime = 5 11 | ) 12 | $IE = New-Object -ComObject internetexplorer.application 13 | $IE.visible = $true 14 | $IE.FullScreen = $true 15 | $shell = New-Object -ComObject wscript.shell 16 | $shell.AppActivate("Internet Explorer") 17 | 18 | while ($true) { 19 | $request = Invoke-WebRequest -Uri "http://thecatapi.com/api/images/get" -Method get 20 | $IE.Navigate($request.BaseResponse.ResponseUri.AbsoluteUri) 21 | Start-Sleep -Seconds $refreshtime 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /TOOL-Get-HashTableEmptyValue/Get-HashTableEmptyValue.ps1: -------------------------------------------------------------------------------- 1 | Function Get-HashTableEmptyValue { 2 | <# 3 | .SYNOPSIS 4 | This function will get the empty or Null entry of a hashtable object 5 | .DESCRIPTION 6 | This function will get the empty or Null entry of a hashtable object 7 | .PARAMETER Hashtable 8 | Specifies the hashtable that will be showed 9 | .EXAMPLE 10 | Get-HashTableEmptyValue -HashTable $SplattingVariable 11 | .NOTES 12 | Francois-Xavier Cat 13 | @lazywinadmin 14 | lazywinadmin.com 15 | .LINK 16 | https://github.com/lazywinadmin/PowerShell 17 | #> 18 | PARAM([System.Collections.Hashtable]$HashTable) 19 | 20 | $HashTable.GetEnumerator().name | 21 | ForEach-Object -Process { 22 | if ($HashTable[$_] -eq "" -or $null -eq $HashTable[$_]) { 23 | Write-Output $_ 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /TOOL-Get-ImageInformation/readme.md: -------------------------------------------------------------------------------- 1 | # Get-ImageInformation 2 | 3 | ## Using the function 4 | ``` powershell 5 | Get-ImageInformation -FilePath c:\test\image.png 6 | ``` 7 | 8 | ## Output example 9 | 10 | ``` powershell 11 | Tag : 12 | PhysicalDimension : {Width=301, Height=308} 13 | Size : {Width=301, Height=308} 14 | Width : 301 15 | Height : 308 16 | HorizontalResolution : 96 17 | VerticalResolution : 96 18 | Flags : 77840 19 | RawFormat : [ImageFormat: b96b3cae-0728-11d3-9d7b-0000f81ef32e] 20 | PixelFormat : Format24bppRgb 21 | Palette : System.Drawing.Imaging.ColorPalette 22 | FrameDimensionsList : {7462dc86-6180-4c7e-8e3f-ee7333a7a483} 23 | PropertyIdList : {305, 36864, 40962, 40963...} 24 | PropertyItems : {305, 36864, 40962, 40963...} 25 | 26 | ``` -------------------------------------------------------------------------------- /TOOL-Remove-PSObjectProperty/Remove-PSObjectProperty.ps1: -------------------------------------------------------------------------------- 1 | function Remove-PSObjectProperty { 2 | <# 3 | .SYNOPSIS 4 | Function to Remove a specifid property from a PowerShell object 5 | 6 | .DESCRIPTION 7 | Function to Remove a specifid property from a PowerShell object 8 | 9 | .PARAMETER PSObject 10 | Specifies the PowerShell Object 11 | 12 | .PARAMETER Property 13 | Specifies the property to remove 14 | 15 | .EXAMPLE 16 | PS C:\> Remove-PSObjectProperty -PSObject $UserInfo -Property Info 17 | 18 | .NOTES 19 | Francois-Xavier Cat 20 | lazywinadmin.com 21 | @lazywinadmin 22 | .LINK 23 | https://github.com/lazywinadmin/PowerShell 24 | #> 25 | PARAM ( 26 | $PSObject, 27 | 28 | [String[]]$Property) 29 | PROCESS { 30 | Foreach ($item in $Property) { 31 | $PSObject.psobject.Properties.Remove("$item") 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /TOOL-New-DjoinFile/README.md: -------------------------------------------------------------------------------- 1 | [NewDjoinFile01]: https://github.com/lazywinadmin/PowerShell/blob/master/TOOL-New-DjoinFile/media/New-DjoinFile01.png 2 | New-DjoinFile 3 | =================== 4 | ## Related Article(s) 5 | [Blog article on lazywinadmin.com](http://www.lazywinadmin.com/2016/07/offline-domain-join-recreating-blob.html) 6 | 7 | ## Description 8 | 9 | The New-DjoinFile function create a Blob file from the String Generated by Djoin. 10 | This blob file can then be passed to djoin to join the machine to the Active Directory domain. 11 | 12 | ## Usage 13 | 14 | ```PowerShell 15 | # Load the function (Dot Sourcing) 16 | . C:\MyScripts\New-DjoinFile.ps1 17 | 18 | # Blob generated 19 | $Blob = "" 20 | 21 | # Recreate djoin file 22 | New-DjoinFile -Blob $blob -DestinationFile $home\desktop\blob.txt -Verbose 23 | ``` 24 | 25 | ![alt text][NewDjoinFile01] 26 | -------------------------------------------------------------------------------- /TOOL-Get-HashTableNotEmptyValue/Get-HashTableNotEmptyOrNullValue.ps1: -------------------------------------------------------------------------------- 1 | Function Get-HashTableNotEmptyOrNullValue { 2 | <# 3 | .SYNOPSIS 4 | This function will get the values that are not empty or Null in a hashtable object 5 | .DESCRIPTION 6 | This function will get the values that are not empty or Null in a hashtable object 7 | .PARAMETER Hashtable 8 | Specifies the hashtable that will be showed 9 | .EXAMPLE 10 | Get-HashTableNotEmptyOrNullValue -HashTable $SplattingVariable 11 | .NOTES 12 | Francois-Xavier Cat 13 | @lazywinadmin 14 | lazywinadmin.com 15 | .LINK 16 | https://github.com/lazywinadmin/PowerShell 17 | #> 18 | PARAM([System.Collections.Hashtable]$HashTable) 19 | 20 | $HashTable.GetEnumerator().name | 21 | ForEach-Object -Process { 22 | if ($HashTable[$_] -ne "") { 23 | Write-Output $_ 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TOOL-Get-ImageInformation/Get-ImageInformation.ps1: -------------------------------------------------------------------------------- 1 | function Get-ImageInformation { 2 | <# 3 | .SYNOPSIS 4 | function to retrieve Image file information 5 | 6 | .DESCRIPTION 7 | function to retrieve Image file information 8 | 9 | .PARAMETER FilePath 10 | Specify one or multiple image file path(s). 11 | 12 | .EXAMPLE 13 | PS C:\> Get-ImageInformation -FilePath c:\temp\image.png 14 | 15 | .NOTES 16 | Francois-Xavier Cat 17 | lazywinadmin.com 18 | @lazywinadmin 19 | github.com/lazywinadmin 20 | .LINK 21 | https://github.com/lazywinadmin/PowerShell 22 | #> 23 | PARAM ( 24 | [System.String[]]$FilePath 25 | ) 26 | Foreach ($Image in $FilePath) { 27 | # Load Assembly 28 | Add-Type -AssemblyName System.Drawing 29 | 30 | # Retrieve information 31 | New-Object -TypeName System.Drawing.Bitmap -ArgumentList $Image 32 | } 33 | } -------------------------------------------------------------------------------- /TOOL-Get-NetFrameworkTypeAccelerator/Get-NetFrameworkTypeAccelerator.ps1: -------------------------------------------------------------------------------- 1 | function Get-NetFrameworkTypeAccelerator { 2 | <# 3 | .SYNOPSIS 4 | Function to retrieve the list of Type Accelerator available 5 | .DESCRIPTION 6 | Function to retrieve the list of Type Accelerator available 7 | 8 | .EXAMPLE 9 | Get-NetFrameworkTypeAccelerator 10 | 11 | Return the list of Type Accelerator available on your system 12 | .EXAMPLE 13 | Get-Accelerator 14 | 15 | Return the list of Type Accelerator available on your system 16 | This is a function alias created by [Alias()] 17 | .NOTES 18 | Francois-Xavier Cat 19 | lazywinadmin.com 20 | @lazywinadmin 21 | github.com/lazywinadmin 22 | .LINK 23 | https://github.com/lazywinadmin/PowerShell 24 | #> 25 | [Alias('Get-Acceletrator')] 26 | PARAM () 27 | [System.Management.Automation.PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::get 28 | } -------------------------------------------------------------------------------- /TOOL-Repair-ScriptFormat/Repair-ScriptFormat.ps1: -------------------------------------------------------------------------------- 1 | function Repair-ScriptFormat { 2 | [CmdletBinding()] 3 | param ( 4 | [Parameter(ValueFromPipeline)] 5 | [ValidateScript( { Test-Path -Path $_ })] 6 | $Path, 7 | [System.String]$Settings = 'CodeFormatting' 8 | ) 9 | 10 | begin { 11 | #Validate PSScriptAnalyzer is present 12 | #minimum vers 13 | } 14 | 15 | process { 16 | try{ 17 | # Retrieve content 18 | $scriptContent = Get-Content -Path $Path -Raw 19 | 20 | # Apply Formatting 21 | $NewContent = Invoke-Formatter -ScriptDefinition $scriptContent -Settings $Settings 22 | 23 | # Replace whitespace lines 24 | #$NewContent = $NewContent -replace '\' 25 | 26 | $NewContent | Out-File -FilePath $Path -Force -NoNewline 27 | }catch{ 28 | $PSCmdlet.ThrowTerminatingError($_) 29 | } 30 | } 31 | end { 32 | } 33 | } -------------------------------------------------------------------------------- /TOOL-ConvertTo-Base64/ConvertTo-Base64.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-Base64 { 2 | <# 3 | .SYNOPSIS 4 | Function to convert an image to Base64 5 | 6 | .DESCRIPTION 7 | Function to convert an image to Base64 8 | 9 | .PARAMETER Path 10 | Specifies the path of the file 11 | 12 | .EXAMPLE 13 | ConvertTo-Base64 -Path "C:\images\PowerShellLogo.png" 14 | 15 | .NOTES 16 | Francois-Xavier Cat 17 | @lazywinadmin 18 | lazywinadmin.com 19 | github.com/lazywinadmin 20 | .LINK 21 | https://github.com/lazywinadmin/PowerShell 22 | #> 23 | 24 | [CmdletBinding()] 25 | param 26 | ( 27 | [Parameter(Mandatory = $true, 28 | ValueFromPipeline = $true)] 29 | [ValidateScript( { Test-Path -Path $_ })] 30 | [String]$Path 31 | ) 32 | Write-Verbose -Message "[ConvertTo-Base64] Converting image to Base64 $Path" 33 | [System.convert]::ToBase64String((Get-Content -Path $path -Encoding Byte)) 34 | } 35 | -------------------------------------------------------------------------------- /TOOL-Remove-PSObjectEmptyOrNullProperty/Remove-PSObjectEmptyOrNullProperty.ps1: -------------------------------------------------------------------------------- 1 | function Remove-PSObjectEmptyOrNullProperty { 2 | <# 3 | .SYNOPSIS 4 | Function to Remove all the empty or null properties with empty value in a PowerShell Object 5 | 6 | .DESCRIPTION 7 | Function to Remove all the empty or null properties with empty value in a PowerShell Object 8 | 9 | .PARAMETER PSObject 10 | Specifies the PowerShell Object 11 | 12 | .EXAMPLE 13 | PS C:\> Remove-PSObjectEmptyOrNullProperty -PSObject $UserInfo 14 | 15 | .NOTES 16 | Francois-Xavier Cat 17 | lazywinadmin.com 18 | @lazywinadmin 19 | .LINK 20 | https://github.com/lazywinadmin/PowerShell 21 | #> 22 | PARAM ( 23 | $PSObject) 24 | PROCESS { 25 | $PsObject.psobject.Properties | 26 | Where-Object -FilterScript { -not $_.value } | 27 | ForEach-Object -Process { 28 | $PsObject.psobject.Properties.Remove($_.name) 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /TOOL-Resolve-ShortURL/Resolve-ShortURL.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-ShortURL { 2 | <# 3 | .SYNOPSIS 4 | Function to resolve a short URL to the absolute URI 5 | 6 | .DESCRIPTION 7 | Function to resolve a short URL to the absolute URI 8 | 9 | .PARAMETER ShortUrl 10 | Specifies the ShortURL 11 | 12 | .EXAMPLE 13 | Resolve-ShortURL -ShortUrl http://goo.gl/P5PKq 14 | 15 | .EXAMPLE 16 | Resolve-ShortURL -ShortUrl http://go.microsoft.com/fwlink/?LinkId=280243 17 | 18 | .NOTES 19 | Francois-Xavier Cat 20 | lazywinadmin.com 21 | @lazywinadmin 22 | github.com/lazywinadmin 23 | .LINK 24 | https://github.com/lazywinadmin/PowerShell 25 | #> 26 | 27 | [CmdletBinding()] 28 | [OutputType([System.String])] 29 | PARAM 30 | ( 31 | [String[]]$ShortUrl 32 | ) 33 | 34 | FOREACH ($URL in $ShortUrl) { 35 | TRY { 36 | Write-Verbose -Message "$URL - Querying..." 37 | (Invoke-WebRequest -Uri $URL -MaximumRedirection 0 -ErrorAction Ignore).Headers.Location 38 | } 39 | CATCH { 40 | $PSCmdlet.ThrowTerminatingError($_) 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Francois-Xavier Cat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /TOOL-Remove-HashTableEmptyValue/Remove-HashTableEmptyValue.ps1: -------------------------------------------------------------------------------- 1 | Function Remove-HashTableEmptyValue { 2 | <# 3 | .SYNOPSIS 4 | This function will remove the empty or Null entry of a hashtable object 5 | .DESCRIPTION 6 | This function will remove the empty or Null entry of a hashtable object 7 | .PARAMETER Hashtable 8 | Specifies the hashtable that will be cleaned up. 9 | .EXAMPLE 10 | Remove-HashTableEmptyValue -HashTable $SplattingVariable 11 | .NOTES 12 | Francois-Xavier Cat 13 | @lazywinadmin 14 | lazywinadmin.com 15 | github.com/lazywinadmin 16 | .LINK 17 | https://github.com/lazywinadmin/PowerShell 18 | #> 19 | [CmdletBinding()] 20 | PARAM([System.Collections.Hashtable]$HashTable) 21 | 22 | $HashTable.GetEnumerator().name | 23 | ForEach-Object -Process { 24 | if ($HashTable[$_] -eq "" -or $null -eq $HashTable[$_]) { 25 | Write-Verbose -Message "[Remove-HashTableEmptyValue][PROCESS] - Property: $_ removing..." 26 | [void]$HashTable.Remove($_) 27 | Write-Verbose -Message "[Remove-HashTableEmptyValue][PROCESS] - Property: $_ removed" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemRelatedCI/Get-SCSMWorkItemRelatedCI.ps1: -------------------------------------------------------------------------------- 1 | function Get-SCSMWorkItemRelatedCI { 2 | <# 3 | .SYNOPSIS 4 | Function to retrieve the related configuration item of a System Center Service Manager Work Item 5 | 6 | .DESCRIPTION 7 | Function to retrieve the related configuration item of a System Center Service Manager Work Item 8 | 9 | .PARAMETER GUID 10 | Specifies the GUID of the WorkItem 11 | 12 | .EXAMPLE 13 | PS C:\> Get-SCSMWorkItemRelatedCI -GUID "69c5dfc9-9acb-0afb-9210-190d3054901e" 14 | 15 | .NOTES 16 | Francois-Xavier.Cat 17 | @lazywinadmin 18 | lazywinadmin.com 19 | .LINK 20 | https://github.com/lazywinadmin/PowerShell 21 | #> 22 | PARAM ( 23 | [parameter()] 24 | [Alias()] 25 | $GUID 26 | ) 27 | PROCESS { 28 | # Find the Ticket Object 29 | $WorkItemObject = Get-SCSMObject -id $GUID 30 | 31 | # Find the Related Configuration Items 32 | Get-SCSMRelationshipObject -BySource $WorkItemObject | 33 | Where-Object -FilterScript { $_.relationshipid -eq 'd96c8b59-8554-6e77-0aa7-f51448868b43' } 34 | } 35 | } -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemAffectedCI/Get-SCSMWorkItemAffectedCI.ps1: -------------------------------------------------------------------------------- 1 | function Get-SCSMWorkItemAffectedCI { 2 | <# 3 | .SYNOPSIS 4 | Function to retrieve the affected configuration item of a System Center Service Manager Work Item 5 | 6 | .DESCRIPTION 7 | Function to retrieve the affected configuration item of a System Center Service Manager Work Item 8 | 9 | .PARAMETER GUID 10 | Specifies the GUID of the WorkItem 11 | 12 | .EXAMPLE 13 | PS C:\> Get-SCSMWorkItemAffectedCI -GUID "69c5dfc9-9acb-0afb-9210-190d3054901e" 14 | 15 | .NOTES 16 | Francois-Xavier.Cat 17 | @lazywinadmin 18 | lazywinadmin.com 19 | .LINK 20 | https://github.com/lazywinadmin/PowerShell 21 | #> 22 | PARAM ( 23 | [parameter()] 24 | [Alias()] 25 | $GUID 26 | ) 27 | PROCESS { 28 | # Find the Ticket Object 29 | $WorkItemObject = Get-SCSMObject -id $GUID 30 | 31 | # Find the Affected Configuration Items 32 | Get-SCSMRelationshipObject -BySource $WorkItemObject | 33 | Where-Object -FilterScript { $_.relationshipid -eq 'b73a6094-c64c-b0ff-9706-1822df5c2e82' } 34 | } 35 | } -------------------------------------------------------------------------------- /AZURE-Get-AzToken/Get-AzToken.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Retrieve token of the current Azure Context session 4 | .DESCRIPTION 5 | Retrieve token of the current Azure Context session 6 | This is using the Get-AzContext cmdlets from the module Az.Account and assume a session is already opened. 7 | 8 | .EXAMPLE 9 | $token=Get-AzToken 10 | $uri = "https://management.azure.com/tenants?api-version=2019-11-01" 11 | invoke-restmethod -method get -uri $uri -Headers @{Authorization="Bearer $token";'Content-Type'='application/json'} 12 | 13 | This leverate the token of the current session to query the Azure Management 14 | API and retrieves all the tenants information 15 | .LINK 16 | https://github.com/lazywinadmin/PowerShell 17 | 18 | #> 19 | [CmdletBinding()] 20 | Param() 21 | try{ 22 | $currentAzureContext = Get-AzContext 23 | $azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile; 24 | $profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azureRmProfile) 25 | $profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId).AccessToken 26 | }catch{ 27 | throw $_ 28 | } -------------------------------------------------------------------------------- /AD-TOOL-Test-ADCredential/Test-ADCredential.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Verify Active Directory credentials 4 | .DESCRIPTION 5 | This function takes a user name and a password as input and will verify if the combination is correct. The function returns a boolean based on the result. 6 | .NOTES 7 | Name: Test-ADCredential 8 | Version: 1.0 9 | .PARAMETER UserName 10 | The samaccountname of the Active Directory user account 11 | .PARAMETER Password 12 | The password of the Active Directory user account 13 | .EXAMPLE 14 | Test-ADCredential -username username1 -password Password1! 15 | Description: 16 | Verifies if the username and password provided are correct, returning either true or false based on the result 17 | #> 18 | function Test-ADCredential { 19 | [CmdletBinding()] 20 | Param 21 | ( 22 | [string]$UserName, 23 | [string]$Password 24 | ) 25 | if (!($UserName) -or !($Password)) { 26 | Write-Warning 'Test-ADCredential: Please specify both user name and password' 27 | } else { 28 | Add-Type -AssemblyName System.DirectoryServices.AccountManagement 29 | $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain') 30 | $DS.ValidateCredentials($UserName, $Password) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TOOL-Get-StringLastDigit/Get-StringLastDigit.ps1: -------------------------------------------------------------------------------- 1 | function Get-StringLastDigit { 2 | <# 3 | .SYNOPSIS 4 | Get the last digit of a string 5 | .DESCRIPTION 6 | Get the last digit of a string using Regular Expression 7 | .PARAMETER String 8 | Specifies the String to check 9 | .EXAMPLE 10 | PS C:\> Get-StringLastDigit -String "Francois-Xavier.cat5" 11 | 12 | 5 13 | .EXAMPLE 14 | PS C:\> Get-StringLastDigit -String "Francois-Xavier.cat" 15 | 16 | 17 | .EXAMPLE 18 | PS C:\> Get-StringLastDigit -String "Francois-Xavier.cat" -Verbose 19 | 20 | 21 | VERBOSE: The following string does not finish by a digit: Francois-Xavier.cat 22 | .NOTES 23 | Francois-Xavier Cat 24 | @lazywinadmin 25 | lazywinadmin.com 26 | .LINK 27 | https://github.com/lazywinadmin/PowerShell 28 | #> 29 | [CmdletBinding()] 30 | PARAM($String) 31 | try { 32 | #Check if finish by Digit 33 | if ($String -match "^.*\d$") { 34 | # Output the last digit 35 | $String.Substring(($String.ToCharArray().count) - 1) 36 | } 37 | else { Write-Verbose -Message "The following string does not finish by a digit: $String" } 38 | } 39 | catch { $PSCmdlet.ThrowTerminatingError($_) } 40 | } -------------------------------------------------------------------------------- /TOOL-ConvertFrom-Base64/ConvertFrom-Base64.ps1: -------------------------------------------------------------------------------- 1 | function ConvertFrom-Base64 { 2 | <# 3 | .SYNOPSIS 4 | Converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array. 5 | 6 | .DESCRIPTION 7 | Converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array. 8 | 9 | .PARAMETER String 10 | Specifies the String to Convert 11 | 12 | .EXAMPLE 13 | ConvertFrom-Base64 -String $ImageBase64 |Out-File ImageTest.png 14 | 15 | .NOTES 16 | Francois-Xavier Cat 17 | @lazywinadmin 18 | lazywinadmin.com 19 | github.com/lazywinadmin 20 | .Link 21 | https://github.com/lazywinadmin/PowerShell 22 | #> 23 | [CmdletBinding()] 24 | PARAM ( 25 | [parameter(Mandatory = $true, ValueFromPipeline)] 26 | [String]$String 27 | ) 28 | TRY { 29 | Write-Verbose -Message "[ConvertFrom-Base64] Converting String" 30 | [System.Text.Encoding]::Default.GetString( 31 | [System.Convert]::FromBase64String($String) 32 | ) 33 | } 34 | CATCH { 35 | Write-Error -Message "[ConvertFrom-Base64] Something wrong happened" 36 | $Error[0].Exception.Message 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /AD-GPO-Get-ADGPOReplication/README.MD: -------------------------------------------------------------------------------- 1 | Get-ADGPOReplication 2 | =================== 3 | 4 | [Blog article on lazywinadmin.com](http://www.lazywinadmin.com/2014/10/powershell-check-gpo-replication.html) 5 | 6 | Get-ADGPOReplication is retrieving the GPO version and Sysvol version accross the domain for one or more Group Policy objects. This can especially helps you troubleshooting replication issues. 7 | 8 | This small function is taking advantage of the module ActiveDirectory to retrieve the list of all Domain Controllers and the module GroupPolicy to query one or more Group Policy objects. 9 | 10 | For each GPO, It will then retrieve the version of the User/Computer configurations and the Sysvol Version. 11 | 12 | 13 | ##Examples 14 | Using the function against one GPO: 15 | ```PowerShell 16 | Get-ADGPOReplication -GPOName "AZE_Test" 17 | ``` 18 | 19 | Using the function against multiple GPO: 20 | ```PowerShell 21 | Get-ADGPOReplication -GPOName "AZE_Test", "AZE_Test2" 22 | ``` 23 | 24 | ![alt tag](images/Get-ADGPOReplication01.png) 25 | 26 | 27 | Using the function against All GPO: 28 | ```PowerShell 29 | Get-ADGPOReplication -All 30 | ``` 31 | 32 | Optionally you can send the output to Out-Gridview which will give you a very nice view on all your GPO versions. 33 | ```PowerShell 34 | Get-ADGPOReplication -GPOName AZE_Test | Out-GridView -Title "AZE_Test $(Get-Date)" 35 | ``` 36 | ![alt tag](images/Get-ADGPOReplication_OutGridView.png) 37 | 38 | -------------------------------------------------------------------------------- /TOOL-Clean-MacAddress/README.md: -------------------------------------------------------------------------------- 1 | [CleanMacaddress01]: https://github.com/lazywinadmin/PowerShell/blob/master/TOOL-Clean-MacAddress/Clean-MacAddress01.png 2 | # Clean-MacAddress 3 | This function is used to clean up a Mac Address string. 4 | 5 | I'm using this for some report and for SCCM Automation to keep everything clean :-) 6 | ## Loading the function 7 | 8 | ```PowerShell 9 | # Load the function in your PS 10 | . .\Clean-MacAddress.ps1 11 | ``` 12 | 13 | ![alt text][CleanMacAddress01] 14 | 15 | ## Clean a Mac Address 16 | 17 | ```PowerShell 18 | # Clean a Mac Address 19 | Clean-MacAddress -MacAddress '00:11:22:33:44:55' 20 | 001122334455 21 | 22 | # Clean a Mac Address and convert to UpperCase 23 | Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Uppercase 24 | 001122DDEEFF 25 | 26 | # Clean a Mac Address and convert to LowerCase 27 | Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Lowercase 28 | 001122ddeeff 29 | 30 | # Clean a Mac Address and convert to LowerCase and add a dash separator 31 | Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Lowercase -Separator '-' 32 | 00-11-22-dd-ee-ff 33 | 34 | # Clean a Mac Address and convert to LowerCase and add a dot separator 35 | Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Lowercase -Separator '.' 36 | 00.11.22.dd.ee.ff 37 | 38 | # Clean a Mac Address and convert to LowerCase and add a colon separator 39 | Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Lowercase -Separator : 40 | 00:11:22:dd:ee:ff 41 | 42 | ``` 43 | -------------------------------------------------------------------------------- /TOOL-Get-HelpMessage/Get-HelpMessage.ps1: -------------------------------------------------------------------------------- 1 | function Get-HelpMessage { 2 | <# 3 | .SYNOPSIS 4 | Function to explain why an error occurred and provides problem-solving information. 5 | Equivalent of NET HELPMSG 6 | 7 | .DESCRIPTION 8 | Function to explain why an error occurred and provides problem-solving information. 9 | Equivalent of NET HELPMSG. 10 | 11 | The function also create an alias called HelpMsg, so you can call the function this way: 12 | HelpMsg 618 13 | 14 | .PARAMETER Id 15 | Specify the ID of the error you want to retrieve. 16 | Can be decimal, hexadecimal 17 | 18 | .EXAMPLE 19 | Get-HelpMessage 618 20 | 21 | The specified compression format is unsupported 22 | 23 | .EXAMPLE 24 | Get-HelpMessage 0x80070652 25 | 26 | Another installation is already in progress. Complete that installation before proceeding with this install 27 | 28 | .EXAMPLE 29 | Get-HelpMessage –2147023278 30 | Another installation is already in progress. Complete that installation before proceeding with this install 31 | 32 | .NOTES 33 | http://www.leeholmes.com/blog/2009/09/15/powershell-equivalent-of-net-helpmsg/ 34 | .LINK 35 | https://github.com/lazywinadmin/PowerShell 36 | #> 37 | [CmdletBinding()] 38 | [Alias('HelpMsg')] 39 | PARAM($Id) 40 | try { 41 | [ComponentModel.Win32Exception] $id 42 | } 43 | catch { 44 | $PSCmdlet.ThrowTerminatingError($_) 45 | } 46 | } -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemParent/README.md: -------------------------------------------------------------------------------- 1 | [GetSCSMWorkItemParent01]: https://github.com/lazywinadmin/PowerShell/blob/master/SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent01.jpg 2 | [GetSCSMWorkItemParent02]: https://github.com/lazywinadmin/PowerShell/blob/master/SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent02.jpg 3 | [GetSCSMWorkItemParent03]: https://github.com/lazywinadmin/PowerShell/blob/master/SCSM-Get-SCSMWorkItemParent/images/Get-SCSMWorkItemParent03.jpg 4 | # Get-SCSMWorkItemParent 5 | 6 | ## Loading the function 7 | 8 | ```PowerShell 9 | # Load the function in your PS 10 | . .\Get-SCSMWorkItemParent.ps1 11 | ``` 12 | 13 | ![alt text][GetSCSMWorkItemParent01] 14 | 15 | ## Get the Work Item Parent of a Runbook Activity 16 | 17 | ```PowerShell 18 | # Load the function in your PS 19 | # Get a Runbook Activity 20 | $RunbookActivity = Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.SystemCenter.Orchestrator.RunbookAutomationActivity$) -filter 'ID -eq RB12813' 21 | 22 | # Get the Runbook Activity's Work Item Parent 23 | Get-SCSMWorkItemParent -WorkItemObject $RunbookActivity 24 | ``` 25 | 26 | ![alt text][GetSCSMWorkItemParent02] 27 | 28 | 29 | ## Get the Work Item Parent of a Runbook Activity using a GUID 30 | 31 | ```PowerShell 32 | # Load the function in your PS 33 | # Get a Runbook Activity GUID 34 | $RunbookActivity.get_id() 35 | 36 | # Get the Runbook Activity's Work Item Parent from the RBA guid 37 | Get-SCSMWorkItemParent -WorkItemGuid $RunbookActivity.Get_id() 38 | ``` 39 | 40 | ![alt text][GetSCSMWorkItemParent03] 41 | -------------------------------------------------------------------------------- /TOOL-Test-RemoteDesktopIsEnabled/Test-RemoteDesktopIsEnabled.ps1: -------------------------------------------------------------------------------- 1 | function Test-RemoteDesktopIsEnabled { 2 | <# 3 | .SYNOPSIS 4 | Function to check if RDP is enabled 5 | 6 | .DESCRIPTION 7 | Function to check if RDP is enabled 8 | 9 | .EXAMPLE 10 | Test-RemoteDesktopIsEnabled 11 | 12 | Test if Remote Desktop is enabled on the current machine 13 | 14 | .EXAMPLE 15 | Test-RemoteDesktopIsEnabled -ComputerName SERVER01,SERVER02 16 | 17 | Test if Remote Desktop is enabled on the remote machine SERVER01 and SERVER02 18 | 19 | .NOTES 20 | Francois-Xavier Cat 21 | @lazywinadmin 22 | lazywinadmin.com 23 | github.com/lazywinadmin 24 | #> 25 | 26 | 27 | PARAM( 28 | [String[]]$ComputerName = $env:COMPUTERNAME 29 | ) 30 | FOREACH ($Computer in $ComputerName) { 31 | TRY { 32 | IF (Test-Connection -Computer $Computer -count 1 -quiet) { 33 | $Splatting = @{ 34 | ComputerName = $Computer 35 | NameSpace = "root\cimv2\TerminalServices" 36 | } 37 | # Enable Remote Desktop 38 | [boolean](Get-WmiObject -Class Win32_TerminalServiceSetting @Splatting).AllowTsConnections 39 | 40 | # Disable requirement that user must be authenticated 41 | #(Get-WmiObject -Class Win32_TSGeneralSetting @Splatting -Filter "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(0) | Out-Null 42 | } 43 | } 44 | CATCH { 45 | $PSCmdlet.ThrowTerminatingError($_) 46 | } 47 | }#FOREACH 48 | 49 | }#Function -------------------------------------------------------------------------------- /TOOL-Get-NetStat/Get-NetStat.ps1: -------------------------------------------------------------------------------- 1 | function Get-NetStat { 2 | <# 3 | .SYNOPSIS 4 | This function will get the output of netstat -n and parse the output 5 | .DESCRIPTION 6 | This function will get the output of netstat -n and parse the output 7 | .EXAMPLE 8 | Get-Netstat 9 | .LINK 10 | https://lazywinadmin.com/2014/08/powershell-parse-this-netstatexe.html 11 | .NOTES 12 | Francois-Xavier Cat 13 | lazywinadmin.com 14 | @lazywinadmin 15 | .LINK 16 | https://github.com/lazywinadmin/PowerShell 17 | #> 18 | PROCESS { 19 | # Get the output of netstat 20 | $data = netstat -n 21 | 22 | # Keep only the line with the data (we remove the first lines) 23 | $data = $data[4..$data.count] 24 | 25 | # Each line need to be splitted and get rid of unnecessary spaces 26 | foreach ($line in $data) { 27 | # Get rid of the first whitespaces, at the beginning of the line 28 | $line = $line -replace '^\s+', '' 29 | 30 | # Split each property on whitespaces block 31 | $line = $line -split '\s+' 32 | 33 | # Define the properties 34 | $properties = @{ 35 | Protocole = $line[0] 36 | LocalAddressIP = ($line[1] -split ":")[0] 37 | LocalAddressPort = ($line[1] -split ":")[1] 38 | ForeignAddressIP = ($line[2] -split ":")[0] 39 | ForeignAddressPort = ($line[2] -split ":")[1] 40 | State = $line[3] 41 | } 42 | 43 | # Output the current line 44 | New-Object -TypeName PSObject -Property $properties 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /_Template/Get-Something.ps1: -------------------------------------------------------------------------------- 1 | Function Get-Something { 2 | <# 3 | .SYNOPSIS 4 | A brief description of the Get-Something function. 5 | 6 | .DESCRIPTION 7 | A detailed description of the Get-Something function. 8 | 9 | .PARAMETER ComputerName 10 | A description of the ComputerName parameter. 11 | 12 | .PARAMETER Credential 13 | A description of the Credential parameter. 14 | 15 | .EXAMPLE 16 | Get-Something -ComputerName $value1 -Credential $value2 17 | 18 | .NOTES 19 | Francois-Xavier Cat 20 | lazywinadmin.github.io 21 | lazywinadmin.com 22 | @lazywinadmin 23 | 24 | 1.0 | 2016/00/00 | Francois-Xavier Cat 25 | Initial Version 26 | #> 27 | [CmdletBinding()] 28 | PARAM ( 29 | [Alias("CN", "__SERVER", "PSComputerName")] 30 | [String[]]$ComputerName = $env:COMPUTERNAME, 31 | 32 | [Alias("RunAs")] 33 | [System.Management.Automation.Credential()] 34 | [pscredential] 35 | $Credential = [System.Management.Automation.PSCredential]::Empty 36 | )#PARAM 37 | TRY { 38 | $FunctionName = $MyInvocation.MyCommand.Name 39 | 40 | 41 | $Splatting = @{ 42 | ComputerName = $ComputerName 43 | } 44 | 45 | IF ($PSBoundParameters['Credential']) { 46 | Write-Verbose -Message "[$FunctionName] Appending Credential" 47 | $Splatting.Credential = $Credential 48 | } 49 | 50 | # MAIN CODE HERE 51 | Write-Verbose -Message "[$FunctionName] Connect to..." 52 | 53 | } 54 | CATCH { 55 | $PSCmdlet.ThrowTerminatingError($_) 56 | }#CATCH 57 | FINALLY { 58 | #Some Cleanup tasks 59 | }#FINALLY 60 | }#Function -------------------------------------------------------------------------------- /tests/Add-LocalGroupMember.ps1: -------------------------------------------------------------------------------- 1 | Function Add-LocalGroupMember { 2 | <# 3 | .SYNOPSIS 4 | .DESCRIPTION 5 | .PARAMETER 6 | .EXAMPLE 7 | .NOTES 8 | Add support for local user/group and ad user/group 9 | 10 | New-ADGroup -Name "AdmServer$env:COMPUTERNAME" -GroupScope Global -GroupCategory Security -Path $ouPath 11 | $fqdn = $_.DNSRoot 12 | ([adsi]"WinNT://./Administrators,group").Add("WinNT://$fqdn/AdmServer$env:COMPUTERNAME") 13 | 14 | #> 15 | [cmdletBinding()] 16 | Param ( 17 | [Parameter(Mandatory = $True)] 18 | [string[]]$ComputerName, 19 | [Parameter(Mandatory = $True)] 20 | [string]$GroupName, 21 | [Parameter(Mandatory = $True)] 22 | [string]$Domain, 23 | [Parameter(Mandatory = $True)] 24 | [string]$Account 25 | ) 26 | BEGIN { 27 | #Check in AD for SamAccountName 28 | $ADCheck = ([adsisearcher]"(samaccountname=$Account)").findone().properties['samaccountname'] 29 | if ($SamAccountName -notmatch '\\') { 30 | $ADResolved = (Resolve-SamAccount -SamAccount $SamAccountName -Exit:$true) 31 | $SamAccountName = 'WinNT://', "$env:userdomain", '/', $ADResolved -join '' 32 | } 33 | else { 34 | $ADResolved = ($SamAccountName -split '\\')[1] 35 | $DomainResolved = ($SamAccountName -split '\\')[0] 36 | $SamAccountName = 'WinNT://', $DomainResolved, '/', $ADResolved -join '' 37 | } 38 | 39 | } 40 | PROCESS { 41 | $de = [ADSI]"WinNT://$computer/$Group,group" 42 | $de.psbase.Invoke("Add", ([ADSI]"WinNT://$domain/$user").path) 43 | } 44 | END { 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /TOOL-Get-ISEShortcut/Get-ISEShortcut.ps1: -------------------------------------------------------------------------------- 1 | function Get-ISEShortCut { 2 | <# 3 | .SYNOPSIS 4 | List ISE Shortcuts 5 | 6 | .DESCRIPTION 7 | List ISE Shortcuts. 8 | This won't run in a regular powershell console, only in ISE. 9 | 10 | .EXAMPLE 11 | Get-ISEShortcut 12 | 13 | Will list all the shortcuts available 14 | .EXAMPLE 15 | Get-Help Get-ISEShortcut -Online 16 | 17 | Will show technet page of ISE Shortcuts 18 | .NOTES 19 | Francois-Xavier Cat 20 | lazywinadmin.com 21 | @lazywinadmin 22 | 23 | VERSION HISTORY 24 | 2015/01/10 Initial Version 25 | http://technet.microsoft.com/en-us/library/jj984298.aspx 26 | .LINK 27 | https://github.com/lazywinadmin/PowerShell 28 | #> 29 | PARAM($Key, $Name) 30 | BEGIN { 31 | function Test-IsISE { 32 | # try...catch accounts for: 33 | # Set-StrictMode -Version latest 34 | try { 35 | $null -ne $psISE 36 | } 37 | catch { 38 | return $false; 39 | } 40 | } 41 | } 42 | PROCESS { 43 | if ($(Test-IsISE) -eq $true) { 44 | # http://www.powershellmagazine.com/2013/01/29/the-complete-list-of-powershell-ise-3-0-keyboard-shortcuts/ 45 | 46 | # Reference to the ISE Microsoft.PowerShell.GPowerShell assembly (DLL) 47 | $gps = $psISE.GetType().Assembly 48 | $rm = New-Object -TypeName System.Resources.ResourceManager -ArgumentList GuiStrings, $gps 49 | $rs = $rm.GetResourceSet((Get-Culture), $true, $true) 50 | $rs | Where-Object -Property Name -match 'Shortcut\d?$|^F\d+Keyboard' | 51 | Sort-Object -Property Value 52 | 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /TOOL-Set-RDPEnable/Set-RDPEnable.ps1: -------------------------------------------------------------------------------- 1 | function Set-RDPEnable { 2 | <# 3 | .SYNOPSIS 4 | The function Set-RDPEnable enable RDP remotely using the registry 5 | 6 | .DESCRIPTION 7 | The function Set-RDPEnable enable RDP remotely using the registry 8 | 9 | .PARAMETER ComputerName 10 | Specifies the ComputerName 11 | 12 | .EXAMPLE 13 | PS C:\> Set-RDPEnable 14 | 15 | .EXAMPLE 16 | PS C:\> Set-RDPEnable -ComputerName "DC01" 17 | 18 | .EXAMPLE 19 | PS C:\> Set-RDPEnable -ComputerName "DC01","DC02","DC03" 20 | 21 | .NOTES 22 | Francois-Xavier Cat 23 | lazywinadmin.com 24 | @lazywinadmin 25 | #> 26 | 27 | [CmdletBinding(SupportsShouldProcess = $true)] 28 | PARAM ( 29 | [String[]]$ComputerName = $env:COMPUTERNAME 30 | ) 31 | PROCESS { 32 | FOREACH ($Computer in $ComputerName) { 33 | TRY { 34 | IF ($PSCmdlet.ShouldProcess($Computer, "Enable Remote Desktop")) { 35 | IF (Test-Connection -ComputerName $Computer -Count 1 -Quiet) { 36 | $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $Computer) 37 | $regKey = $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server", $True) 38 | $regkey.SetValue("fDenyTSConnections", 0) 39 | $regKey.flush() 40 | $regKey.Close() 41 | } #IF Test-Connection 42 | } 43 | } #Try 44 | CATCH { 45 | $PSCmdlet.ThrowTerminatingError($_) 46 | } #Catch 47 | } #FOREACH 48 | } #Process 49 | } -------------------------------------------------------------------------------- /TOOL-Get-ProcessForeignAddress/Get-ProcessForeignAddress.ps1: -------------------------------------------------------------------------------- 1 | function Get-ProcessForeignAddress { 2 | <# 3 | .SYNOPSIS 4 | Get all foreignIPAddress for all or specific processname 5 | 6 | .DESCRIPTION 7 | Get all foreignIPAddress for all or specific processname 8 | 9 | .PARAMETER ProcessName 10 | Specifies the ProcessName to filter on 11 | 12 | .EXAMPLE 13 | Get-ProcessForeignAddress 14 | 15 | Retrieve all the foreign addresses 16 | 17 | .EXAMPLE 18 | Get-ProcessForeignAddress chrome 19 | 20 | Show all the foreign address(es) for the process chrome 21 | 22 | .EXAMPLE 23 | Get-ProcessForeignAddress chrome | select ForeignAddress -Unique 24 | 25 | Show all the foreign address(es) for the process chrome and show only the ForeignAddress(es) once 26 | 27 | .NOTES 28 | Author : Francois-Xavier Cat 29 | Website : lazywinadmin.com 30 | Github : github.com/lazywinadmin 31 | Twitter : @lazywinadmin 32 | .LINK 33 | https://github.com/lazywinadmin/PowerShell 34 | #> 35 | PARAM ($ProcessName) 36 | $netstat = netstat -no 37 | 38 | $Result = $netstat[4..$netstat.count] | 39 | ForEach-Object -Process { 40 | $current = $_.trim() -split '\s+' 41 | 42 | New-Object -TypeName PSobject -Property @{ 43 | ProcessName = (Get-Process -id $current[4]).processname 44 | ForeignAddressIP = ($current[2] -split ":")[0] #-as [ipaddress] 45 | ForeignAddressPort = ($current[2] -split ":")[1] 46 | State = $current[3] 47 | } 48 | } 49 | 50 | if ($ProcessName) { 51 | $result | Where-Object -FilterScript { $_.processname -like "$processname" } 52 | } 53 | else { $Result } 54 | } -------------------------------------------------------------------------------- /TOOL-Set-RDPDisable/Set-RDPDisable.ps1: -------------------------------------------------------------------------------- 1 | function Set-RDPDisable { 2 | <# 3 | .SYNOPSIS 4 | The function Set-RDPDisable disable RDP remotely using the registry 5 | 6 | .DESCRIPTION 7 | The function Set-RDPDisable disable RDP remotely using the registry 8 | 9 | .PARAMETER ComputerName 10 | Specifies the ComputerName 11 | 12 | .EXAMPLE 13 | PS C:\> Set-RDPDisable 14 | 15 | .EXAMPLE 16 | PS C:\> Set-RDPDisable -ComputerName "DC01" 17 | 18 | .EXAMPLE 19 | PS C:\> Set-RDPDisable -ComputerName "DC01","DC02","DC03" 20 | 21 | .NOTES 22 | Francois-Xavier Cat 23 | lazywinadmin.com 24 | @lazywinadmin 25 | .LINK 26 | https://github.com/lazywinadmin/PowerShell 27 | #> 28 | [CmdletBinding(SupportsShouldProcess = $true)] 29 | PARAM ( 30 | [String[]]$ComputerName = $env:COMPUTERNAME 31 | ) 32 | PROCESS { 33 | FOREACH ($Computer in $ComputerName) { 34 | TRY { 35 | IF ($PSCmdlet.ShouldProcess($Computer, "Disable Remote Desktop")) { 36 | IF (Test-Connection -ComputerName $Computer -Count 1 -Quiet) { 37 | $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $Computer) 38 | $regKey = $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server", $True) 39 | $regkey.SetValue("fDenyTSConnections", 1) 40 | $regKey.flush() 41 | $regKey.Close() 42 | } 43 | } 44 | } #Try 45 | CATCH { 46 | $PSCmdlet.ThrowTerminatingError($_) 47 | } #Catch 48 | } #FOREACH 49 | } #Process 50 | } -------------------------------------------------------------------------------- /EXCHANGE-Connect-ExchangeOnPremises/Connect-ExchangeOnPremises.ps1: -------------------------------------------------------------------------------- 1 | function Connect-ExchangeOnPremises { 2 | <# 3 | .SYNOPSIS 4 | Function to Connect to an Exchange OnPremises environment 5 | 6 | .DESCRIPTION 7 | Function to Connect to an Exchange OnPremises environment 8 | 9 | .PARAMETER ConnectionUri 10 | Specifies the Connection Uri to use 11 | Example: http://ExchServer.lazywinadmin.com/powershell 12 | 13 | .PARAMETER Credential 14 | Specifies the credential to use 15 | 16 | .EXAMPLE 17 | PS C:\> Connect-ExchangeOnPremises -ConnectionUri http://ExchServer.lazywinadmin.com/powershell 18 | 19 | .EXAMPLE 20 | PS C:\> Connect-ExchangeOnPremises -ConnectionUri http://ExchServer.lazywinadmin.com/powershell -Credential (Get-Credential) 21 | 22 | .NOTES 23 | Francois-Xavier Cat 24 | lazywinadmin.com 25 | @lazywinadmin 26 | .LINK 27 | https://github.com/lazywinadmin/PowerShell 28 | #> 29 | PARAM ( 30 | [Parameter(Mandatory, HelpMessage = 'http:///powershell')] 31 | [system.string]$ConnectionUri, 32 | 33 | [Alias('RunAs')] 34 | [pscredential] 35 | [System.Management.Automation.Credential()] 36 | $Credential = [System.Management.Automation.PSCredential]::Empty 37 | ) 38 | try{ 39 | 40 | 41 | $Splatting = @{ 42 | ConnectionUri = $ConnectionUri 43 | ConfigurationName = 'microsoft.exchange' 44 | } 45 | IF ($PSBoundParameters['Credential']) { $Splatting.Credential = $Credential } 46 | 47 | # Load Exchange cmdlets (Implicit remoting) 48 | Import-PSSession -Session (New-PSSession @Splatting) 49 | }catch{ 50 | $PSCmdlet.ThrowTerminatingError($_) 51 | } 52 | } -------------------------------------------------------------------------------- /TOOL-Get-LocalGroup/Get-LocalGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-LocalGroup { 2 | 3 | <# 4 | .SYNOPSIS 5 | This script can be list all of local group account. 6 | 7 | .DESCRIPTION 8 | This script can be list all of local group account. 9 | The function is using WMI to connect to the remote machine 10 | 11 | .PARAMETER ComputerName 12 | Specifies the computers on which the command . The default is the local computer. 13 | 14 | .PARAMETER Credential 15 | A description of the Credential parameter. 16 | 17 | 18 | .EXAMPLE 19 | Get-LocalGroup 20 | 21 | This example shows how to list all the local groups on local computer. 22 | 23 | .NOTES 24 | Francois-Xavier Cat 25 | lazywinadmin.com 26 | @lazywinadmin 27 | .LINK 28 | https://github.com/lazywinadmin/PowerShell 29 | #> 30 | 31 | PARAM 32 | ( 33 | [Alias('cn')] 34 | [String[]]$ComputerName = $Env:COMPUTERNAME, 35 | 36 | [String]$AccountName, 37 | 38 | [System.Management.Automation.PsCredential]$Credential 39 | ) 40 | 41 | $Splatting = @{ 42 | Class = "Win32_Group" 43 | Namespace = "root\cimv2" 44 | Filter = "LocalAccount='$True'" 45 | } 46 | 47 | #Credentials 48 | If ($PSBoundParameters['Credential']) { $Splatting.Credential = $Credential } 49 | 50 | Foreach ($Computer in $ComputerName) { 51 | TRY { 52 | Write-Verbose -Message "[PROCESS] ComputerName: $Computer" 53 | Get-WmiObject @Splatting -ComputerName $Computer | Select-Object -Property Name, Caption, Status, SID, SIDType, Domain, Description 54 | } 55 | CATCH { 56 | Write-Warning -Message "[PROCESS] Issue connecting to $Computer" 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /TOOL-Get-LocalAdministrator/Get-LocalAdministrator.ps1: -------------------------------------------------------------------------------- 1 | function Get-LocalAdministratorBuiltin { 2 | <# 3 | .SYNOPSIS 4 | function to retrieve the local Administrator account 5 | 6 | .DESCRIPTION 7 | function to retrieve the local Administrator account 8 | 9 | .PARAMETER ComputerName 10 | Specifies the computername 11 | 12 | .EXAMPLE 13 | PS C:\> Get-LocalAdministratorBuiltin 14 | 15 | .EXAMPLE 16 | PS C:\> Get-LocalAdministratorBuiltin -ComputerName SERVER01 17 | 18 | .NOTES 19 | Francois-Xavier Cat 20 | lazywinadmin.com 21 | @lazywinadmin 22 | 23 | #function to get the BUILTIN LocalAdministrator 24 | #http://blog.simonw.se/powershell-find-builtin-local-administrator-account/ 25 | #> 26 | 27 | [CmdletBinding()] 28 | param ( 29 | [Parameter()] 30 | $ComputerName = $env:computername 31 | ) 32 | Process { 33 | Foreach ($Computer in $ComputerName) { 34 | Try { 35 | Add-Type -AssemblyName System.DirectoryServices.AccountManagement 36 | $PrincipalContext = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine, $Computer) 37 | $UserPrincipal = New-Object -TypeName System.DirectoryServices.AccountManagement.UserPrincipal($PrincipalContext) 38 | $Searcher = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalSearcher 39 | $Searcher.QueryFilter = $UserPrincipal 40 | $Searcher.FindAll() | Where-Object -FilterScript { $_.Sid -Like "*-500" } 41 | } 42 | Catch { 43 | Write-Warning -Message "$($_.Exception.Message)" 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /TOOL-Get-PSObjectEmptyOrNullProperty/Get-PSObjectEmptyOrNullProperty.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSObjectEmptyOrNullProperty { 2 | <# 3 | .SYNOPSIS 4 | Function to Get all the empty or null properties with empty value in a PowerShell Object 5 | 6 | .DESCRIPTION 7 | Function to Get all the empty or null properties with empty value in a PowerShell Object. 8 | I used this function in a System Center Orchestrator where I had a runbook that could update most of the important 9 | properties of a user. Using this function I knew which properties were not be updated. 10 | 11 | .PARAMETER PSObject 12 | Specifies the PowerShell Object 13 | 14 | .EXAMPLE 15 | PS C:\> Get-PSObjectEmptyOrNullProperty -PSObject $UserInfo 16 | 17 | .EXAMPLE 18 | 19 | # Create a PowerShell Object with some properties 20 | $o=''|select FirstName,LastName,nullable 21 | $o.firstname='Nom' 22 | $o.lastname='' 23 | $o.nullable=$null 24 | 25 | # Look for empty or null properties 26 | Get-PSObjectEmptyOrNullProperty -PSObject $o 27 | 28 | MemberType : NoteProperty 29 | IsSettable : True 30 | IsGettable : True 31 | Value : 32 | TypeNameOfValue : System.String 33 | Name : LastName 34 | IsInstance : True 35 | 36 | MemberType : NoteProperty 37 | IsSettable : True 38 | IsGettable : True 39 | Value : 40 | TypeNameOfValue : System.Object 41 | Name : nullable 42 | IsInstance : True 43 | 44 | .NOTES 45 | Francois-Xavier Cat 46 | lazywinadmin.com 47 | @lazywinadmin 48 | .LINK 49 | https://github.com/lazywinadmin/PowerShell 50 | #> 51 | PARAM ( 52 | $PSObject) 53 | PROCESS { 54 | $PsObject.psobject.Properties | 55 | Where-Object -FilterScript { -not $_.value } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /TOOL-Set-RemoteDesktop/Set-RemoteDesktop.ps1: -------------------------------------------------------------------------------- 1 | function Set-RemoteDesktop { 2 | <# 3 | .SYNOPSIS 4 | The function Set-RemoteDesktop allows you to enable or disable RDP remotely using the registry 5 | 6 | .DESCRIPTION 7 | The function Set-RemoteDesktop allows you to enable or disable RDP remotely using the registry 8 | 9 | .PARAMETER ComputerName 10 | Specifies the ComputerName 11 | 12 | .EXAMPLE 13 | PS C:\> Set-RemoteDesktop -enable $true 14 | 15 | .EXAMPLE 16 | PS C:\> Set-RemoteDesktop -ComputerName "DC01" -enable $false 17 | 18 | .EXAMPLE 19 | PS C:\> Set-RemoteDesktop -ComputerName "DC01","DC02","DC03" -enable $false 20 | 21 | .NOTES 22 | Francois-Xavier Cat 23 | lazywinadmin.com 24 | @lazywinadmin 25 | #> 26 | 27 | [CmdletBinding()] 28 | PARAM ( 29 | [String[]]$ComputerName = $env:COMPUTERNAME, 30 | [Parameter(Mandatory = $true)] 31 | [Boolean]$Enable 32 | ) 33 | PROCESS { 34 | FOREACH ($Computer in $ComputerName) { 35 | TRY { 36 | IF (Test-Connection -ComputerName $Computer -Count 1 -Quiet) { 37 | $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $Computer) 38 | $regKey = $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server", $True) 39 | 40 | IF ($Enable) { $regkey.SetValue("fDenyTSConnections", 0) } 41 | ELSE { $regkey.SetValue("fDenyTSConnections", 1) } 42 | $regKey.flush() 43 | $regKey.Close() 44 | } #IF Test-Connection 45 | } #Try 46 | CATCH { 47 | $PSCmdlet.ThrowTerminatingError($_) 48 | } #Catch 49 | } #FOREACH 50 | } #Process 51 | } -------------------------------------------------------------------------------- /TOOL-New-RandomPassword/New-RandomPassword.ps1: -------------------------------------------------------------------------------- 1 | function New-RandomPassword { 2 | <# 3 | .SYNOPSIS 4 | Function to generate a complex and random password 5 | .DESCRIPTION 6 | Function to generate a complex and random password 7 | 8 | This is using the GeneratePassword method from the 9 | system.web.security.membership NET Class. 10 | 11 | https://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword(v=vs.100).aspx 12 | 13 | .PARAMETER Length 14 | The number of characters in the generated password. The length must be between 1 and 128 characters. 15 | Default is 12. 16 | 17 | .PARAMETER NumberOfNonAlphanumericCharacters 18 | The minimum number of non-alphanumeric characters (such as @, #, !, %, &, and so on) in the generated password. 19 | Default is 5. 20 | 21 | .PARAMETER Count 22 | Specifies how many password you want. Default is 1 23 | 24 | .EXAMPLE 25 | New-RandomPassword 26 | []sHX@]W#w-{ 27 | .EXAMPLE 28 | New-RandomPassword -Length 8 -NumberOfNonAlphanumericCharacters 2 29 | v@Warq_6 30 | .EXAMPLE 31 | New-RandomPassword -Count 5 32 | *&$6&d1[f8zF 33 | Ns$@[lRH{;f4 34 | ;G$Su^M$bS+W 35 | mgZ/{y8}I@-t 36 | **W.)60kY4$V 37 | .NOTES 38 | francois-xavier.cat 39 | lazywinadmin.com 40 | @lazywinadmin 41 | github.com/lazywinadmin 42 | .LINK 43 | https://github.com/lazywinadmin/PowerShell 44 | #> 45 | PARAM ( 46 | [Int32]$Length = 12, 47 | 48 | [Int32]$NumberOfNonAlphanumericCharacters = 5, 49 | 50 | [Int32]$Count = 1 51 | ) 52 | 53 | BEGIN { 54 | Add-Type -AssemblyName System.web; 55 | } 56 | 57 | PROCESS { 58 | 1..$Count | ForEach-Object -Process { 59 | [System.Web.Security.Membership]::GeneratePassword($Length, $NumberOfNonAlphanumericCharacters) 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemChildItem/Get-SCSMWorkItemChildItem.ps1: -------------------------------------------------------------------------------- 1 | Function Get-SCSMWorkItemChildItem { 2 | <# 3 | .SYNOPSIS 4 | Retrieve item associated with a work item 5 | .DESCRIPTION 6 | Retrieve item associated with a work item 7 | .PARAMETER WorkItemGUID 8 | Specify the GUID of the WorkItem 9 | .EXAMPLE 10 | Get-SCSMWorkItemChildItem -WorkItemGuid $WIGuid 11 | .NOTES 12 | General notes 13 | .LINK 14 | https://github.com/lazywinadmin/PowerShell 15 | #> 16 | [CmdletBinding()] 17 | param ( 18 | [Parameter(Mandatory = $True)] 19 | $WorkItemGUID 20 | ) 21 | try { 22 | ### Variables to Return 23 | $childWIs_obj = @() 24 | 25 | ### MAIN 26 | $inputPWI_obj = get-scsmobject -id $WorkItemGUID 27 | $containsActivity_relclass_id = '2da498be-0485-b2b2-d520-6ebd1698e61b' 28 | $childWIs_relobj_filter = "RelationshipId -eq '$containsActivity_relclass_id'" 29 | $childWIs_relobj = Get-SCSMRelationshipObject -BySource $inputPWI_obj | 30 | Where-Object -FilterScript { 31 | $_.RelationshipId -eq $containsActivity_relclass_id 32 | } 33 | ForEach ($childWI_relobj in $childWIs_relobj) { 34 | if ($childWI_relobj.IsDeleted -ne 'false') { 35 | 36 | $childWI_id = $childWI_relobj.TargetObject.id.guid 37 | $childWI_obj = get-scsmobject -id $childWI_id 38 | #filter for DynamicReviewerActivity 39 | If ($childWI_obj.ClassName -eq 'System.WorkItem.Activity.ReviewActivity' -AND $childWI_obj.Title -match 'DynamicReviewerActivity') { 40 | $childWIs_obj += $childWI_obj 41 | } 42 | } 43 | } 44 | $childWIs_obj 45 | 46 | } 47 | catch { 48 | $PSCmdlet.ThrowTerminatingError($_) 49 | } 50 | } -------------------------------------------------------------------------------- /TOOL-Get-LocalUser/Get-LocalUser.ps1: -------------------------------------------------------------------------------- 1 | function Get-LocalUser { 2 | 3 | <# 4 | .SYNOPSIS 5 | This script can be list all of local user account. 6 | 7 | .DESCRIPTION 8 | This script can be list all of local user account. 9 | The function is using WMI to connect to the remote machine 10 | 11 | .PARAMETER ComputerName 12 | Specifies the computers on which the command . The default is the local computer. 13 | 14 | .PARAMETER Credential 15 | A description of the Credential parameter. 16 | 17 | 18 | .EXAMPLE 19 | Get-LocalUser 20 | 21 | This example shows how to list all of local users on local computer. 22 | 23 | .NOTES 24 | Francois-Xavier Cat 25 | lazywinadmin.com 26 | @lazywinadmin 27 | .LINK 28 | https://github.com/lazywinadmin/PowerShell 29 | #> 30 | 31 | PARAM 32 | ( 33 | [Alias('cn')] 34 | [String[]]$ComputerName = $Env:COMPUTERNAME, 35 | 36 | [String]$AccountName, 37 | 38 | [System.Management.Automation.PsCredential]$Credential 39 | ) 40 | 41 | $Splatting = @{ 42 | Class = "Win32_UserAccount" 43 | Namespace = "root\cimv2" 44 | Filter = "LocalAccount='$True'" 45 | } 46 | 47 | #Credentials 48 | If ($PSBoundParameters['Credential']) { $Splatting.Credential = $Credential } 49 | 50 | Foreach ($Computer in $ComputerName) { 51 | TRY { 52 | Write-Verbose -Message "[PROCESS] ComputerName: $Computer" 53 | Get-WmiObject @Splatting -ComputerName $Computer | Select-Object -Property Name, FullName, Caption, Disabled, Status, Lockout, PasswordChangeable, PasswordExpires, PasswordRequired, SID, SIDType, AccountType, Domain, Description 54 | } 55 | CATCH { 56 | Write-Warning -Message "[PROCESS] Issue connecting to $Computer" 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /SCCM-New-SCCMTSAppVariable/New-SCCMTSAppVariable.ps1: -------------------------------------------------------------------------------- 1 | Function New-SCCMTSAppVariable { 2 | <# 3 | .SYNOPSIS 4 | Function to create a SCCM Task Sequence Application Variable during the OSD 5 | 6 | .DESCRIPTION 7 | Function to create a SCCM Task Sequence Application Variable during the OSD 8 | 9 | .PARAMETER BaseVariableName 10 | Specifies the "Base Variable Name" present in the task "Install Application" of the Task Sequence. 11 | (In the 'Install application according to dynamic variable list' section) 12 | 13 | .PARAMETER ApplicationList 14 | Specifies the list of application to install. 15 | Those must match the SCCM Application name to install 16 | 17 | .EXAMPLE 18 | New-SCCMTSVariable -BaseVariableName "FX" -ApplicationList "Photoshop","AutoCad" 19 | 20 | .EXAMPLE 21 | New-SCCMTSVariable -BaseVariableName "FX" -ApplicationList $Variable 22 | 23 | .NOTES 24 | Francois-Xavier Cat 25 | lazywinadmin.com 26 | @lazywinadmin 27 | .LINK 28 | https://github.com/lazywinadmin/PowerShell 29 | #> 30 | 31 | PARAM ( 32 | [String]$BaseVariableName, 33 | [String[]]$ApplicationList 34 | ) 35 | 36 | BEGIN { 37 | # Create an TaskSequence Environment Object 38 | $TaskSequenceEnvironment = New-Object -COMObject Microsoft.SMS.TSEnvironment 39 | } 40 | PROCESS { 41 | 42 | # Create a Counter 43 | $Counter = 1 44 | 45 | # Foreach Application we create an incremented variable 46 | $ApplicationList | ForEach-Object -Process { 47 | 48 | # Define the Variable Name 49 | $Variable = "$BaseVariableName{0:00}" -f $Counter 50 | 51 | # Create the Task Sequence Variable 52 | $TaskSequenceEnvironment.value("$Variable") = "$_" 53 | 54 | # Increment the counter 55 | [void]$Counter++ 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /SCSM-Set-SCSMMAStatus/SCSM-Set-SCSMMAStatus.ps1: -------------------------------------------------------------------------------- 1 | Function Set-SCSMMAStatus { 2 | <# 3 | .SYNOPSIS 4 | Set the status of a Manual Activity 5 | .DESCRIPTION 6 | Set the status of a Manual Activity 7 | .PARAMETER ManualActivityID 8 | Specify the ID of the Manual Activity 9 | .PARAMETER Status 10 | Specify the status of the Manual activity 11 | 12 | Status possible: 13 | In Progress 14 | Cancelled 15 | Completed 16 | Failed 17 | On Hold 18 | Pending 19 | Rerun 20 | Skipped 21 | .EXAMPLE 22 | Set-SCSMMAStatus -ManualActivityID MA123456 -Status 'Cancelled' 23 | .LINK 24 | https://github.com/lazywinadmin/PowerShell 25 | #> 26 | [CmdletBinding()] 27 | PARAM( 28 | $ManualActivityID, 29 | 30 | $Status = "Completed" 31 | ) 32 | BEGIN { 33 | TRY { 34 | if (-not(Get-Module -Name smlets)) { 35 | # Import the module 36 | Import-Module -Name smlets 37 | } 38 | } 39 | CATCH { 40 | Write-Warning -Message "[BEGIN] Error while loading the smlets" 41 | Write-Warning -Message $Error[0].exception.message 42 | } 43 | } 44 | PROCESS { 45 | TRY { 46 | # Get a specific manual activity 47 | $ManualActivity = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Activity.ManualActivity$) -filter "ID -eq $ManualActivityID" 48 | # Change the status of the Manual Activity 49 | Set-SCSMObject -SMObject $ManualActivity -Property Status -Value $Status 50 | } 51 | CATCH { 52 | Write-Warning -Message "[PROCESS] Something wrong happened" 53 | Write-Warning -Message $Error[0].exception.message 54 | } 55 | } 56 | END { 57 | Write-Verbose -Message "[END] Set-SCSMMAStatus Done!" 58 | } 59 | } -------------------------------------------------------------------------------- /SCSM-Get-SCSMWorkItemRequestOffering/Get-SCSMWorkItemRequestOffering.ps1: -------------------------------------------------------------------------------- 1 | function Get-SCSMWorkItemRequestOffering { 2 | <# 3 | .SYNOPSIS 4 | Function to retrieve the RequestOffering used to create a specific work item. 5 | 6 | .DESCRIPTION 7 | Function to retrieve the RequestOffering used to create a specific work item. 8 | It will output the full object and add the work item Name and GUID to the output 9 | 10 | .EXAMPLE 11 | $SR = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -Filter "ID -eq 'SR55000'" 12 | Get-SCSMWorkItemRequestOffering -SMObject $SR 13 | 14 | .EXAMPLE 15 | Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -Filter "ID -eq 'SR55000'" | Get-SCSMWorkItemRequestOffering 16 | 17 | .EXAMPLE 18 | $SR = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -Filter "ID -eq 'SR55000'" 19 | $IR = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.IncidentRequest$) -Filter "ID -eq 'IR99000'" 20 | Get-SCSMWorkItemRequestOffering -SMObject $SR,IR 21 | 22 | .NOTES 23 | Francois-Xavier Cat 24 | @lazywinadmin 25 | lazywinadmin.com 26 | .LINK 27 | https://github.com/lazywinadmin/PowerShell 28 | 29 | #> 30 | PARAM ( 31 | [Parameter(ValueFromPipeline)] 32 | $SMObject 33 | ) 34 | BEGIN { Import-Module -Name SMLets -ErrorAction Stop } 35 | PROCESS { 36 | foreach ($Item in $SMObject) { 37 | (Get-SCSMRelationshipObject -BySource $Item | Where-Object -FilterScript { $_.RelationshipID -eq "2730587f-3d88-a4e4-42d8-08cf94535a6e" }).TargetObject | 38 | Select-Object -property @{ Label = "WorkItemName"; Expression = { $Item.Name } }, @{ Label = "WorkItemGUID"; Expression = { $Item.get_id() } }, * 39 | 40 | } 41 | }#PROCESS 42 | END { Remove-Module -Name Smlets -ErrorAction SilentlyContinue } 43 | } -------------------------------------------------------------------------------- /TOOL-Remove-StringDiacritic/Remove-StringDiacritic.ps1: -------------------------------------------------------------------------------- 1 | function Remove-StringDiacritic { 2 | <# 3 | .SYNOPSIS 4 | This function will remove the diacritics (accents) characters from a string. 5 | 6 | .DESCRIPTION 7 | This function will remove the diacritics (accents) characters from a string. 8 | 9 | .PARAMETER String 10 | Specifies the String(s) on which the diacritics need to be removed 11 | 12 | .PARAMETER NormalizationForm 13 | Specifies the normalization form to use 14 | https://msdn.microsoft.com/en-us/library/system.text.normalizationform(v=vs.110).aspx 15 | 16 | .EXAMPLE 17 | PS C:\> Remove-StringDiacritic "L'été de Raphaël" 18 | 19 | L'ete de Raphael 20 | 21 | .NOTES 22 | Francois-Xavier Cat 23 | @lazywinadmin 24 | lazywinadmin.com 25 | github.com/lazywinadmin 26 | #> 27 | [CMdletBinding()] 28 | PARAM 29 | ( 30 | [ValidateNotNullOrEmpty()] 31 | [Alias('Text')] 32 | [System.String[]]$String, 33 | [System.Text.NormalizationForm]$NormalizationForm = "FormD" 34 | ) 35 | 36 | FOREACH ($StringValue in $String) { 37 | Write-Verbose -Message "$StringValue" 38 | try { 39 | # Normalize the String 40 | $Normalized = $StringValue.Normalize($NormalizationForm) 41 | $NewString = New-Object -TypeName System.Text.StringBuilder 42 | 43 | # Convert the String to CharArray 44 | $normalized.ToCharArray() | 45 | ForEach-Object -Process { 46 | if ([Globalization.CharUnicodeInfo]::GetUnicodeCategory($psitem) -ne [Globalization.UnicodeCategory]::NonSpacingMark) { 47 | [void]$NewString.Append($psitem) 48 | } 49 | } 50 | 51 | #Combine the new string chars 52 | Write-Output $($NewString -as [string]) 53 | } 54 | Catch { 55 | Write-Error -Message $Error[0].Exception.Message 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /TOOL-Read-ExcelFile/Read-ExcelFile-Example_Using_COM.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | https://lazywinadmin.com/2014/03/powershell-read-excel-file-using-com.html 3 | #> 4 | [cmdletbinding()] 5 | PARAM ( 6 | [Parameter(Mandatory, 7 | HelpMessage = "You must specify the full path of the file")] 8 | [ValidateScript( { Test-Path -Path $_ })] 9 | $Path, 10 | [Parameter(Mandatory, 11 | HelpMessage = "You must specify the SheetName of the Excel file")] 12 | $Sheet) 13 | 14 | #Specify the path of the excel file 15 | $FilePath = $path 16 | 17 | #Specify the Sheet name 18 | $SheetName = $Sheet 19 | 20 | # Create an Object Excel.Application using Com interface 21 | $objExcel = New-Object -ComObject Excel.Application 22 | # Disable the 'visible' property so the document won't open in excel 23 | $objExcel.Visible = $false 24 | # Open the Excel file and save it in $WorkBook 25 | $WorkBook = $objExcel.Workbooks.Open($FilePath) 26 | # Load the WorkSheet 'BuildSpecs' 27 | $WorkSheet = $WorkBook.sheets.item($SheetName) 28 | 29 | [pscustomobject][ordered]@{ 30 | ComputerName = $WorkSheet.Range("C3").Text 31 | Project = $WorkSheet.Range("C4").Text 32 | Ticket = $WorkSheet.Range("C5").Text 33 | Role = $WorkSheet.Range("C8").Text 34 | RoleType = $WorkSheet.Range("C9").Text 35 | Environment = $WorkSheet.Range("C10").Text 36 | Manufacturer = $WorkSheet.Range("C12").Text 37 | SiteCode = $WorkSheet.Range("C15").Text 38 | isDMZ = $WorkSheet.Range("C16").Text 39 | OperatingSystem = $WorkSheet.Range("C18").Text 40 | ServicePack = $WorkSheet.Range("C19").Text 41 | OSKey = $WorkSheet.Range("C20").Text 42 | Owner = $WorkSheet.Range("C22").Text 43 | MaintenanceWindow = $WorkSheet.Range("C23").Text 44 | NbOfProcessor = $WorkSheet.Range("C26").Text 45 | NbOfCores = $WorkSheet.Range("C27").Text 46 | MemoryGB = $WorkSheet.Range("C29").Text 47 | } -------------------------------------------------------------------------------- /EXCHANGE-Connect-ExchangeOnline/Connect-ExchangeOnline.ps1: -------------------------------------------------------------------------------- 1 | function Connect-ExchangeOnline { 2 | <# 3 | .SYNOPSIS 4 | Function to Connect to an Exchange Online 5 | 6 | .DESCRIPTION 7 | Function to Connect to an Exchange Online 8 | 9 | .PARAMETER ConnectionUri 10 | Specifies the Connection Uri to use 11 | Default is https://ps.outlook.com/powershell/ 12 | 13 | .PARAMETER Credential 14 | Specifies the credential to use 15 | 16 | .EXAMPLE 17 | PS C:\> Connect-ExchangeOnline 18 | 19 | .EXAMPLE 20 | PS C:\> Connect-ExchangeOnline -Credential (Get-Credential) 21 | 22 | .NOTES 23 | Francois-Xavier Cat 24 | lazywinadmin.com 25 | @lazywinadmin 26 | .LINK 27 | https://github.com/lazywinadmin/PowerShell 28 | #> 29 | 30 | param 31 | ( 32 | [system.string]$ConnectionUri = 'https://ps.outlook.com/powershell/', 33 | [Parameter(Mandatory)] 34 | [Alias('RunAs')] 35 | [pscredential] 36 | [System.Management.Automation.Credential()] 37 | $Credential 38 | ) 39 | PROCESS { 40 | TRY { 41 | # Make sure the credential username is something like admin@domain.com 42 | if ($Credential.username -notlike '*@*') { 43 | Write-Error 'Must be email format' 44 | break 45 | } 46 | 47 | $Splatting = @{ 48 | ConnectionUri = $ConnectionUri 49 | ConfigurationName = 'microsoft.exchange' 50 | Authentication = 'Basic' 51 | AllowRedirection = $true 52 | } 53 | IF ($PSBoundParameters['Credential']) { $Splatting.Credential = $Credential } 54 | 55 | # Load Exchange cmdlets (Implicit remoting) 56 | Import-PSSession -Session (New-PSSession @Splatting -ErrorAction Stop) -ErrorAction Stop 57 | } 58 | CATCH { 59 | $PSCmdlet.ThrowTerminatingError($_) 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /TOOL-Remove-StringLatinCharacter/Remove-StringLatinCharacter.ps1: -------------------------------------------------------------------------------- 1 | function Remove-StringLatinCharacter { 2 | <# 3 | .SYNOPSIS 4 | Function to remove diacritics from a string 5 | .DESCRIPTION 6 | Function to remove diacritics from a string 7 | .PARAMETER String 8 | Specifies the String that will be processed 9 | .EXAMPLE 10 | Remove-StringLatinCharacter -String "L'été de Raphaël" 11 | 12 | L'ete de Raphael 13 | .EXAMPLE 14 | Foreach ($file in (Get-ChildItem c:\test\*.txt)) 15 | { 16 | # Get the content of the current file and remove the diacritics 17 | $NewContent = Get-content $file | Remove-StringLatinCharacter 18 | 19 | # Overwrite the current file with the new content 20 | $NewContent | Set-Content $file 21 | } 22 | 23 | Remove diacritics from multiple files 24 | 25 | .NOTES 26 | Francois-Xavier Cat 27 | lazywinadmin.com 28 | @lazywinadmin 29 | github.com/lazywinadmin 30 | 31 | BLOG ARTICLE 32 | https://lazywinadmin.com/2015/05/powershell-remove-diacritics-accents.html 33 | 34 | VERSION HISTORY 35 | 1.0.0.0 | Francois-Xavier Cat 36 | Initial version Based on Marcin Krzanowic code 37 | 1.0.0.1 | Francois-Xavier Cat 38 | Added support for ValueFromPipeline 39 | 1.0.0.2 | Francois-Xavier Cat 40 | Add Support for multiple String 41 | Add Error Handling 42 | .LINK 43 | https://github.com/lazywinadmin/PowerShell 44 | #> 45 | [CmdletBinding()] 46 | PARAM ( 47 | [Parameter(ValueFromPipeline = $true)] 48 | [System.String[]]$String 49 | ) 50 | PROCESS { 51 | FOREACH ($StringValue in $String) { 52 | Write-Verbose -Message "$StringValue" 53 | 54 | TRY { 55 | [Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($StringValue)) 56 | } 57 | CATCH { 58 | $PSCmdlet.ThrowTerminatingError($_) 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /AZURE-Get-PolicyComplianceData/Get-PolicyComplianceData.ps1: -------------------------------------------------------------------------------- 1 | 2 | <#PSScriptInfo 3 | 4 | .VERSION 1.0 5 | 6 | .GUID f2d5adaf-ed37-4dcc-96d5-2ac72b770cf8 7 | 8 | .AUTHOR Francois-Xavier Cat 9 | 10 | .COMPANYNAME 11 | 12 | .COPYRIGHT 13 | 14 | .TAGS 15 | 16 | .LICENSEURI 17 | 18 | .PROJECTURI 19 | https://github.com/lazywinadmin/PowerShell 20 | 21 | .ICONURI 22 | 23 | .EXTERNALMODULEDEPENDENCIES 24 | 25 | .REQUIREDSCRIPTS 26 | 27 | .EXTERNALSCRIPTDEPENDENCIES 28 | 29 | .RELEASENOTES 30 | 31 | .PRIVATEDATA 32 | 33 | #> 34 | 35 | <# 36 | .SYNOPSIS 37 | Retrieve Azure Policy Compliance Data for a specific Assignment under a specific ManagementGroupName 38 | .DESCRIPTION 39 | Retrieve Azure Policy Compliance Data for a specific Assignment under a specific ManagementGroupName 40 | This will also retrieve the subscription name 41 | 42 | This script assume you are already connected and authenticated to Azure. 43 | 44 | .PARAMETER ManagementGroupName 45 | Specify the ManagementGroupName 46 | 47 | .PARAMETER AssignmentID 48 | Specify the AssignmentID 49 | 50 | .EXAMPLE 51 | Get-PolicyComplianceData.ps1 -ManagementGroupName -AssignmentID 52 | 53 | .LINK 54 | https://github.com/lazywinadmin/PowerShell 55 | 56 | #> 57 | [CmdletBinding()] 58 | Param( 59 | $ManagementGroupName, 60 | $AssignmentID 61 | ) 62 | try{ 63 | # Retrieve the Compliance data 64 | $State = Get-AzPolicyState -ManagementGroupName $ManagementGroupName -Filter "(AssignmentID eq $AssignmentID)" 65 | 66 | $SubscriptionNames = $State | Group-Object -Property SubscriptionId | ForEach-Object -Process { 67 | Get-AzSubscription -SubscriptionId $_.Name 68 | } 69 | 70 | $State | Select-Object -Property *,@{ 71 | Label='SubscriptionName'; 72 | Expression=@{ 73 | #keep current state in var 74 | $CurrentState=$_ 75 | # retrieve sub name 76 | ($SubscriptionNames | Where-Object -Filter {$_.id -eq $currentState.subscriptionid}).name 77 | } 78 | } 79 | }catch{ 80 | throw $_ 81 | } -------------------------------------------------------------------------------- /SCSM-Get-SCSMUserManager/Get-SCSMUserManager.ps1: -------------------------------------------------------------------------------- 1 | Function Get-SCSMUserManager { 2 | <# 3 | .SYNOPSIS 4 | Function to retrieve the manager of a user 5 | .DESCRIPTION 6 | Function to retrieve the manager of a user 7 | .PARAMETER UserID 8 | Specify the User ID 9 | .EXAMPLE 10 | Get-SCSMUserManager -UserID $UserID 11 | .LINK 12 | https://github.com/lazywinadmin/PowerShell 13 | #> 14 | [CmdletBinding()] 15 | Param ( 16 | [Alias('input_affectedUser_id')] 17 | [String]$UserID 18 | ) 19 | try { 20 | ## Return Variables 21 | $managerOfAffectedUser_obj = $null 22 | 23 | ## MAIN 24 | $affectedUser_obj = get-scsmobject -id $UserID 25 | $userManagesUser_relclass_id = '4a807c65-6a1f-15b2-bdf3-e967e58c254a' 26 | $managerOfAffectedUser_relobjs = Get-SCSMRelationshipObject -ByTarget $affectedUser_obj | 27 | Where-Object -FilterScript { 28 | $_.relationshipId -eq $userManagesUser_relclass_id 29 | } 30 | 31 | ## Check if Manager User Exists and that the relationship is current. 32 | ## get-scsmrelationshipobject tends to keep track of relationship history. It returns old and new 33 | ## relationships 34 | 35 | If ($null -ne $managerOfAffectedUser_relobjs) { 36 | ForEach ($managerOfAffectedUser_relobj in $managerOfAffectedUser_relobjs) { 37 | If ($managerOfAffectedUser_relobj.IsDeleted -eq $True) { 38 | #The relationship no longer exists. Returning nothing 39 | # which will effectively keep the managerOfAffectedUser_obj the same as before. 40 | } 41 | Else { 42 | #The relationship exists, setting managerOfAffectedUser_relExists to true. 43 | get-scsmobject -id ($managerofaffecteduser_relobj.SourceObject.Id.Guid) 44 | } 45 | } 46 | } 47 | } 48 | catch { 49 | $PSCmdlet.ThrowTerminatingError($_) 50 | } 51 | } -------------------------------------------------------------------------------- /SCSM-Get-SCSMIRComment/Get-SCSMIRComment.ps1: -------------------------------------------------------------------------------- 1 | function Get-SCSMIRComment { 2 | <# 3 | .SYNOPSIS 4 | Function to retrieve all the comment of a Incident Request 5 | 6 | .DESCRIPTION 7 | Function to retrieve all the comment of a Incident Request 8 | 9 | .PARAMETER Incident 10 | Specifies the Incident Request Object. 11 | 12 | .EXAMPLE 13 | PS C:\> Get-SCSMIRComment -Incident (get-scsmincident -ID 'IR55444') 14 | 15 | .NOTES 16 | Francois-Xavier Cat 17 | lazywinadmin.com 18 | @lazywinadmin 19 | .LINK 20 | https://github.com/lazywinadmin/PowerShell 21 | #> 22 | [CmdletBinding()] 23 | PARAM 24 | ( 25 | #[System.WorkItem.Incident[]] 26 | [object[]]$Incident 27 | ) 28 | PROCESS { 29 | FOREACH ($IR in $Incident) { 30 | TRY { 31 | # Retrieve Comments 32 | $FilteredIncidents = $IR.AppliesToTroubleTicket | Where-Object -FilterScript { 33 | $_.ClassName -eq "System.WorkItem.TroubleTicket.UserCommentLog" -OR $_.ClassName -eq "System.WorkItem.TroubleTicket.AnalystCommentLog" 34 | } 35 | 36 | IF ($FilteredIncidents.count -gt 0) { 37 | FOREACH ($Comment in $FilteredIncidents) { 38 | $Properties = @{ 39 | IncidentID = $IR.ID 40 | EnteredDate = $Comment.EnteredDate 41 | EnteredBy = $Comment.EnteredBy 42 | Comment = $Comment.Comment 43 | ClassName = $Comment.ClassName 44 | IsPrivate = $Comment.IsPrivate 45 | } 46 | 47 | New-Object -TypeName PSObject -Property $Properties 48 | } # FOREACH 49 | } #IF Incident found 50 | } 51 | CATCH { 52 | $PSCmdlet.ThrowTerminatingError($_) 53 | } 54 | } #FOREACH ($IR in $Incident) 55 | } #Process 56 | } #Function -------------------------------------------------------------------------------- /SAPIEN-PowerShellStudio-themes/EditorPresets/LazyWinAdmin-Dark Theme.preset: -------------------------------------------------------------------------------- 1 | 2 |