├── .vscode └── launch.json ├── ActiveDirectory ├── ADGroupMemberExport.ps1 ├── BulkCreateComputers.ps1 ├── Create-PasswordSettingsObject.ps1 ├── Disable-ADComputer.ps1 ├── Disable-ADComputer │ ├── Disable-ADComputer.Tests.ps1 │ └── Disable-ADComputer.ps1 ├── Disable-ADUser.ps1 ├── DisableADComputerFunction.ps1 ├── EnableADUser.ps1 ├── Examples.ps1 ├── Filters.ps1 ├── Find-AllOperatingSysems.ps1 ├── Get-ADGroupExamples.ps1 ├── Get-ADNestedGroup.ps1 ├── Get-AllLinkedGPOs.ps1 ├── Get-LinkedGPOs.ps1 ├── Get-MultiDomainADUser.ps1 ├── Get-UserWithNoEmail.ps1 ├── Invoke-ADMTUserMigration.ps1 ├── Invoke-IntraADMTUserMigration.ps1 ├── LearnActiveDirectoryMOL │ ├── Chapter01 │ │ └── ReadMeChapter01.txt │ ├── Chapter02 │ │ ├── CodeListing02.txt │ │ ├── LABchapter02.doc │ │ ├── LABnames.csv │ │ ├── TryItNewUser.ps1 │ │ ├── labnewbulkuser.ps1 │ │ ├── names.csv │ │ └── newbulkuser.ps1 │ ├── Chapter03 │ │ ├── CodeListing03.txt │ │ ├── LABchapter03.doc │ │ ├── bulkuserchange.ps1 │ │ ├── officechange.csv │ │ └── renameuser.ps1 │ ├── Chapter04 │ │ ├── CodeListing04.txt │ │ ├── LABchapter04.doc │ │ ├── Solving the 5000 user limit in Get-ADGroupMember.docx │ │ ├── bulkgroupcreate.ps1 │ │ ├── changegroupscope.ps1 │ │ ├── chapter4_computersingroups.ps1 │ │ └── groups.csv │ ├── Chapter05 │ │ ├── CodeListing05.txt │ │ ├── Domain_lockout_policy.tif │ │ └── LABchapter05.doc │ ├── Chapter06 │ │ ├── CodeListing06.txt │ │ ├── LABchapter06.doc │ │ ├── bullkcreatecomputers.ps1 │ │ ├── bullkdeletecomputers.ps1 │ │ ├── computers.txt │ │ └── computersTodelete.txt │ ├── Chapter07 │ │ ├── CodeListing07.txt │ │ ├── LABchapter07.doc │ │ ├── bullkcreateous.ps1 │ │ └── ous.txt │ ├── Chapter08 │ │ ├── CodeListing08.txt │ │ └── LABchapter08.doc │ ├── Chapter09 │ │ ├── CodeListing09.txt │ │ ├── LABchapter09.doc │ │ └── Listing9.1.ps1 │ ├── Chapter10 │ │ ├── CodeListing10.txt │ │ └── LABchapter10.doc │ ├── Chapter11 │ │ ├── CodeListing11.txt │ │ └── LABchapter11.doc │ ├── Chapter12 │ │ ├── CodeListing12.txt │ │ ├── LABchapter12.doc │ │ ├── move-afsmo.ps1 │ │ ├── new-globalcatalog.ps1 │ │ └── remove-globalcatalog.ps1 │ ├── Chapter13 │ │ ├── CodeListing13.txt │ │ ├── LABchapter13.doc │ │ ├── restore-fromrecyclebin.ps1 │ │ └── snapshot.txt │ ├── Chapter14 │ │ ├── CodeListing14.txt │ │ └── LABchapter14.doc │ ├── Chapter15(DNS) │ │ ├── CodeListing15.txt │ │ └── LABchapter15.doc │ ├── Chapter16 │ │ ├── ADtopology.pdf │ │ ├── ADtopology.vsdx │ │ ├── CodeListing16.txt │ │ ├── LABchapter16.doc │ │ ├── Missing subnets.doc │ │ ├── get-site.ps1 │ │ ├── get-sitelink.ps1 │ │ ├── get-subnet.ps1 │ │ ├── new-site.ps1 │ │ ├── new-sitelink.ps1 │ │ ├── new-subnet.ps1 │ │ └── set-schedule.ps1 │ ├── Chapter17 │ │ ├── CodeListing17.txt │ │ ├── LABchapter17.doc │ │ └── test-replication.ps1 │ ├── Chapter18 │ │ └── ReadMeChapter18.txt │ ├── Chapter19 │ │ ├── CodeListing19.txt │ │ ├── LABchapter19.doc │ │ ├── Listing19.1.ps1 │ │ ├── Test-DC.ps1 │ │ ├── Test-UserLogonCapability.ps1 │ │ └── set-logonhours.ps1 │ ├── Chapter20 │ │ ├── CodeListing20.txt │ │ ├── LABchapter20.doc │ │ ├── Listing20.1.ps1 │ │ ├── Listing20.2.ps1 │ │ ├── Listing20.3.ps1 │ │ ├── Listing20.4.ps1 │ │ ├── Listing20.5.ps1 │ │ ├── Listing20.6.ps1 │ │ ├── Listing20.7.ps1 │ │ ├── Listing20.8.ps1 │ │ └── Listing20.9.ps1 │ ├── Chapter21 │ │ ├── CodeListing21.txt │ │ ├── LABchapter21.doc │ │ └── users.csv │ └── Chapter22 │ │ └── CodeListing22.txt ├── MVAPSAD │ ├── 01 - Introduction │ │ ├── PowerShell Cmd Line Conversion Guide AD.pdf │ │ ├── _1_0_INTRODUCTION.ps1 │ │ ├── _1_1_Version History.ps1 │ │ ├── _1_2_Getting Started.ps1 │ │ ├── _1_3_ADAC History.ps1 │ │ └── _1_4_One-Liners.ps1 │ ├── 02 - User and Groups │ │ ├── _2_0_USERS AND GROUPS.ps1 │ │ ├── _2_1_Creating.ps1 │ │ ├── _2_2_Updating.ps1 │ │ ├── _2_2_Updating_GroupsCrossDomain.ps1 │ │ ├── _2_3_Deleting.ps1 │ │ └── newusers.csv │ ├── 03 - Queries │ │ ├── _3_0_QUERIES.ps1 │ │ ├── _3_1_LDAP Basics.ps1 │ │ ├── _3_2_Query Parameters.ps1 │ │ └── _3_3_Filters.ps1 │ ├── 04 - Forensics │ │ ├── _4_0_FORENSICS.ps1 │ │ ├── _4_1_Metadata.ps1 │ │ ├── _4_2_Event Logs.ps1 │ │ ├── _4_3_Lockouts.ps1 │ │ └── _4_4_Permissions.ps1 │ ├── 05 - Stale Objects │ │ ├── _5_0_STALE OBJECTS.ps1 │ │ ├── _5_1_Dates.ps1 │ │ ├── _5_2_Users.ps1 │ │ ├── _5_3_Computers.ps1 │ │ ├── _5_4_Groups.ps1 │ │ └── _5_5_Exceptions.ps1 │ ├── 06 - Replication │ │ ├── ADSiteLinks.csv │ │ ├── ADSites.csv │ │ ├── ADSubnets.csv │ │ ├── _6_0_REPLICATION.ps1 │ │ ├── _6_1_Topology.ps1 │ │ └── _6_2_Troubleshooting.ps1 │ ├── 07 - Recovery │ │ ├── AD Snapshots │ │ │ ├── AD_Snapshot_Functions.ps1 │ │ │ └── demo.ps1 │ │ ├── _7_0_RECOVERY.ps1 │ │ ├── _7_1_Protect from accidental deletion.ps1 │ │ ├── _7_2_Recycle Bin.ps1 │ │ └── _7_3_Attribute Recovery.ps1 │ ├── 08 - Deployment │ │ ├── _8_0_DEPLOYMENT.ps1 │ │ ├── _8_1_DCPROMO.ps1 │ │ ├── _8_2_ADDSDeployment Module.ps1 │ │ ├── _8_3_DC Cloning.ps1 │ │ └── _8_4_Desired State Configuration.ps1 │ ├── DISCLAIMER.ps1 │ └── README.md ├── Migrate-ADMTUser.ps1 ├── Migrate-ADMTUserCLI.ps1 ├── Migrate-ADMTUserSplat.ps1 ├── Move-ADGroupMemberofToMember.ps1 ├── Move-GPO.ps1 ├── Remove-AccidentalDeletion.ps1 ├── Search-ADGroups.ps1 ├── SearchGroupACLs.ps1 ├── Set-GPOStatus.ps1 └── new-globalcatalog.ps1 ├── Classes ├── File.ps1 ├── Group.ps1 ├── Helper.ps1 ├── SQLString.ps1 ├── ScheduledTask.ps1 ├── ScheduledTaskv2.ps1 ├── ScheduledTaskv3.ps1 └── WineClass.ps1 ├── DSC ├── CertificateAuthority.ps1 ├── CredentialEncryptExample.ps1 ├── DSCBookCodeSnippets │ ├── LCMConfig.ps1 │ ├── LCM_Pull │ │ └── Pull.meta.mof │ ├── ParisTZ.ps1 │ └── WebServer.ps1 ├── DSCLabUp.ps1 ├── Demo_WindowServer2012R2 │ ├── DomainController │ │ ├── Assert-DC.ps1 │ │ ├── Assert-DCVM.ps1 │ │ └── Assert-Network.ps1 │ ├── PreReq │ │ ├── BakeryWebsite │ │ │ ├── About.cshtml │ │ │ ├── App_Data │ │ │ │ ├── bakery.sdf │ │ │ │ └── packages │ │ │ │ │ └── microsoft-web-helpers.1.0 │ │ │ │ │ └── microsoft-web-helpers.1.0.nupkg │ │ │ ├── Default.cshtml │ │ │ ├── Images │ │ │ │ ├── Products │ │ │ │ │ ├── Thumbnails │ │ │ │ │ │ ├── bread.jpg │ │ │ │ │ │ ├── carrot_cake.jpg │ │ │ │ │ │ ├── chocolate_cake.jpg │ │ │ │ │ │ ├── cupcakes.jpg │ │ │ │ │ │ ├── lemon_tart.jpg │ │ │ │ │ │ └── pear_tart.jpg │ │ │ │ │ ├── bread.jpg │ │ │ │ │ ├── carrot_cake.jpg │ │ │ │ │ ├── chocolate_cake.jpg │ │ │ │ │ ├── cupcakes.jpg │ │ │ │ │ ├── lemon_tart.jpg │ │ │ │ │ └── pear_tart.jpg │ │ │ │ ├── Thumbs.db │ │ │ │ ├── bkg.png │ │ │ │ └── brand.png │ │ │ ├── Order.cshtml │ │ │ ├── OrderSuccess.cshtml │ │ │ ├── Styles │ │ │ │ └── Site.css │ │ │ ├── Website │ │ │ │ └── Images │ │ │ │ │ └── Thumbs.db │ │ │ ├── _PageStart.cshtml │ │ │ ├── _SiteLayout.cshtml │ │ │ ├── bin │ │ │ │ ├── Microsoft.Web.Helpers.dll │ │ │ │ ├── Microsoft.Web.Infrastructure.dll │ │ │ │ ├── System.Web.Razor.dll │ │ │ │ ├── System.Web.WebPages.Deployment.dll │ │ │ │ ├── System.Web.WebPages.Razor.dll │ │ │ │ └── System.Web.WebPages.dll │ │ │ ├── favicon.ico │ │ │ └── robots.txt │ │ ├── Get-VMIP │ │ │ └── Get-VMIP.psm1 │ │ ├── Resources │ │ │ ├── Demo_Computer │ │ │ │ ├── Demo_Computer.psd1 │ │ │ │ ├── Demo_Computer.psm1 │ │ │ │ └── Demo_Computer.schema.mof │ │ │ ├── Demo_DCPromo │ │ │ │ ├── Demo_DCPromo.psd1 │ │ │ │ ├── Demo_DCPromo.psm1 │ │ │ │ └── Demo_DCPromo.schema.mof │ │ │ ├── Demo_DHCPOption │ │ │ │ ├── Demo_DHCPOption.psd1 │ │ │ │ ├── Demo_DHCPOption.psm1 │ │ │ │ └── Demo_DHCPOption.schema.mof │ │ │ ├── Demo_DHCPScope │ │ │ │ ├── Demo_DHCPScope.psd1 │ │ │ │ ├── Demo_DHCPScope.psm1 │ │ │ │ └── Demo_DHCPScope.schema.mof │ │ │ ├── Demo_DHCPServerInDC │ │ │ │ ├── Demo_DHCPServerInDC.psd1 │ │ │ │ ├── Demo_DHCPServerInDC.psm1 │ │ │ │ └── Demo_DHCPServerInDC.schema.mof │ │ │ ├── Demo_IISWebsite │ │ │ │ ├── Demo_IISWebsite.psd1 │ │ │ │ ├── Demo_IISWebsite.psm1 │ │ │ │ └── Demo_IISWebsite.schema.mof │ │ │ ├── Demo_IPAddress │ │ │ │ ├── Demo_IPAddress.psd1 │ │ │ │ ├── Demo_IPAddress.psm1 │ │ │ │ └── Demo_IPAddress.schema.mof │ │ │ ├── Demo_OptionalFeature │ │ │ │ ├── Demo_OptionalFeature.psd1 │ │ │ │ ├── Demo_OptionalFeature.psm1 │ │ │ │ └── Demo_OptionalFeature.schema.mof │ │ │ ├── Demo_VHD │ │ │ │ ├── Demo_VHD.psd1 │ │ │ │ ├── Demo_VHD.psm1 │ │ │ │ └── Demo_VHD.schema.mof │ │ │ ├── Demo_VM │ │ │ │ ├── Demo_VM.psd1 │ │ │ │ ├── Demo_VM.psm1 │ │ │ │ └── Demo_VM.schema.mof │ │ │ └── Demo_VMSwitch │ │ │ │ ├── Demo_VMSwitch.psd1 │ │ │ │ ├── Demo_VMSwitch.psm1 │ │ │ │ └── Demo_VMSwitch.schema.mof │ │ └── WebVM │ │ │ └── WebVM.psm1 │ ├── PullServer │ │ ├── Assert-WebVM.ps1 │ │ ├── Content │ │ │ ├── Configuration │ │ │ │ ├── 8cac052d-d3d4-423e-b088-f93979094d11.mof │ │ │ │ ├── 8cac052d-d3d4-423e-b088-f93979094d11.mof.checksum │ │ │ │ ├── e349d5e6-337b-48e6-b381-6dcc4d707750.mof │ │ │ │ └── e349d5e6-337b-48e6-b381-6dcc4d707750.mof.checksum │ │ │ └── Modules │ │ │ │ ├── Demo_Computer.zip │ │ │ │ ├── Demo_Computer.zip.checksum │ │ │ │ ├── Demo_DCPromo.zip │ │ │ │ ├── Demo_DCPromo.zip.checksum │ │ │ │ ├── Demo_DHCPOption.zip │ │ │ │ ├── Demo_DHCPOption.zip.checksum │ │ │ │ ├── Demo_DHCPScope.zip │ │ │ │ ├── Demo_DHCPScope.zip.checksum │ │ │ │ ├── Demo_DHCPServerInDC.zip │ │ │ │ ├── Demo_DHCPServerInDC.zip.checksum │ │ │ │ ├── Demo_IISWebsite.zip │ │ │ │ ├── Demo_IISWebsite.zip.checksum │ │ │ │ ├── Demo_IPAddress.zip │ │ │ │ └── Demo_IPAddress.zip.checksum │ │ ├── Invoke-PullonNode.ps1 │ │ └── Setup │ │ │ ├── Assert-PullServerVM.ps1 │ │ │ └── Scripts │ │ │ ├── InstallPullServerConfig.ps1 │ │ │ └── PSWSIISEndpoint.psm1 │ ├── ReadMe.txt │ ├── Website │ │ ├── Assert-WebVM.ps1 │ │ ├── Assert-Website1.ps1 │ │ └── Assert-Website2.ps1 │ └── WebsiteWithVM │ │ └── Assert-Website.ps1 ├── GenPullServerCert.ps1 ├── HTTPSPull.ps1 ├── Helper-Functions │ ├── Copy-ItemResources.ps1 │ ├── Export-MachineCert.ps1 │ ├── Export-Resources.ps1 │ ├── New-DSCCompositeResource.ps1 │ └── Publish-DSCResourcePull.ps1 ├── LCM v1 HTTPS Example.ps1 ├── LCM v2 HTTPS Example.ps1 ├── NewDomain.ps1 └── PullServerv2.ps1 ├── DotNet └── Get_CurrentDomain.ps1 ├── FileSystems ├── Examples.ps1 ├── Get-Icon.ps1 ├── Get-MSIinfo.ps1 └── UnblockFiles.ps1 ├── Formatting-Output └── Examples.ps1 ├── Hyper-V ├── Clone-VM.ps1 ├── DSCLab-LCMconfig.ps1 ├── DSCLab.ps1 ├── DSCLabHFile01Config.ps1 ├── DSCLabSecondDomain.ps1 ├── DSCLabSetup.ps1 ├── Enable-NestedVm.ps1 ├── GW01Config.ps1 ├── HydraLCMconfig.ps1 ├── Hyper-v_Nat.ps1 ├── LabSetup.ps1 ├── LabUp-Master.ps1 ├── New-VM.ps1 ├── Set-NetworkSettings.ps1 ├── Set-VMNetworkAdapter.ps1 └── VyOSConfig.ps1 ├── MISC ├── Automate_The_World.ps1 ├── Automate_The_WorldProd.ps1 ├── PowerShell-Pocket-Book.ps1 ├── Profile.ps1 ├── RenameResetLocalAdmin.ps1 └── Test-RemoteSessionSettings.ps1 ├── Modules └── SQLcmdlets.psm1 ├── Networking └── Set-NetAdapterPrivate ├── PSRemoting ├── Examples.ps1 ├── Invoke-32bitPS.ps1 └── Test-PSSession.ps1 ├── Presentations ├── NPS │ └── NPSdemo.ps1 └── PowerShellandSQL │ ├── Demo.ps1 │ ├── PluralSightDemo.ps1 │ └── PreDemo.ps1 ├── README.md ├── SCCM ├── ApplicationAutomation │ ├── Create-ConfigMgrApplication.ps1 │ ├── Initialize-CMApplicationAutomation.ps1 │ ├── NewCMPackageFunction.ps1 │ ├── PADT-Template.ps1 │ └── Write-PADT.ps1 ├── ConfigMgrTools │ ├── Add-DriverContentToDriverPackage.ps1 │ ├── CreateADGroupSCCMCollection.ps1 │ ├── CreateCatalogCategories.ps1 │ ├── CreateOUCollections.ps1 │ ├── Enter-CMSession.ps1 │ ├── Import-Drivers.ps1 │ ├── Migrate-CMApplication.ps1 │ ├── New-CMApplication.ps1 │ ├── OneLiners.ps1 │ ├── Remove-AllCMDriverCatagories.ps1 │ ├── SCCMCleanup.ps1 │ ├── Set-CCMCacheSize.ps1 │ └── Update-0KBDriverPacks.ps1 ├── DetectionMethods │ ├── CCMCacheSize.ps1 │ ├── CitrixReceiver14.1.200.13.ps1 │ ├── Registry.ps1 │ ├── SAPNetWeaverBusinessClient3.5P14.ps1 │ └── WindowsUpdateAgentVersion.ps1 ├── Modules │ └── ConfigMgrApplicationAutomation.psm1 ├── OSD-Tools │ ├── Get-CABfiles.ps1 │ └── Get-DellCAB.ps1 ├── PackageAutomation │ ├── CreateCMPackage.csv │ └── CreateCMPackage.ps1 └── README.md ├── SQL ├── Copy-SQLTable.ps1 ├── SMO.ps1 └── SMO_Article_Code.ps1 ├── Snippets └── Create-Snippets.ps1 ├── Tips-Tricks ├── Advanced_Function_Template.ps1 ├── Append-Begin&END.ps1 ├── Convert-FirstCharToUpper.ps1 ├── Examples.ps1 ├── HashTables.ps1 └── debug.ps1 ├── Utilities ├── Convert-PullServerModules.ps1 ├── ConvertTo-DSCPullArchive.ps1 ├── Create-PullServerModule.ps1 ├── Get-MachineCert.ps1 ├── Get-MediaFileDuration.ps1 ├── New-ISOFile.ps1 └── New-ZipArchive.ps1 ├── WMI ├── Examples.ps1 └── Get-OSVersion.ps1 ├── profile.ps1 └── test.ps1 /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [] 4 | } -------------------------------------------------------------------------------- /ActiveDirectory/ADGroupMemberExport.ps1: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------- 2 | # Version: 1.0 3 | # Author: Joshua Duffney, Robert Merriman 4 | # Date: 07/16/2014 5 | # Description: Using PowerShell to get all AD users of a group and exports to .txt file. 6 | # Comments: Change ADgroup to a portion of the name of the group you're looking for. 7 | # --------------------------------------------------- 8 | 9 | 10 | Get-ADGroup -filter 'Name -like"*ADgroup*"' | 11 | foreach{ 12 | $AD=$_.Name 13 | $AD 14 | $AD|Out-File -append c:\scripts\membersofadgroup.txt 15 | $AD |Get-ADGroupMember|FT Name|Out-File -append c:\scripts\membersofadgroup.txt 16 | } 17 | -------------------------------------------------------------------------------- /ActiveDirectory/BulkCreateComputers.ps1: -------------------------------------------------------------------------------- 1 | ##Source Learn Active Directory in a Month of Lunches 2 | Import-Csv -Path C:\Scripts\ADLunches\computers.txt | 3 | foreach { 4 | New-ADComputer -Enabled $true -Name $_.Name ` 5 | -Path:"CN=Computers,DC=Manticore,DC=org" ` 6 | -SamAccountName $_.Name ` 7 | -Description $_.Description -PassThru 8 | } 9 | 10 | ##Remove comments and place into a .csv file 11 | #Name,Description 12 | #ADLComp1, "Test Machine for AD Lunches" 13 | #ADLComp2, "Test Machine for AD Lunches" 14 | #ADLComp3, "Test Machine for AD Lunches" 15 | -------------------------------------------------------------------------------- /ActiveDirectory/Create-PasswordSettingsObject.ps1: -------------------------------------------------------------------------------- 1 | New-ADFineGrainedPasswordPolicy -Name ADMLpso2 -Precedence 200 ` 2 | -MinPasswordLength 12 -MaxPasswordAge "21" -MinPasswordAge "2" ` 3 | -PasswordHistoryCount 50 -ComplexityEnabled:$true ` 4 | -Description "ADML policy 2" -LockoutDuration "4:00" ` 5 | -LockoutObservationWindow "4:00" -LockoutThreshold 3 ` 6 | -ReversibleEncryptionEnabled:$false -------------------------------------------------------------------------------- /ActiveDirectory/Disable-ADComputer/Disable-ADComputer.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") 3 | . "$here\$sut" 4 | 5 | Describe "Disable-ADComputer" { 6 | It "does something useful" { 7 | $true | Should Be $false 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ActiveDirectory/DisableADComputerFunction.ps1: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------- 2 | # Version: 2.0 3 | # Author: Joshua Duffney 4 | # Date: 05/11/2014 5 | # Description: Read a text file with a list of computer names and then disables them. 6 | # Comments: Refer to ApplicationCreation.csv in the repo to complete the script. 7 | # --------------------------------------------------- 8 | 9 | Function DisableADComputer { 10 | 11 | Param( 12 | [string]$File 13 | ) 14 | 15 | Import-Module activedirectory 16 | 17 | ForEach ($Computer in (Get-Content $File)){ 18 | Set-ADComputer -Identity $Computer -Enabled $false 19 | Write-host "$Computer has been disabled" 20 | } 21 | 22 | } 23 | 24 | DisableADComputer -File "C:\Scripts\DisableComputerList.txt" 25 | -------------------------------------------------------------------------------- /ActiveDirectory/EnableADUser.ps1: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------- 2 | # Version: 1.0 3 | # Author: Joshua Duffney 4 | # Date: 07/16/2014 5 | # Description: Using PowerShell to enable mass amount of users accounts & sets account expiration. 6 | # Comments: Populate the enableuser.txt with the names of disabled users accounts. 7 | # --------------------------------------------------- 8 | 9 | 10 | Import-Module activedirectory 11 | $File = "C:\scripts\enableusers.txt" 12 | 13 | ForEach ($User in (Get-Content $File)) 14 | { Enable-ADAccount -Identity $User ; Set-ADAccountExpiration -Identity $User 12/31/2014 15 | } 16 | -------------------------------------------------------------------------------- /ActiveDirectory/Examples.ps1: -------------------------------------------------------------------------------- 1 | Get-ADuser –filter * -properties * | ft name,department 2 | 3 | Get-ADUser –Filter * -Properties * | sort –Property Department | ft Name,Department 4 | 5 | Get-ADUser –filter {Department –eq “Sales” –or Department –eq “Marketing”} –Properties * | ft –Property Surname,Department,PasswordLastSet 6 | 7 | Get-ADComputer –filter * | % {Get-hotfix –computername $PSItem.Name} 8 | 9 | Get-ADComputer –filter * | % {Invoke-command $PSitem.Name –scriptblock { get-hotfix}} 10 | 11 | Get-ADGroupMember -Identity 'domain controllers' | % {Get-ADComputer $PSItem.Name -Properties OperatingSystem} | select Name,OperatingSystem 12 | #Add Computers to groups in PowerShell 13 | Set-ADGroup -Add:@{'Member'="CN=WEFS1,CN=Computers,DC=WEF,DC=COM"} -Identity:"CN=Event Log Readers,CN=Builtin,DC=WEF,DC=COM" -Server:"WEFDC.WEF.COM" 14 | help about_active* 15 | -------------------------------------------------------------------------------- /ActiveDirectory/Filters.ps1: -------------------------------------------------------------------------------- 1 | Get-ADUser -Filter 'memberOf -RecursiveMatch "CN=Domain Admins,CN=groups,DC=dc,DC=domain,DC=com"' 2 | 3 | trap {return "error"} 4 | If ( 5 | Get-ADUser ` 6 | -Filter "memberOf -RecursiveMatch '$((Get-ADGroup "Domain Admins").DistinguishedName)'" ` 7 | -SearchBase $((Get-ADUser $user).DistinguishedName) 8 | ) {$true} 9 | Else {$false} 10 | -------------------------------------------------------------------------------- /ActiveDirectory/Find-AllOperatingSysems.ps1: -------------------------------------------------------------------------------- 1 | Get-ADComputer -Filter * -Properties * | select OperatingSystem -Unique 2 | -------------------------------------------------------------------------------- /ActiveDirectory/Get-ADGroupExamples.ps1: -------------------------------------------------------------------------------- 1 | (Get-ADGroup -Filter {GroupScope -eq "Global"} | Where-Object Name -NotMatch "Administrators").Name 2 | -------------------------------------------------------------------------------- /ActiveDirectory/Get-ADNestedGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-ADNestedGroup ($Group) { 2 | $Members = (Get-ADGroupMember -Identity $Group).samAccountName 3 | 4 | foreach ($Member in $Members){ 5 | try { 6 | Get-ADGroup -Identity $Member 7 | 8 | if (Get-ADGroup -Identity $Member) { 9 | Get-ADNestedGroup -Group $Member 10 | } 11 | 12 | 13 | } 14 | Catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { 15 | Write-Warning -Message "$Member is not a group" 16 | } 17 | } 18 | } 19 | 20 | Get-ADNestedGroup -group 'DevOpsTeam' -------------------------------------------------------------------------------- /ActiveDirectory/Get-AllLinkedGPOs.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Listing 9.1 from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 09 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | 11 | $gpolinks = Get-ADOrganizationalUnit -Filter * | #1 12 | where LinkedGroupPolicyObjects | #2 13 | foreach { 14 | $ou = $_.DistinguishedName 15 | $_.LinkedGroupPolicyObjects | #3 16 | foreach { 17 | $x = $_.ToUpper() -split ",", 2 18 | $id = $x[0].Replace("CN={","").Replace("}","") 19 | $props = [ordered]@{ 20 | OU = $ou 21 | GPO = Get-GPO -Guid $id | select -ExpandProperty DisplayName #4 22 | } 23 | New-Object -TypeName PSObject -Property $props 24 | } 25 | } 26 | $gpolinks | sort OU | Format-Table OU, GPO -AutoSize 27 | $gpolinks | sort GPO | Format-Table GPO, OU -AutoSize 28 | -------------------------------------------------------------------------------- /ActiveDirectory/Get-LinkedGPOs.ps1: -------------------------------------------------------------------------------- 1 | $gpos = Get-GPInheritance -Target "OU=ADMLUsers,DC=manticore,DC=org" 2 | $linked = $gpos.GpoLinks | select -ExpandProperty DisplayName 3 | $gpos | select -ExpandProperty GpoLinks 4 | $gpos | select -ExpandProperty InheritedGpoLinks |where DisplayName -NotIn $linked -------------------------------------------------------------------------------- /ActiveDirectory/Get-MultiDomainADUser.ps1: -------------------------------------------------------------------------------- 1 | function Get-MDADUser { 2 | <# 3 | .SYNOPSIS 4 | Gets Active Directory user information from all trusted domains. 5 | .DESCRIPTION 6 | Gathers all trusted domains from within a forest and then queries each domain for 7 | the user account specified. 8 | .PARAMETER Identity 9 | Specifies an Active Directory user object by providing one of the following property values. 10 | -- A Distinguished Name 11 | -- A GUID (objectGUID) 12 | -- A Security Identifier (objectSid) 13 | -- A SAM Account Name (sAMAccountName) 14 | .PARAMETER Properties 15 | Specifies the properties of the output object to retrieve from the server. Use this parameter to retrieve properties that are not included in the default set. 16 | 17 | Specify properties for this parameter as a comma-separated list of names. To display all of the attributes that are set on the object, specify * (asterisk). 18 | 19 | To specify an individual extended property, use the name of the property. For properties that are not default or extended properties, you must specify the LDAP display name of the attribute. 20 | 21 | To retrieve properties and display them for an object, you can use the Get-* cmdlet associated with the object and pass the output to the Get-Member cmdlet. 22 | .EXAMPLE 23 | Get-MDADUser -Identity duffney -Properties * 24 | #> 25 | [CmdletBinding()] 26 | param( 27 | [string]$Identity, 28 | [string]$Properties 29 | ) 30 | 31 | BEGIN { 32 | $Server = (Get-ADForest).DomainNamingMaster 33 | $Domains = (Get-ADObject -Filter {ObjectClass -eq "trusteddomain"} -Server $server).Name 34 | $Domains += (Get-ADDomain -Server $Server).DNSRoot 35 | } 36 | 37 | PROCESS { 38 | foreach ($Domain in $Domains){ 39 | Try { 40 | if ($Properties -ne ""){ 41 | Get-ADUser -Identity $Identity -Server $Domain -Properties $Properties 42 | } else { 43 | Get-ADUser -Identity $Identity -Server $Domain 44 | } 45 | break 46 | } 47 | Catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { 48 | 49 | } 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ActiveDirectory/Get-UserWithNoEmail.ps1: -------------------------------------------------------------------------------- 1 | Get-ADUser -Filter {EmailAddress -notlike "*"} -Properties EmailAddress | Select Name 2 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter01/ReadMeChapter01.txt: -------------------------------------------------------------------------------- 1 | There isn't a lab or further data for chapter01. -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/CodeListing02.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/CodeListing02.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/LABchapter02.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/LABchapter02.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/LABnames.csv: -------------------------------------------------------------------------------- 1 | FirstName,LastName,SamAccountName 2 | Bill,Smith,bsmith 3 | Dave,Jones,djones 4 | Tom,Brown,tbrown 5 | John,James,jjames -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/TryItNewUser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 02 5 | LAB Complete the Try it Now sections User creation 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | 9 | #> 10 | 11 | $secpass = Read-Host "Passw0rd!" -AsSecureString 12 | New-ADUser -Name "GREEN Dave" -SamAccountName dgreen ` 13 | -UserPrincipalName "dgreen@manticore.org" -AccountPassword $secpass ` 14 | -Path "cn=Users,dc=Manticore,dc=org" -Enabled:$true 15 | 16 | $secpass = Read-Host "Passw0rd!" -AsSecureString 17 | New-ADUser -Name "GREEN Jo" -SamAccountName jgreen ` 18 | -UserPrincipalName "jgreen@manticore.org" -AccountPassword $secpass ` 19 | -Path "cn=Users,dc=Manticore,dc=org" -Enabled:$true 20 | 21 | $secpass = Read-Host "Passw0rd!" -AsSecureString 22 | New-ADUser -Name "GREEN Fred" -SamAccountName fgreen ` 23 | -UserPrincipalName "fgreen@manticore.org" -AccountPassword $secpass ` 24 | -Path "cn=Users,dc=Manticore,dc=org" -Enabled:$true 25 | 26 | $secpass = Read-Host "Password!" -AsSecureString 27 | New-ADUser -Name "GREEN Mike" -SamAccountName mgreen ` 28 | -UserPrincipalName "mgreen@manticore.org" -AccountPassword $secpass ` 29 | -Path "cn=Users,dc=Manticore,dc=org" -Enabled:$true -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/labnewbulkuser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 02 5 | LAB Bulk User creation 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | 9 | #> 10 | $secpass = Read-Host "Passw0rd!" -AsSecureString 11 | Import-Csv labnames.csv | 12 | foreach { 13 | $name = "$($_.LastName) $($_.FirstName)" 14 | 15 | New-ADUser -GivenName $($_.FirstName) -Surname $($_.LastName) ` 16 | -Name $name -SamAccountName $($_.SamAccountName) ` 17 | -UserPrincipalName "$($_.SamAccountName)@manticore.org" ` 18 | -AccountPassword $secpass -Path "cn=Users,dc=Manticore,dc=org" ` 19 | -Enabled:$true 20 | } 21 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/names.csv: -------------------------------------------------------------------------------- 1 | FirstName,LastName,SamAccountName 2 | Dave,GREEN,dgreen 3 | Fred,GREEN,fgreen 4 | Jo,GREEN,jgreen 5 | Mike,GREEN,mgreen 6 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter02/newbulkuser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 02 5 | 2.3 User creation in bulk 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | 9 | #> 10 | $secpass = Read-Host "Password" -AsSecureString 11 | Import-Csv c:\temp\names.csv | 12 | foreach { 13 | $name = "$($_.FirstName) $($_.LastName)" 14 | 15 | New-ADUser -GivenName $($_.FirstName) -Surname $($_.LastName) ` 16 | -Name $name -SamAccountName $($_.SamAccountName) ` 17 | -UserPrincipalName "$($_.SamAccountName)@manticore.org" ` 18 | -AccountPassword $secpass -Path "cn=Users,dc=Manticore,dc=org" ` 19 | -Enabled:$true -Server hydra.manticore.org -Credential hydra\administrator 20 | } 21 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter03/CodeListing03.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter03/CodeListing03.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter03/LABchapter03.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter03/LABchapter03.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter03/bulkuserchange.ps1: -------------------------------------------------------------------------------- 1 | Import-Csv -Path C:\Scripts\officechange.csv | 2 | foreach { 3 | Set-ADUser -Identity $_.samaccountname -Office $_.Office ` 4 | -StreetAddress $_.StreetAddress -POBox $_.POBox -City $_.City ` 5 | -State $_.State -PostalCode $_.Zip -Country $_.Country 6 | } 7 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter03/officechange.csv: -------------------------------------------------------------------------------- 1 | SamAccountName,Office,StreetAddress,POBox,City,State,Zip,Country 2 | mgreen,"North East","1 West Street",PO567,Boston,Massachusetts,567890,US 3 | dgreen,"North West","1 New Street",PO123,Seattle,Washington,123456,US 4 | jgreen,"North East","1 West Street",PO567,Boston,Massachusetts,567890,US 5 | bgreen,"North West","1 New Street",PO123,Seattle,Washington,123456,US -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter03/renameuser.ps1: -------------------------------------------------------------------------------- 1 | Get-ADUser -Identity wgreen | 2 | Rename-ADObject -NewName "GREEN Bill" 3 | 4 | Get-ADUser -Identity wgreen -Properties * | 5 | Set-ADUser -DisplayName "GREEN Bill" -SamAccountName bgreen ` 6 | -GivenName "Bill" 7 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/CodeListing04.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/CodeListing04.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/LABchapter04.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/LABchapter04.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/Solving the 5000 user limit in Get-ADGroupMember.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/Solving the 5000 user limit in Get-ADGroupMember.docx -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/bulkgroupcreate.ps1: -------------------------------------------------------------------------------- 1 | Import-Csv -Path .\groups.csv | 2 | foreach { 3 | New-ADGroup -Name $_.Name -Path "CN=Users,DC=Manticore,DC=org" ` 4 | -GroupCategory Security -GroupScope Global ` 5 | -Description $_.Description 6 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/changegroupscope.ps1: -------------------------------------------------------------------------------- 1 | "ADLgroup3", "ADLgroup4", "ADLgroup5", "ADLgroup6" | foreach {Set-ADGroup -Identity $_ -GroupScope Universal} 2 | "ADLgroup3", "ADLgroup4" | foreach {Set-ADGroup -Identity $_ -GroupScope DomainLocal } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/chapter4_computersingroups.ps1: -------------------------------------------------------------------------------- 1 | New-ADGroup -Name ADLcomputers -Description "Test group for computers" -GroupCategory Security -GroupScope Global -Path "cn=Computers,dc=Manticore,dc=org" 2 | 3 | "ADLComp1", "ADLComp2" | 4 | foreach { 5 | New-ADComputer -Name $_ -Path "cn=Computers,dc=Manticore,dc=org" 6 | } 7 | 8 | Add-ADGroupMember -Identity ADLcomputers -Members (Get-ADComputer -Filter {Name -like "ADLcomp*"}) 9 | 10 | Get-ADGroupMember -Identity ADLComputers -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter04/groups.csv: -------------------------------------------------------------------------------- 1 | Name,Description 2 | ADLgroup1,"ADL Global group 1" 3 | ADLgroup2,"ADL Global group 2" 4 | ADLgroup3,"ADL Domain Local group 1" 5 | ADLgroup4,"ADL Domain Local group 2" 6 | ADLgroup5,"ADL Universal group 1" 7 | ADLgroup6,"ADL Universal group 2" 8 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter05/CodeListing05.txt: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 05 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | 11 | 12 | # section 5.1.1 13 | Search-ADAccount -AccountDisabled | select Name, samAccountName 14 | 15 | Get-ADUser -Identity dgreen | Enable-ADAccount 16 | 17 | # section 5.1.3 18 | Search-ADAccount -AccountExpired | Format-Table Name, SamAccountName, DistinguishedName, AccountExpirationDate -AutoSize 19 | 20 | Get-ADUser -Identity dgreen | Set-ADAccountExpiration -DateTime (Get-Date).AddDays(30) 21 | 22 | 23 | Get-ADUser -Identity dgreen | Set-ADAccountExpiration -DateTime ([datetime]'11/25/2013') 24 | 25 | Get-ADUser -Identity dgreen | Clear-ADAccountExpiration 26 | 27 | # section 5.2 28 | Search-ADAccount -PasswordExpired 29 | 30 | # password reset 31 | $password = Read-Host -Prompt "Password" -AsSecureString 32 | 33 | $id = "dgreen" 34 | Set-ADAccountPassword -Identity $id -NewPassword $password -Reset 35 | Set-ADUser -Identity $id -ChangePasswordAtLogon:$true 36 | 37 | # section 5.4 Unlocking a user account 38 | Search-ADAccount -LockedOut 39 | 40 | Unlock-ADAccount -Identity dgreen 41 | 42 | 43 | #section 5.5 Group membership 44 | Get-ADUser -Identity mgreen -Properties memberof | select -ExpandProperty memberof 45 | 46 | Get-ADUser -Identity dgreen -Properties memberof | select -ExpandProperty memberof 47 | 48 | # set goup memberships to match 49 | $target = Get-ADUser -Identity mgreen -Properties memberof 50 | foreach ($member in $target.memberof){ 51 | Remove-ADGroupMember -Identity $member -Members $target -Confirm:$false 52 | } 53 | $source = Get-ADUser -Identity dgreen -Properties memberof 54 | foreach ($member in $source.memberof){ 55 | Add-ADGroupMember -Identity $member -Members $target -Confirm:$false 56 | } 57 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter05/Domain_lockout_policy.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter05/Domain_lockout_policy.tif -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter05/LABchapter05.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter05/LABchapter05.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter06/CodeListing06.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter06/CodeListing06.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter06/LABchapter06.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter06/LABchapter06.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter06/bullkcreatecomputers.ps1: -------------------------------------------------------------------------------- 1 | Import-Csv -Path C:\Scripts\ADLunches\computers.txt | 2 | foreach { 3 | New-ADComputer -Enabled $true -Name $_.Name ` 4 | -Path:"CN=Computers,DC=Manticore,DC=org" ` 5 | -SamAccountName $_.Name ` 6 | -Description $_.Description -PassThru 7 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter06/bullkdeletecomputers.ps1: -------------------------------------------------------------------------------- 1 | Import-Csv -Path C:\Scripts\ADLunches\computersTodelete.txt | 2 | foreach { 3 | Remove-ADComputer -Identity $_.Name -Confirm:$false 4 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter06/computers.txt: -------------------------------------------------------------------------------- 1 | Name,Description 2 | ADLComp10, "Test Machine for AD Lunches" 3 | ADLComp11, "Test Machine for AD Lunches" 4 | ADLComp12, "Test Machine for AD Lunches" 5 | ADLComp13, "Test Machine for AD Lunches" 6 | ADLComp14, "Test Machine for AD Lunches" 7 | ADLComp15, "Test Machine for AD Lunches" 8 | ADLComp16, "Test Machine for AD Lunches" 9 | ADLComp17, "Test Machine for AD Lunches" 10 | ADLComp18, "Test Machine for AD Lunches" 11 | ADLComp19, "Test Machine for AD Lunches" 12 | ADLComp20, "Test Machine for AD Lunches" 13 | ADLComp21, "Test Machine for AD Lunches" 14 | ADLComp22, "Test Machine for AD Lunches" 15 | ADLComp23, "Test Machine for AD Lunches" 16 | ADLComp24, "Test Machine for AD Lunches" 17 | ADLComp25, "Test Machine for AD Lunches" 18 | ADLComp26, "Test Machine for AD Lunches" 19 | ADLComp27, "Test Machine for AD Lunches" 20 | ADLComp28, "Test Machine for AD Lunches" 21 | ADLComp29, "Test Machine for AD Lunches" 22 | ADLComp30, "Test Machine for AD Lunches" -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter06/computersTodelete.txt: -------------------------------------------------------------------------------- 1 | Name 2 | ADLComp21 3 | ADLComp22 4 | ADLComp23 5 | ADLComp24 6 | ADLComp25 7 | ADLComp26 8 | ADLComp27 9 | ADLComp28 10 | ADLComp29 11 | ADLComp30 -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter07/CodeListing07.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter07/CodeListing07.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter07/LABchapter07.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter07/LABchapter07.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter07/bullkcreateous.ps1: -------------------------------------------------------------------------------- 1 | import-csv C:\Scripts\ADLunches\ous.txt | 2 | foreach { 3 | New-ADOrganizationalUnit -Name $_.Name -Path $_.Path ` 4 | -ProtectedFromAccidentalDeletion $true -PassThru 5 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter07/ous.txt: -------------------------------------------------------------------------------- 1 | Name,Path 2 | ADML4,"DC=Manticore,DC=org" 3 | Computers,"OU=ADML4,DC=Manticore,DC=org" 4 | Users,"OU=ADML4,DC=Manticore,DC=org" 5 | Desktops,"OU=Computers,OU=ADML4,DC=Manticore,DC=org" 6 | Laptops,"OU=Computers,OU=ADML4,DC=Manticore,DC=org" 7 | Staff,"OU=Users,OU=ADML4,DC=Manticore,DC=org" 8 | Contractors,"OU=Users,OU=ADML4,DC=Manticore,DC=org" 9 | Managers,"OU=Users,OU=ADML4,DC=Manticore,DC=org" -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter08/CodeListing08.txt: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 08 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | 11 | 12 | # 8.2.2 Creating a GPO with PowerShell 13 | Import-Module GroupPolicy 14 | New-GPO -Name ADMLp1 -Comment "AD Lunches GPO" 15 | 16 | New-GPO -Name ADMLp2 -Comment "AD Lunches GPO from starter GPO" -StarterGpoName ADMLstarterGPO2 17 | 18 | #8.2.3 Creating Starter GPOs 19 | New-GPStarterGPO -Name ADMLstarterGPO2 -Comment "ADM Lunches starter GPO 2" 20 | 21 | #8.3.2 Designating a GPO for users or computers 22 | $gpo = Get-GPO -Name ADMLg1 23 | $gpo.GpoStatus = "UserSettingsDisabled" 24 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter08/LABchapter08.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter08/LABchapter08.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter09/CodeListing09.txt: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 09 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | 11 | 12 | # CREATING A LINK USING POWERSHELL 13 | Get-GPO -Name ADMlgpo2 | 14 | New-GPLink -Target "OU=ADMLunches,DC=manticore,DC=org" 15 | 16 | # DISCOVERING LINKS USING POWERSHELL 17 | Get-GPInheritance -Target "OU=ADMLunches,DC=manticore,DC=org" 18 | 19 | $gpos = Get-GPInheritance -Target "OU=ADMLunches,DC=manticore,DC=org" 20 | $linked = $gpos.GpoLinks | select -ExpandProperty DisplayName 21 | $gpos | select -ExpandProperty GpoLinks 22 | $gpos | select -ExpandProperty InheritedGpoLinks |where DisplayName -NotIn $linked 23 | 24 | 25 | Get-GPInheritance -Target "OU=ADMLunches,DC=manticore,DC=org" |select -ExpandProperty InheritedGpoLinks |Format-Table DisplayName, Order, Target -AutoSize 26 | 27 | # DELETING A GPO USING POWERSHELL 28 | Remove-GPO -Name ADMLtest2 29 | 30 | # UNLINKING A GPO USING POWERSHELL 31 | Remove-GPLink -Name ADMLgpo2 -Target "OU=ADMLunches,DC=Manticore,DC=org" 32 | 33 | 34 | # 9.4 Customizing GPO Refresh settings 35 | gpupdate 36 | 37 | gpupdate /Target:Computer 38 | gpupdate /Target:User 39 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter09/LABchapter09.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter09/LABchapter09.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter09/Listing9.1.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Listing 9.1 from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 09 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | 11 | $gpolinks = Get-ADOrganizationalUnit -Filter * | #1 12 | where LinkedGroupPolicyObjects | #2 13 | foreach { 14 | $ou = $_.DistinguishedName 15 | $_.LinkedGroupPolicyObjects | #3 16 | foreach { 17 | $x = $_.ToUpper() -split ",", 2 18 | $id = $x[0].Replace("CN={","").Replace("}","") 19 | $props = [ordered]@{ 20 | OU = $ou 21 | GPO = Get-GPO -Guid $id | select -ExpandProperty DisplayName #4 22 | } 23 | New-Object -TypeName PSObject -Property $props 24 | } 25 | } 26 | $gpolinks | sort OU | Format-Table OU, GPO -AutoSize 27 | $gpolinks | sort GPO | Format-Table GPO, OU -AutoSize 28 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter10/CodeListing10.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter10/CodeListing10.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter10/LABchapter10.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter10/LABchapter10.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter11/LABchapter11.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter11/LABchapter11.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter12/CodeListing12.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter12/CodeListing12.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter12/LABchapter12.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter12/LABchapter12.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter12/move-afsmo.ps1: -------------------------------------------------------------------------------- 1 | function move-afsmo { 2 | [CmdletBinding()] 3 | param([string]$server, 4 | 5 | [ValidateSet("schema", "domain", "rid", "infra", "pdc")] 6 | [string]$fsmo 7 | ) 8 | $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 9 | $sid = ($dom.GetDirectoryEntry()).objectSid 10 | $dc = [ADSI]"LDAP://$server/rootDSE" 11 | 12 | switch ($fsmo.ToLower()){ 13 | "schema" {$role = "becomeSchemaMaster"; break} 14 | "domain" {$role = "becomeDomainMaster"; break} 15 | "rid" {$role = "becomeRidMaster"; break} 16 | "infra" {$role = "becomeInfraStructureMaster"; break} 17 | "pdc" {$role = "becomePDC"; break} 18 | } 19 | 20 | if ($role -eq "becomePDC"){ $dc.Put($role, $sid[0])} 21 | else {$dc.Put($role, 1) } 22 | $dc.SetInfo() 23 | } 24 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter12/new-globalcatalog.ps1: -------------------------------------------------------------------------------- 1 | $dc = "dc02.manticore.org" 2 | $contextType = [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::DirectoryServer 3 | 4 | $context = New-Object -TypeName 5 | 6 | System.DirectoryServices.ActiveDirectory.DirectoryContext -ArgumentList $contextType, $dc 7 | 8 | $gc = [System.DirectoryServices.ActiveDirectory.DomainController]::GetDomainController($context) 9 | 10 | $gc.EnableGlobalCatalog() 11 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter12/remove-globalcatalog.ps1: -------------------------------------------------------------------------------- 1 | $dc = "dc02.manticore.org" 2 | 3 | $contextType = [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::DirectoryServer 4 | 5 | $context = New-Object –TypeName 6 | 7 | System.DirectoryServices.ActiveDirectory.DirectoryContext -ArgumentList $contextType, $dc 8 | 9 | $gc = [System.DirectoryServices.ActiveDirectory.GlobalCatalog]::GetGlobalCatalog($context) 10 | 11 | $gc.DisableGlobalCatalog() -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter13/CodeListing13.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter13/CodeListing13.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter13/LABchapter13.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter13/LABchapter13.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter13/restore-fromrecyclebin.ps1: -------------------------------------------------------------------------------- 1 | Get-ADObject -IncludeDeletedObjects -Filter {Name -like '*Test*' -AND objectclass -eq 'organizationalunit'} | where Deleted | Restore-ADObject 2 | 3 | Get-ADObject -IncludeDeletedObjects -Properties * -Filter {LastKnownParent -eq "OU=Test,DC=Manticore,DC=org" -AND objectclass -eq 'user'} | where Deleted | Restore-ADObject -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter13/snapshot.txt: -------------------------------------------------------------------------------- 1 | ## help 2 | ntdsutil snapshot help quit quit 3 | 4 | ## view snapshots 5 | ntdsutil snapshot 'List All' quit quit 6 | 7 | 8 | ## create snapshot 9 | - take screen shot 10 | 11 | ntdsutil snapshot 'Activate Instance NTDS' Create quit quit 12 | 13 | 14 | ##take the last one and mount 15 | ntdsutil snapshot "mount 4f85522d-6d7b-42bc-be78-cd29585b7a20" quit quit 16 | 17 | ## unmount 18 | ntdsutil snapshot "unmount 4f85522d-6d7b-42bc-be78-cd29585b7a20" quit quit 19 | 20 | ## need to have only a single NIC so no conflict 21 | dsamain -dbpath 'C:\$SNAP_201303251401_VOLUMEC$\Windows\NTDS\ntds.dit' -ldapPort: 60000 -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter14/CodeListing14.txt: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 14 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | 11 | # 14.1.1 Builtin Container 12 | 13 | Get-ADGroup -SearchBase "CN=Builtin,DC=Manticore,DC=org" -Filter * | select Name 14 | Get-ADUser -SearchBase "CN=Builtin,DC=Manticore,DC=org" -Filter * | select Name 15 | Get-ADComputer -SearchBase "CN=Builtin,DC=Manticore,DC=org" -Filter * | select Name 16 | Get-ADObject -SearchBase "CN=Builtin,DC=Manticore,DC=org" -Filter * | select Name, objectclass 17 | 18 | Add the objectclass property when using Get-AdObject to distinguish object types 19 | 20 | 21 | 14.1.2 Users container 22 | 23 | Get-ADGroup -SearchBase "CN=Users,DC=Manticore,DC=org" -Filter * | select Name 24 | Get-ADUser -SearchBase "CN=Users,DC=Manticore,DC=org" -Filter * | select Name 25 | Get-ADComputer -SearchBase "CN=Users,DC=Manticore,DC=org" -Filter * | select Name 26 | Get-ADObject -SearchBase "CN=Users,DC=Manticore,DC=org" -Filter * | select Name, objectclass 27 | 28 | Add the objectclass property when using Get-AdObject to distinguish object types 29 | 30 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter14/LABchapter14.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter14/LABchapter14.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter15(DNS)/CodeListing15.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter15(DNS)/CodeListing15.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter15(DNS)/LABchapter15.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter15(DNS)/LABchapter15.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/ADtopology.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/ADtopology.pdf -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/ADtopology.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/ADtopology.vsdx -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/LABchapter16.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/LABchapter16.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/Missing subnets.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/Missing subnets.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/get-site.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/get-site.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/get-sitelink.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 16 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | $for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() 11 | $for.sites | Format-Table Name, SiteLinks -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/get-subnet.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/get-subnet.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/new-site.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 16 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | ## get current forest and set context 11 | $for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() 12 | $fortyp = [System.DirectoryServices.ActiveDirectory.DirectoryContexttype]"forest" 13 | $forcntxt = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext($fortyp, $for) 14 | 15 | ## create the site 16 | $site = new-object System.DirectoryServices.ActiveDirectory.ActiveDirectorySite($forcntxt, "MyNewSite2") 17 | $site.Save() -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/new-sitelink.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 16 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | ## get current forest and set context 11 | $for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() 12 | $fortyp = [System.DirectoryServices.ActiveDirectory.DirectoryContexttype]"forest" 13 | $forcntxt = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext($fortyp, $for) 14 | 15 | $link = New-Object -TypeName System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink -ArgumentList $forcntxt, "MyNewSite3-MyNewSite4" 16 | 17 | $site1 = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::FindByName($forcntxt, "MyNewSite3") 18 | $site2 = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::FindByName($forcntxt, "MyNewSite4") 19 | 20 | $link.Sites.Add($site1) 21 | $link.Sites.Add($site2) 22 | 23 | $link.Cost = 150 24 | $link.ReplicationInterval = "01:00:00" ## 1 hour 24x7 25 | $link.Save() 26 | 27 | $linkde = $link.GetDirectoryEntry() 28 | $linkde.Description = "Links sites MyNewSite3 and MyNewSite4" 29 | $linkde.SetInfo() -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/new-subnet.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 16 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | ## get current forest and set context 11 | $for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() 12 | $fortyp = [System.DirectoryServices.ActiveDirectory.DirectoryContexttype]"forest" 13 | $forcntxt = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext($fortyp, $for) 14 | 15 | $site = "MyNewSite2" 16 | $subnetlocation = "Building X" 17 | $subnetname = "10.55.0.0/24" 18 | 19 | ## create subnet and link to the site 20 | $subnet = New-Object System.DirectoryServices.ActiveDirectory.ActiveDirectorySubnet($forcntxt, $subnetname, $site) 21 | $Subnet.Location = $subnetlocation 22 | $subnet.Save() -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter16/set-schedule.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 16 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | ## get current forest and set context 11 | $for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() 12 | $fortyp = [System.DirectoryServices.ActiveDirectory.DirectoryContexttype]"forest" 13 | $forcntxt = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext($fortyp, $for) 14 | 15 | $link = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink]::FindByName($forcntxt, "MyNewSite3-MyNewSite4") 16 | 17 | $sched = New-Object -TypeName System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule 18 | $sched.ResetSchedule() 19 | $sched.SetDailySchedule("Eighteen", "Zero", "TwentyThree", "FortyFive") 20 | 21 | $link.InterSiteReplicationSchedule = $sched 22 | $link.Save() 23 | 24 | $days = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" 25 | $sched.SetSchedule($days, "Twelve", "Zero", "Thirteen", "FortyFive") 26 | 27 | $link.InterSiteReplicationSchedule = $sched 28 | $link.Save() -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter17/CodeListing17.txt: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 17 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | 11 | # 17.3.2 Testing replication using PowerShell 12 | 13 | Get-ADReplicationConnection 14 | 15 | Get-ADReplicationConnection -Filter {ReplicateFromDirectoryServer -like "*server03*"} 16 | 17 | Get-ADReplicationUpToDatenessVectorTable -Target server02 18 | 19 | Get-ADReplicationPartnerMetadata -Target server02, server03 -PartnerType both 20 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter17/LABchapter17.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter17/LABchapter17.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter17/test-replication.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 17 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() #1 11 | 12 | $dom.FindAllDomainControllers() | 13 | foreach { 14 | $_.Name 15 | $contextType = [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::DirectoryServer 16 | 17 | $context = New-Object -TypeName System.DirectoryServices.ActiveDirectory.DirectoryContext -ArgumentList $contextType, $($_.Name) 18 | 19 | $dc = [System.DirectoryServices.ActiveDirectory.DomainController]::GetDomainController($context) 20 | 21 | $dc.GetAllReplicationNeighbors() | 22 | select PartitionName, SourceServer, UsnLastObjectChangeSynced, 23 | LastSuccessfulSync, LastAttemptedSync, LastSyncMessage, 24 | ConsecutiveFailureCount 25 | } 26 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter18/ReadMeChapter18.txt: -------------------------------------------------------------------------------- 1 | There isn't a lab or further data for chapter18. -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter19/CodeListing19.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter19/CodeListing19.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter19/LABchapter19.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter19/LABchapter19.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter19/Listing19.1.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 19 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | Get-ADComputer -SearchBase "OU=Domain Controllers,DC=Manticore,DC=org" -Filter * | 11 | foreach { 12 | Get-ADDomainController -Identity $_.DNSHostName 13 | } | 14 | where Site -eq 'Default-First-Site-Name' | 15 | foreach { 16 | if (Test-Connection -ComputerName $psitem.Name -Quiet -Count 1){ 17 | Get-ADReplicationFailure -Target DC01 18 | } 19 | else { 20 | Write-Warning -Message "Cannot contact $($psitem.Name)" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter19/Test-DC.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Sample lab answer from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 19 5 | 6 | This script performs tests against one or more domain controllers 7 | to determine if DC availability is affecting logon 8 | 9 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 10 | It is YOUR responsibilty to test if for suitability in YOUR environment. 11 | The comments match the section headings in the chapter 12 | #> 13 | 14 | function test-dc { 15 | [CmdletBinding()] 16 | param 17 | ( 18 | [string[]]$dcs 19 | ) 20 | 21 | foreach ($dc in $dcs) { 22 | $DCstate = [ordered]@{} 23 | $DCstate += @{"DCname" = $dc} 24 | 25 | ## ping test 26 | $pingable = Test-Connection -ComputerName $dc -Quiet -Count 1 27 | $DCstate += @{"Pingable" = $pingable} 28 | 29 | ## NTDS service 30 | $ntdsState = (Get-Service -Name NTDS -ComputerName $dc).Status 31 | $DCstate += @{"NTDSstatus" = $ntdsState} 32 | 33 | # perfrom AD lookup 34 | $ADlookup = $null 35 | $ADlookup = Get-ADUser –Identity "jduffney" –Server $dc 36 | 37 | if ($ADlookup) 38 | { 39 | $DCstate += @{"ADLookup" = $true} 40 | } 41 | else 42 | { 43 | $DCstate += @{"ADLookup" = $false} 44 | } 45 | 46 | New-Object -TypeName PSObject -Property $DCstate 47 | 48 | } # end outer foreach 49 | } # end of function 50 | 51 | $domaincontrollers = Get-ADComputer -Filter * -SearchBase (Get-ADDomain | select -ExpandProperty DomainControllersContainer) | 52 | select -ExpandProperty DNSHostName 53 | 54 | test-dc -dcs $domaincontrollers -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter19/set-logonhours.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter19/set-logonhours.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/CodeListing20.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/CodeListing20.txt -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/LABchapter20.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/LABchapter20.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.1.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## Test FSMO role holders 3 | ## 4 | $for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() 5 | Test-Connection -ComputerName $for.SchemaRoleOwner -Count 2 6 | Test-Connection -ComputerName $for.NamingRoleOwner -Count 2 7 | 8 | $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 9 | Test-Connection -ComputerName $dom.PdcRoleOwner -Count 2 10 | Test-Connection -ComputerName $dom.InfrastructureRoleOwner -Count 2 11 | Test-Connection -ComputerName $dom.RidRoleOwner -Count 2 -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.2.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## Test domain controllers 3 | ## 4 | $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 5 | foreach ($dc in $dom.DomainControllers){ 6 | Test-Connection -ComputerName $dc -Count 2 7 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.3.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## Test global catalog 3 | ## 4 | $for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() 5 | foreach ($gc in $for.GlobalCatalogs){ 6 | Test-Connection -ComputerName $gc -Count 2 7 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.4.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## test SRV records 3 | ## 4 | $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 5 | foreach ($dc in $dom.DomainControllers){ 6 | Get-DnsServerResourceRecord -RRType SRV -ComputerName DC01 -ZoneName manticore.org | 7 | where {$_.RecordData.DomainName -eq "$dc."} | 8 | sort hostname | 9 | Format-Table -AutoSize 10 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.5.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## Test services 3 | ## 4 | $session = New-PSSession -ComputerName 'server02', 'server03' 5 | 6 | 'DFSR', 'NtFrs', 'Kdc', 'W32Time', 'ADWS', 'DNS', 'EventLog', 'gpsvc', 'Netlogon', 'NTDS', 'wuauserv' | 7 | foreach -BEGIN { 8 | $sb = { 9 | param($service) 10 | Get-Service -Name $service 11 | } 12 | } -PROCESS { 13 | Invoke-Command -Session $session -ScriptBlock $sb -ArgumentList $psitem 14 | } 15 | 16 | $session | Remove-PSSession -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.6.ps1: -------------------------------------------------------------------------------- 1 | $ous = @() 2 | $dom = Get-ADDomain 3 | 4 | $ous += "CN=Builtin,$($dom.DistinguishedName)" 5 | $ous += "CN=Users,$($dom.DistinguishedName)" 6 | 7 | foreach ($ou in $ous){ 8 | $groups = Get-ADGroup -SearchBase $ou -Filter * | 9 | where {$_.Name -ne 'Domain Users' -and $_.Name -ne 'Domain Computers'} 10 | foreach ($group in $groups){ 11 | Get-ADGroupMember -Identity $group.DistinguishedName | 12 | select @{Name='OU'; Expression={$ou}}, 13 | @{Name='Group'; Expression={$group.Name}}, 14 | @{Name='Member'; Expression={$psitem.Name}} 15 | } 16 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.7.ps1: -------------------------------------------------------------------------------- 1 | $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 2 | foreach ($dc in $dom.DomainControllers){ 3 | Get-WmiObject -Class Win32_Volume -ComputerName $dc -Filter "Name='C:\\'" | 4 | select Name, 5 | @{N='Size(GB)'; E={[Math]::Round(($_.Capacity / 1GB),2)}}, 6 | @{N='Free(GB)'; E={[Math]::Round(($_.FreeSpace / 1GB), 2)}}, 7 | @{N='PercFree'; E={[Math]::Round((($_.FreeSpace / $_.Capacity) * 100) ,2 )}}, 8 | PSComputerName 9 | } 10 | 11 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.8.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## test domain controller time 3 | ## 4 | $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 5 | $dom.DomainControllers | select Name, CurrentTime -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter20/Listing20.9.ps1: -------------------------------------------------------------------------------- 1 |  2 | $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 3 | foreach ($dc in $dom.DomainControllers){ 4 | Get-WmiObject -Class Win32_OperatingSystem -ComputerName $dc | 5 | Select PSComputerName, 6 | @{Name='LocalTime'; Expression={$_.ConvertToDateTime($_.LocalDateTime)} } 7 | } -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter21/CodeListing21.txt: -------------------------------------------------------------------------------- 1 | <# 2 | Code listings from: 3 | Active Directory Management in a Month of Lunches 4 | Chapter 21 5 | 6 | All code supplied "as is" as an example to illustrate the text. No guarantees or warranties are supplied with this code. 7 | It is YOUR responsibilty to test if for suitability in YOUR environment. 8 | The comments match the section headings in the chapter 9 | #> 10 | 11 | There is no code for chapter 21 12 | -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter21/LABchapter21.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter21/LABchapter21.doc -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter21/users.csv: -------------------------------------------------------------------------------- 1 | Firstname,Lastname,SamAccountName 2 | Aimee,Jones,ajones 3 | Alex,Smith,asmith 4 | Ann,Green,agreen 5 | Clare,Brown,cbrown 6 | Harry,Black,hblack 7 | June,Sherman,jsherman 8 | Pat,Lee,plee 9 | Robert,Grant,rgrant 10 | Ron,Stuart,rstuart 11 | Sarah,Salisbury,ssalisbury 12 | Tom,Lincoln,tlincoln 13 | William,Churchill,wchurchill -------------------------------------------------------------------------------- /ActiveDirectory/LearnActiveDirectoryMOL/Chapter22/CodeListing22.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/LearnActiveDirectoryMOL/Chapter22/CodeListing22.txt -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/01 - Introduction/PowerShell Cmd Line Conversion Guide AD.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/MVAPSAD/01 - Introduction/PowerShell Cmd Line Conversion Guide AD.pdf -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/01 - Introduction/_1_0_INTRODUCTION.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/MVAPSAD/01 - Introduction/_1_0_INTRODUCTION.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/01 - Introduction/_1_3_ADAC History.ps1: -------------------------------------------------------------------------------- 1 | # Open Windows Server Manager on Windows Server 2012 or above 2 | # Launch the Active Directory Administrative Console 3 | # Look for the "Windows PowerShell History" bar at the bottom 4 | # Click the up arrow /\ on the right to view 5 | # Execute GUI cmds and watch the window 6 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/01 - Introduction/_1_4_One-Liners.ps1: -------------------------------------------------------------------------------- 1 | break 2 | 3 | # List of all domain controllers 4 | Get-ADDomainController -Filter * | Format-Table Name, Domain, Forest, Site, IPv4Address, OperatingSystem, OperationMasterRoles -AutoSize 5 | 6 | # Account unlock 7 | Read-Host "Enter the user account to unlock" | Unlock-ADAccount 8 | 9 | # Password reset 10 | Set-ADAccountPassword (Read-Host 'User') -Reset 11 | 12 | 13 | # Reset Password 14 | # User must change password at next logon 15 | # Alternate credentials 16 | Set-ADAccountPassword -Cr ($c=Get-Credential) -S ($s=Read-Host 'DC') -I ($u=Read-Host 'User') -R;Set-ADUser $u -Ch 1 -Cr $c -Server $s 17 | 18 | 19 | #List all manual replication connections 20 | Get-ADObject -LDAPFilter "(&(objectClass=nTDSConnection)(!options:1.2.840.113556.1.4.804:=1))" -Searchbase (Get-ADRootDSE).ConfigurationNamingContext -Property DistinguishedName, FromServer | Format-Table DistinguishedName, FromServer 21 | 22 | 23 | # Modify all sitelinks 24 | Get-ADObject -Filter 'objectClass -eq "siteLink"' -SearchBase (Get-ADRootDSE).ConfigurationNamingContext | Set-ADObject -Replace @{Cost=100;ReplInterval=15;Options=5} -Confirm 25 | 26 | 27 | 28 | # Password reset 29 | 30 | : 100 characters 31 | : Reset Password 32 | @echo off&&powershell -NoE -C "&{ipmo ActiveDirectory;Set-ADAccountPassword (Read-Host 'User') -R}" 33 | 34 | : 123 characters 35 | : Reset Password 36 | : User must change password at next logon 37 | @echo off&&powershell -NoE -C "&{ipmo ActiveDirectory;Set-ADAccountPassword ($u=Read-Host 'User') -R;Set-ADUser $u -Ch 1}" 38 | 39 | : 154 characters 40 | : Reset Password 41 | : User must change password at next logon 42 | : Alternate credentials 43 | @echo off&&powershell -NoE -C "&{ipmo ActiveDirectory;Set-ADAccountPassword ($u=Read-Host 'User') -R -Cr ($c=Get-Credential);Set-ADUser $u -Ch 1 -Cr $c}" 44 | 45 | : 191 characters 46 | : Reset Password 47 | : User must change password at next logon 48 | : Alternate credentials 49 | : Target a specific DC 50 | @echo off&&powershell -NoE -C "&{ipmo ActiveDirectory;Set-ADAccountPassword -Cr ($c=Get-Credential) -S ($s=Read-Host 'DC') -I ($u=Read-Host 'User') -R;Set-ADUser $u -Ch 1 -Cr $c -Server $s}" 51 | 52 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/02 - User and Groups/_2_0_USERS AND GROUPS.ps1: -------------------------------------------------------------------------------- 1 | break 2 | 3 | Get-Help about_ActiveDirectory_Identity 4 | Get-Help about_ActiveDirectory_ObjectModel 5 | 6 | 7 | # Raw object vs Tricked-out object 8 | Get-ADObject -LDAPFilter '(&(objectClass=group)(cn=Administrators))' -Properties GroupType | fl Name, GroupType 9 | Get-ADGroup Administrators | fl Name, GroupCategory, GroupScope 10 | 11 | Get-ADObject -LDAPFilter '(&(objectClass=user)(cn=Guest))' -Properties UserAccountControl | fl Name, UserAccountControl 12 | Get-ADUser Guest -Properties * | fl Name, Enabled, LockedOut, PasswordExpired 13 | 14 | Get-ADObject -LDAPFilter '(&(objectClass=computer)(cn=CVDC1))' -Properties * | fl LastLogon, DNSHostName 15 | Get-ADComputer CVDC1 -Properties * | fl LastLogon, LastLogonDate, DNSHostName, IPv4Address 16 | 17 | 18 | # Cmdlets 19 | Get-Command -Noun ADUser 20 | Get-Command -Noun ADComputer 21 | Get-Command -Noun Computer 22 | Get-Command -Noun ADGroup 23 | Get-Command -Noun ADOrganizationalUnit 24 | 25 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/02 - User and Groups/_2_2_Updating.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/MVAPSAD/02 - User and Groups/_2_2_Updating.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/02 - User and Groups/_2_3_Deleting.ps1: -------------------------------------------------------------------------------- 1 | break 2 | 3 | 4 | 5 | # Delete a batch of users 6 | Get-ADUser -Filter 'Office -eq "MVA"' | Remove-ADUser -WhatIf 7 | 8 | Get-ADUser -Filter 'Office -eq "MVA"' | Remove-ADUser 9 | 10 | Get-ADUser -Filter 'Office -eq "MVA"' | Remove-ADUser -Confirm:$false 11 | 12 | 13 | 14 | # Empty the AD Recycle Bin (ONLY IN A LAB!) 15 | Get-ADObject -SearchBase (Get-ADDomain).DeletedObjectsContainer -LDAPFilter "(!name=Deleted Objects)" -IncludeDeletedObjects | 16 | Remove-ADObject -Confirm:$false 17 | 18 | 19 | 20 | 21 | #------------------------------------------------------------------------------ 22 | # Deleting computer objects recursively. They are a container! 23 | # Some (like clusters) may contain child objects. 24 | #------------------------------------------------------------------------------ 25 | 26 | 27 | New-ADComputer MP3Server 28 | Get-ADComputer MP3Server 29 | Remove-ADComputer MP3Server -WhatIf 30 | Get-ADComputer MP3Server | Remove-ADObject -Recursive 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | #------------------------------------------------------------------------------ 39 | # Delete objects by batches 40 | #------------------------------------------------------------------------------ 41 | 42 | do { 43 | $query = Get-ADObject -LDAPFilter '(&(objectClass=foo)(attribute=value))' -Server dc1.contoso.com -ResultSetSize 5000 44 | $query | Remove-ADObject -Confirm:$False -Recurse 45 | Start-Sleep -Seconds (15*60) 46 | } while ($query) 47 | 48 | 49 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/02 - User and Groups/newusers.csv: -------------------------------------------------------------------------------- 1 | First Name,Last Name,Department,Title,City,State,Office,EmployeeID 2 | Ana,Duran,Accounting,Analyst,Seattle,WA,MVA,4242 3 | Chad,Lawhorn,Finance,Senior Analyst,New York,NY,MVA,4243 4 | Cole,Catlett,HR,Manager,Los Angeles,CA,MVA,4244 5 | Darren,McCormick,Marketing,Analyst,Atlanta,GA,MVA,4245 6 | Denise,Norris,Research,Senior Analyst,Seattle,WA,MVA,4246 7 | Dwight,Ahmad,Sales,Manager,New York,NY,MVA,4247 8 | Eric,Langer,Accounting,Analyst,Los Angeles,CA,MVA,4248 9 | Harry,Everson,Finance,Senior Analyst,Atlanta,GA,MVA,4249 10 | Hiram,Cornejo,HR,Manager,Seattle,WA,MVA,4250 11 | Irene,Strickland,Marketing,Analyst,New York,NY,MVA,4251 12 | Janine,Leblanc,Research,Senior Analyst,Los Angeles,CA,MVA,4252 13 | Mason,Novotny,Sales,Manager,Atlanta,GA,MVA,4253 14 | Millie,Bray,Accounting,Analyst,Seattle,WA,MVA,4254 15 | Ofelia,Riddle,Finance,Senior Analyst,New York,NY,MVA,4255 16 | Patricia,Thomas,HR,Manager,Los Angeles,CA,MVA,4256 17 | Rhonda,Ballard,Marketing,Analyst,Atlanta,GA,MVA,4257 18 | Ross,Heinrich,Research,Senior Analyst,Seattle,WA,MVA,4258 19 | Sharlene,England,Sales,Manager,New York,NY,MVA,4259 20 | Tania,Witt,Accounting,Analyst,Los Angeles,CA,MVA,4260 21 | Toby,Wickham,Finance,Senior Analyst,Atlanta,GA,MVA,4261 22 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/03 - Queries/_3_0_QUERIES.ps1: -------------------------------------------------------------------------------- 1 | break 2 | 3 | # Active Directory for Windows PowerShell About Help Topics 4 | # http://technet.microsoft.com/en-us/library/hh531525(v=ws.10).aspx 5 | Get-Help about_ActiveDirectory 6 | Get-Help about_ActiveDirectory_Filter 7 | Get-Help about_ActiveDirectory_Identity 8 | Get-Help about_ActiveDirectory_ObjectModel 9 | 10 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/04 - Forensics/_4_0_FORENSICS.ps1: -------------------------------------------------------------------------------- 1 | break 2 | 3 | # Reverse engineer the highest accounts/groups 4 | 5 | # Use this when the big accounts and groups have been renamed. 6 | # Extrapolate other privileged groups and accounts using the formula below to construct their SIDs. 7 | 8 | Import-Module ActiveDirectory 9 | 10 | # Calculate the SIDs of the highest privileged user and groups 11 | $SID_GROUP_EA = [System.Security.Principal.SecurityIdentifier]"$((Get-ADDomain -Identity (Get-ADForest).Name).DomainSID)-519" 12 | $SID_GROUP_DA = [System.Security.Principal.SecurityIdentifier]"$((Get-ADDomain).DomainSID)-512" 13 | $SID_GROUP_AD = [System.Security.Principal.SecurityIdentifier]'S-1-5-32-544' 14 | $SID_USER_AD = [System.Security.Principal.SecurityIdentifier]"$((Get-ADDomain).DomainSID)-500" 15 | 16 | # Get each one of these privileged security principals 17 | Get-ADGroup $SID_GROUP_EA -Properties * -Server (Get-ADForest).Name 18 | Get-ADGroup $SID_GROUP_DA -Properties * 19 | Get-ADGroup $SID_GROUP_AD -Properties * 20 | Get-ADUser $SID_USER_AD -Properties * 21 | 22 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/05 - Stale Objects/_5_0_STALE OBJECTS.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | 3 | Objective is to give you the tools to create your own stale object 4 | solution. Most of the pieces are here. Go forth and script! 5 | 6 | ENABLE THE RECYCLE BIN FIRST 7 | Find your stale accounts (users, computers, groups, etc.) 8 | Filter them against your exceptions list. 9 | Disable them after x days. Update the object description. 10 | Delete them after x more days. 11 | If computer, then delete DNS records also (A, AAAA, PTR). 12 | If anyone complains, use Restore-ADObject. 13 | 14 | #> -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/05 - Stale Objects/_5_5_Exceptions.ps1: -------------------------------------------------------------------------------- 1 | break 2 | 3 | 4 | <# 5 | 6 | Create a database or CSV file of accounts to be excluded for business rules 7 | -Service accounts with non-expiring passwords 8 | -Special groups 9 | -etc. 10 | 11 | Users 12 | -kbrtgt 13 | -etc. 14 | 15 | Computers 16 | -cluster accounts 17 | -SAMBA accounts 18 | -etc. 19 | 20 | Groups 21 | -Schema Admins 22 | -Backup Operators 23 | -Account Operators 24 | -etc. 25 | 26 | #> 27 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/06 - Replication/ADSiteLinks.csv: -------------------------------------------------------------------------------- 1 | Name,SiteA,SiteB,Cost,Interval,Options 2 | CORPHQ - CORPDR,CORPHQ,CORPDR,10,15,1 3 | CORPHQ - EMEAHQ,CORPHQ,EMEAHQ,15,15,1 4 | CORPHQ - APACHQ,CORPHQ,APACHQ,15,15,1 5 | EMEAHQ - EMEABR,EMEAHQ,EMEABR,50,15,0 6 | APACHQ - APACBR,APACHQ,APACBR,50,15,0 7 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/06 - Replication/ADSites.csv: -------------------------------------------------------------------------------- 1 | Name,Description 2 | CORPHQ,Contoso Corporate HQ 3 | CORPDR,Contoso Disaster Recovery Site 4 | EMEAHQ,ContosoEMEA Headquarters 5 | EMEABR,ContosoEMEA Branch Office 6 | APACHQ,ContosoAPAC Headquarters 7 | APACBR,ContosoAPAC Branch Office 8 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/06 - Replication/ADSubnets.csv: -------------------------------------------------------------------------------- 1 | Site,Name 2 | CorpHQ,10.1.1.0/24 3 | CorpHQ,10.1.2.0/24 4 | CorpHQ,10.1.3.0/24 5 | CorpHQ,10.1.4.0/24 6 | CorpDR,10.2.1.0/24 7 | CorpDR,10.2.2.0/24 8 | CorpDR,10.2.3.0/24 9 | CorpDR,10.2.4.0/24 10 | EMEAHQ,10.100.1.0/24 11 | EMEAHQ,10.100.2.0/24 12 | EMEAHQ,10.100.3.0/24 13 | EMEAHQ,10.100.4.0/24 14 | APACHQ,10.101.1.0/24 15 | APACHQ,10.101.2.0/24 16 | APACHQ,10.101.3.0/24 17 | APACHQ,10.101.4.0/24 18 | EMEABR,10.100.50.0/24 19 | APACBR,10.101.50.0/24 20 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/06 - Replication/_6_0_REPLICATION.ps1: -------------------------------------------------------------------------------- 1 | break 2 | 3 | # Trusts 4 | 5 | Get-ADTrust -Filter * | ogv 6 | 7 | 8 | # Find FSMOs 9 | 10 | # netdom /query fsmo 11 | Get-ADDomain | Select-Object InfrastructureMaster, RIDMaster, PDCEmulator 12 | 13 | Get-ADForest | Select-Object DomainNamingMaster, SchemaMaster 14 | 15 | Get-ADDomainController -Service PrimaryDC -Discover 16 | 17 | Get-ADDomainController -Filter * | 18 | Select-Object Name, Domain, Forest, OperationMasterRoles | 19 | ft -AutoSize 20 | 21 | 22 | # FSMO moves 23 | 24 | # Transfer one role 25 | Move-ADDirectoryServerOperationMasterRole -Identity CVDC1 ` 26 | -OperationMasterRole PDCEmulator 27 | 28 | Get-ADDomainController -Filter * | 29 | Select-Object Name, Domain, Forest, OperationMasterRoles | 30 | ft -AutoSize 31 | 32 | # Transfer multiple role 33 | Move-ADDirectoryServerOperationMasterRole -Identity CVDC1 ` 34 | -OperationMasterRole RIDMaster,SchemaMaster 35 | 36 | Get-ADDomainController -Filter * | 37 | Select-Object Name, Domain, Forest, OperationMasterRoles | 38 | ft -AutoSize 39 | 40 | # Reference server identity by variable 41 | $server = Get-ADDomainController -Identity cvdc1.cohovineyard.com 42 | Move-ADDirectoryServerOperationMasterRole -Identity $server ` 43 | -OperationMasterRole SchemaMaster,DomainNamingMaster,PDCEmulator,RIDMaster,InfrastructureMaster 44 | 45 | Get-ADDomainController -Filter * | 46 | Select-Object Name, Domain, Forest, OperationMasterRoles | 47 | ft -AutoSize 48 | 49 | # Seize uses -Force 50 | Move-ADDirectoryServerOperationMasterRole -Identity CVDC1 ` 51 | -OperationMasterRole RIDMaster,InfrastructureMaster,DomainNamingMaster -Force 52 | 53 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/07 - Recovery/_7_0_RECOVERY.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | 3 | Action steps: 4 | 5 | Turn on AD Recycle Bin (forest functional level 2008 R2 and above) 6 | Turn on "Protect from accidental deletion" 7 | Schedule AD snapshots 8 | DOCUMENT RECOVERY PROCEDURES 9 | TEST RECOVERY PROCEDURES 10 | 11 | #> -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/07 - Recovery/_7_1_Protect from accidental deletion.ps1: -------------------------------------------------------------------------------- 1 | break 2 | 3 | # http://blogs.technet.com/b/askds/archive/2013/06/04/two-lines-that-can-save-your-ad-from-a-crisis.aspx 4 | 5 | # Do this for users, computers, groups, OUs, etc. 6 | 7 | New-ADUser ProtectMe 8 | 9 | # View the property 10 | Get-ADuser ProtectMe -Properties ProtectedFromAccidentalDeletion 11 | 12 | # View ACL on an object 13 | Get-ADUser ProtectMe -Properties NTSecurityDescriptor | 14 | Select-Object -ExpandProperty NTSecurityDescriptor | 15 | Select-Object -ExpandProperty Access | ogv 16 | 17 | # Turn on delete protection 18 | Get-ADUser -Identity ProtectMe | Set-ADObject -ProtectedFromAccidentalDeletion:$true 19 | 20 | # View the property 21 | Get-ADuser ProtectMe -Properties ProtectedFromAccidentalDeletion 22 | 23 | # View new ACL with "Everone/Deny/Delete" 24 | Get-ADUser ProtectMe -Properties NTSecurityDescriptor | 25 | Select-Object -ExpandProperty NTSecurityDescriptor | 26 | Select-Object -ExpandProperty Access | ogv 27 | 28 | 29 | # Now go forth and protect thy kingdom from junior admins everywhere. 30 | Get-ADUser -Filter * | Set-ADObject -ProtectedFromAccidentalDeletion:$true 31 | Get-ADGroup -Filter * | Set-ADObject -ProtectedFromAccidentalDeletion:$true 32 | Get-ADOrganizationalUnit -Filter * | Set-ADObject -ProtectedFromAccidentalDeletion:$true 33 | 34 | # This will make it a pain to script deletions. ERROR. 35 | Remove-ADUser ProtectMe -Confirm:$false 36 | 37 | # Get object, remove protection (with passthru), then delete 38 | Get-ADUser ProtectMe | 39 | Set-ADObject -ProtectedFromAccidentalDeletion:$false -PassThru | 40 | Remove-ADUser -Confirm:$false 41 | 42 | # Now gone 43 | Get-ADUser ProtectMe 44 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/07 - Recovery/_7_2_Recycle Bin.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/MVAPSAD/07 - Recovery/_7_2_Recycle Bin.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/07 - Recovery/_7_3_Attribute Recovery.ps1: -------------------------------------------------------------------------------- 1 | Start-Process "C:\Users\administrator.COHOVINEYARD\Documents\MVA\07 - Recovery\AD Snapshots\" 2 | -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/08 - Deployment/_8_0_DEPLOYMENT.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/MVAPSAD/08 - Deployment/_8_0_DEPLOYMENT.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/08 - Deployment/_8_1_DCPROMO.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | 3 | Install a New Windows Server 2012 Active Directory Forest (Level 200) 4 | http://technet.microsoft.com/en-us/library/jj574166.aspx 5 | 6 | "The Dcpromo.exe remains in Windows Server 2012 for command-line unattended 7 | installations only, and no longer runs the graphical installation wizard. 8 | It is highly recommended that you discontinue use of Dcpromo.exe for 9 | unattended installs and replace it with the ADDSDeployment module, as the 10 | now-deprecated executable will not be included in the next version of Windows." 11 | 12 | #> -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/08 - Deployment/_8_2_ADDSDeployment Module.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/MVAPSAD/08 - Deployment/_8_2_ADDSDeployment Module.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/08 - Deployment/_8_4_Desired State Configuration.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/MVAPSAD/08 - Deployment/_8_4_Desired State Configuration.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/DISCLAIMER.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/ActiveDirectory/MVAPSAD/DISCLAIMER.ps1 -------------------------------------------------------------------------------- /ActiveDirectory/MVAPSAD/README.md: -------------------------------------------------------------------------------- 1 | ##[Microsoft Virtual Academy Using PowerShell for Active Directory](https://www.microsoftvirtualacademy.com/en-US/training-courses/using-powershell-for-active-directory-8397) 2 | -------------------------------------------------------------------------------- /ActiveDirectory/Migrate-ADMTUserSplat.ps1: -------------------------------------------------------------------------------- 1 | $Migrate_UserSplat = @{ 2 | 'SourceDomain' = "hydra.manticore.org" 3 | 'SourceDomainController' = "HDC02.Hydra.manticore.org" 4 | 'SourceOU' = "Users" 5 | 'TargetDomain' = "manticore.org" 6 | 'TargetDomainController' = "dc01.manticore.org" 7 | 'TargetOU' = "Users" 8 | 'SamAccountName' = 'ADMT-User06' 9 | } -------------------------------------------------------------------------------- /ActiveDirectory/Move-ADGroupMemberofToMember.ps1: -------------------------------------------------------------------------------- 1 | function Move-ADGroupMemberofToMember { 2 | <# 3 | .SYNOPSIS 4 | Moves all Member Of objects to the Members section of an Active Directory group. 5 | .DESCRIPTION 6 | Queries an Active Directory group for all Member Of groups then add them to the members section 7 | and removes them from the member of section of the active directory group. 8 | .PARAMETER TargetGroup 9 | Specify the group to run the cmdlet against. 10 | .EXAMPLE 11 | Move-ADGroupMemberOfToMember -TargetGroup GroupTest01 -Verbose 12 | #> 13 | [CmdletBinding()] 14 | param( 15 | [Parameter(Mandatory=$True)] 16 | [string]$TargetGroup 17 | ) 18 | BEGIN { 19 | Write-Verbose -message "Gathering all Member of objects" 20 | $Groups = (Get-ADGroup -Identity $TargetGroup -Properties *).Memberof 21 | } 22 | PROCESS { 23 | foreach ($Group in $Groups) { 24 | Try { 25 | Write-Verbose -message "Adding $Group as member" 26 | Add-ADGroupMember -Identity $TargetGroup -Members $Group 27 | Write-Verbose -message "Removing $Group from Member of" 28 | Remove-ADGroupMember -Identity $Group -Members $TargetGroup -Confirm:$false 29 | } 30 | Catch [Microsoft.ActiveDirectory.Management.ADException] { 31 | Write-Warning -message "$Group was already a member of $TargetGroup" 32 | Write-Verbose -message "Removing $Group from Member of" 33 | Remove-ADGroupMember -Identity $Group -Members $TargetGroup -Confirm:$false 34 | } 35 | } 36 | } 37 | END { 38 | Write-Verbose -message "Migration of Member of to Member complete" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ActiveDirectory/Remove-AccidentalDeletion.ps1: -------------------------------------------------------------------------------- 1 | # Get object, remove protection (with passthru), then delete 2 | Get-ADUser ProtectMe | 3 | Set-ADObject -ProtectedFromAccidentalDeletion:$false -PassThru | 4 | Remove-ADUser -Confirm:$false 5 | -------------------------------------------------------------------------------- /ActiveDirectory/SearchGroupACLs.ps1: -------------------------------------------------------------------------------- 1 | #Slack Test 2 | $Domain = "Domain" 3 | $GroupName = "Enterprise Admins" 4 | $Groups = Get-ADGroup -Filter * -ResultSetSize 5| select DistinguishedName,SamAccountName 5 | 6 | foreach ($Group in $Groups) { 7 | 8 | Try { 9 | $ACL = ((Get-Acl $Group.DistinguishedName -ErrorAction SilentlyContinue).access.IdentityReference).value 10 | if ($ACL -notcontains $Domain +'\'+$GroupName) { 11 | Write-Host $Group.SamAccountName -ForegroundColor Green 12 | } 13 | } Catch [System.Management.Automation.DriveNotFoundException] { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ActiveDirectory/new-globalcatalog.ps1: -------------------------------------------------------------------------------- 1 | #Source Learn Active Directory in a Month of LUnches. 2 | $dc = "dc02.manticore.org" 3 | $contextType = [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::DirectoryServer 4 | 5 | $context = New-Object -TypeName 6 | 7 | System.DirectoryServices.ActiveDirectory.DirectoryContext -ArgumentList $contextType, $dc 8 | 9 | $gc = [System.DirectoryServices.ActiveDirectory.DomainController]::GetDomainController($context) 10 | 11 | $gc.EnableGlobalCatalog() -------------------------------------------------------------------------------- /Classes/File.ps1: -------------------------------------------------------------------------------- 1 | #Figure out enums 2 | Class File { 3 | 4 | #constructor 5 | File($Name,$Path){ 6 | $this.Name = $Name 7 | $this.Path = $Path 8 | } 9 | 10 | #properties 11 | [string]$Name 12 | [string]$Path 13 | [string]$Content 14 | 15 | #method 16 | [void] Create() { 17 | New-Item -Name $this.Name -Path $this.Path 18 | } 19 | 20 | } 21 | 22 | #New-Object -TypeName File -ArgumentList 'ClassTest','C:\temp' 23 | $File = [File]::New('PSClassTest','c:\temp') 24 | $File.Create() 25 | 26 | Get-ChildItem -Path c:\temp -------------------------------------------------------------------------------- /Classes/Group.ps1: -------------------------------------------------------------------------------- 1 | class Group { 2 | [string]$Name 3 | [string]$Manager 4 | [string]$Members 5 | [string]$Domain 6 | 7 | Group () {} 8 | 9 | Group ([string]$Name) { 10 | $this.Name = $Name 11 | } 12 | 13 | [void]GetManager(){ 14 | $this.Manager = (Get-ADGroup -Identity $this.Name -Properties Managedby).Managedby 15 | $this.Manager = $this.Manager -replace "(CN=)(.*?),.*",'$2' 16 | } 17 | 18 | [void]GetMembers(){ 19 | $this.Members = (Get-NestedGroupMember -Group $this.Name).samaccountname 20 | } 21 | 22 | [void]GetDomain(){ 23 | $this.Domain = (Get-ADGroup -Identity $this.Name -Properties CanonicalName).CanonicalName 24 | $this.Domain = ($this.Domain -split "/")[0] 25 | } 26 | 27 | [void]GetGroup(){ 28 | $this.Manager = (Get-ADGroup -Identity $this.Name -Properties Managedby).Managedby 29 | $this.Manager = $this.Manager -replace "(CN=)(.*?),.*",'$2' 30 | $this.Members = (Get-NestedGroupMember -Group $this.Name).samaccountname 31 | $this.Domain = (Get-ADGroup -Identity $this.Name -Properties CanonicalName).CanonicalName 32 | $this.Domain = ($this.Domain -split "/")[0] 33 | } 34 | 35 | } 36 | 37 | $Group = [Group]::New('testgroup') 38 | $Group.GetManager() 39 | $Group.GetMembers() 40 | $Group.GetDomain() -------------------------------------------------------------------------------- /Classes/Helper.ps1: -------------------------------------------------------------------------------- 1 | class Helper 2 | { 3 | [HashTable] Splat([String[]] $Properties) 4 | { 5 | $splat = @{} 6 | 7 | foreach($prop in $Properties) 8 | { 9 | if($this.GetType().GetProperty($prop)) 10 | { 11 | if ($this.$prop){ 12 | $splat.Add($prop, $this.$prop) 13 | } 14 | } 15 | } 16 | 17 | return $splat 18 | } 19 | } 20 | 21 | class Action : Helper 22 | { 23 | [string]$Execute 24 | [string]$Argument 25 | [string]$WorkingDirectory 26 | 27 | Action () 28 | { 29 | 30 | } 31 | } 32 | 33 | function Get-Meaning ($Name, $Answer) 34 | { 35 | "The meaning of {0} is {1}." -f $Name, $Answer 36 | } -------------------------------------------------------------------------------- /Classes/SQLString.ps1: -------------------------------------------------------------------------------- 1 | class SQLString { 2 | 3 | [string]$Database 4 | [string]$ServerName 5 | [string]$ConnectionString 6 | [string]$Query 7 | [string]$Columns 8 | [object]$Values 9 | 10 | SQLString([String]$Database,[String]$ServerName){ 11 | $This.ConnectionString = "server=$($ServerName);database=$($Database);trusted_connection=True" 12 | 13 | } 14 | 15 | [void] SelectQuery($Column,$Table) 16 | { 17 | $This.Query = "Select $Column From $Table" 18 | } 19 | 20 | [void] InsertUserQuery($Table,$Values) 21 | { 22 | $This.Columns = (Get-DatabaseData -connectionString $this.ConnectionString -query "SELECT COLUMN_NAME FROM $($Table_Name).information_schema.columns WHERE table_name = '$($Table)' ORDER BY ORDINAL_POSITION" -isSQLServer).Column_Name 23 | $This.Columns = $This.Columns.Replace(" ",",") 24 | $Test = $this.Columns.Split(",") 25 | 26 | foreach ($t in $test){ 27 | $This.Values += "'"+ (Get-ADUser -Identity $Values -Properties $t).$t +"'"+',' 28 | #$this.Values += "'"+$($t)+"'"+',' 29 | } 30 | $This.Values = $this.Values -replace ".$" 31 | 32 | $This.Query = "INSERT INTO $Table ($($This.Columns)) VALUES ($($This.Values))" 33 | } 34 | 35 | } 36 | $2 = [SQLString]::New('Database','ServerName\SQLInstance') 37 | $2.InsertUserQuery('Table_Name','UserName') 38 | $2 39 | -------------------------------------------------------------------------------- /Classes/ScheduledTask.ps1: -------------------------------------------------------------------------------- 1 | class ScheduledTask { 2 | [string]$TaskName 3 | [CimInstance]$Action 4 | [CimInstance]$Settings 5 | [CimInstance]$Task 6 | 7 | ScheduledTask([string]$TaskName,[string]$Execute) { 8 | $this.TaskName = $TaskName 9 | $this.Action = New-ScheduledTaskAction -Execute $Execute 10 | $this.Settings = New-ScheduledTaskSettingsSet 11 | } 12 | 13 | ScheduledTask([string]$TaskName,[string]$Execute) { 14 | $this.TaskName = $TaskName 15 | $this.Action = New-ScheduledTaskAction -Execute $Execute 16 | $this.Settings = New-ScheduledTaskSettingsSet 17 | } 18 | 19 | ScheduledTask([string]$TaskName,[string]$Execute,[string]$Arguement) { 20 | $this.TaskName = $TaskName 21 | $this.Action = New-ScheduledTaskAction -Execute $Execute -Argument $Arguement 22 | $this.Settings = New-ScheduledTaskSettingsSet 23 | } 24 | 25 | [void]SetTask(){ 26 | $this.Task = New-ScheduledTask -Settings $this.Settings -Action $this.Action 27 | } 28 | 29 | [void]Register(){ 30 | Register-ScheduledTask -TaskName $this.TaskName -InputObject $this.task 31 | } 32 | } 33 | 34 | $NewTask = [ScheduledTask]::New('T6','Taskmgr.exe','-NonInteractive -NoLogo') 35 | $NewTask.SetTask() -------------------------------------------------------------------------------- /Classes/ScheduledTaskv2.ps1: -------------------------------------------------------------------------------- 1 | class ScheduledTask { 2 | [string]$TaskName 3 | [ciminstance]$TaskInstance 4 | 5 | ScheduledTask(){} 6 | 7 | ScheduledTask([string]$TaskName) { 8 | $this.TaskName = $TaskName 9 | } 10 | 11 | ScheduledTask([string]$TaskName,[CimInstance]$TaskInstance) { 12 | $this.TaskName = $TaskName 13 | $this.TaskInstance = $TaskInstance 14 | } 15 | 16 | [void]Register(){ 17 | Register-ScheduledTask -TaskName $this.TaskName -InputObject $this.TaskInstance 18 | } 19 | } 20 | 21 | Class Action : ScheduledTask { 22 | [CimInstance]$ActionInstance 23 | 24 | Action([string]$Execute) { 25 | $this.ActionInstance = New-ScheduledTaskAction -Execute $Execute 26 | } 27 | 28 | Action([string]$Execute,[string]$Arguement) { 29 | $this.ActionInstance = New-ScheduledTaskAction -Execute $Execute -Argument $Arguement 30 | } 31 | 32 | Action([string]$Execute,[string]$Arguement,[string]$WorkingDirectory) { 33 | $this.ActionInstance = New-ScheduledTaskAction -Execute $Execute -Argument $Arguement -WorkingDirectory $WorkingDirectory 34 | } 35 | } 36 | 37 | Class Settings : ScheduledTask { 38 | [CimInstance]$SettingsInstance 39 | 40 | Settings() { 41 | $this.SettingsInstance = New-ScheduledTaskSettingsSet 42 | } 43 | 44 | Settings([bool]$DontStopOnIdleEnd) { 45 | $this.SettingsInstance = New-ScheduledTaskSettingsSet -DontStopOnIdleEnd 46 | } 47 | } 48 | 49 | Class Task : ScheduledTask { 50 | [CimInstance]$TaskInstance 51 | 52 | Task([CimInstance]$Actions,[CimInstance]$Settings) { 53 | $this.TaskInstance = New-ScheduledTask -Settings $Settings -Action $Actions 54 | } 55 | } 56 | 57 | $Action = [Action]::new('powershell.exe','-nologon','C:\scripts') 58 | $Settings = [Settings]::new($true) 59 | $Task = [Task]::New($Action.ActionInstance,$Settings.SettingsInstance) 60 | $ScheduledTask = [ScheduledTask]::new('T1',$Task.TaskInstance) 61 | $ScheduledTask.Register() -------------------------------------------------------------------------------- /Classes/ScheduledTaskv3.ps1: -------------------------------------------------------------------------------- 1 | class ScheduledTask { 2 | [string]$TaskName 3 | [ciminstance]$TaskInstance 4 | 5 | ScheduledTask(){} 6 | 7 | ScheduledTask([string]$TaskName) { 8 | $this.TaskName = $TaskName 9 | } 10 | 11 | ScheduledTask([string]$TaskName,[CimInstance]$TaskInstance) { 12 | $this.TaskName = $TaskName 13 | $this.TaskInstance = $TaskInstance 14 | } 15 | 16 | [void]Register(){ 17 | Register-ScheduledTask -TaskName $this.TaskName -InputObject $this.TaskInstance 18 | } 19 | } 20 | 21 | Class Action : ScheduledTask { 22 | [string]$Execute 23 | [string]$Arguement 24 | [string]$WorkingDirectory 25 | 26 | } 27 | 28 | Class Settings : ScheduledTask { 29 | [CimInstance]$SettingsInstance 30 | 31 | Settings() { 32 | $this.SettingsInstance = New-ScheduledTaskSettingsSet 33 | } 34 | 35 | Settings([bool]$DontStopOnIdleEnd) { 36 | $this.SettingsInstance = New-ScheduledTaskSettingsSet -DontStopOnIdleEnd 37 | } 38 | } 39 | 40 | Class Task : ScheduledTask { 41 | [CimInstance]$TaskInstance 42 | 43 | Task([CimInstance]$Actions,[CimInstance]$Settings) { 44 | $this.TaskInstance = New-ScheduledTask -Settings $Settings -Action $Actions 45 | } 46 | } 47 | 48 | # $Action = [Action]::new('powershell.exe','-nologon','C:\scripts') 49 | # $Settings = [Settings]::new($true) 50 | # $Task = [Task]::New($Action.ActionInstance,$Settings.SettingsInstance) 51 | # $ScheduledTask = [ScheduledTask]::new('T1',$Task.TaskInstance) 52 | # $ScheduledTask.Register() 53 | 54 | $Action = [Action]::new() 55 | $Action.Execute = 'powershell.exe';$Action.Arguement = '-nologon';$Action.WorkingDirectory = 'c:\scripts' -------------------------------------------------------------------------------- /Classes/WineClass.ps1: -------------------------------------------------------------------------------- 1 | Class Wine { 2 | [string]$Name 3 | [string]$Winery 4 | [int32]$Year 5 | [ValidateSet("Red", "White", "Rose")][string]$Color 6 | [Double]$Price = 0.0 7 | 8 | [string]NiceString(){ 9 | $wineName = $this.Name 10 | $WineYear = $this.Year 11 | return "$wineName ($wineyear) is a fine wine." 12 | } 13 | [string]NiceString([int]$Rating) 14 | { 15 | $wineName = $this.Name 16 | $WineYear = $this.Year 17 | return "$wineName ($wineyear) is a fine wine." 18 | } 19 | 20 | Wine ([string]$WineName) 21 | { 22 | $this.Name = $WineName 23 | } 24 | } 25 | 26 | $mywine = [Wine]::New('PoshWine') 27 | $myWine.Winery = 'Omaha' 28 | 29 | $Duck = [Wine]@{ 30 | Winery = 'Escalante Winery'; 31 | Year = 2003; 32 | Color = 'White'; 33 | Price = 32 34 | Name = "Great Duck"; 35 | } -------------------------------------------------------------------------------- /DSC/CredentialEncryptExample.ps1: -------------------------------------------------------------------------------- 1 | Configuration CredentialEncryptExample { 2 | Param ( 3 | [Parameter(Mandatory=$true)] 4 | [PSCredential]$Credential 5 | ) 6 | 7 | Node $AllNodes.NodeName 8 | { 9 | Group TestGroup{ 10 | GroupName = 'TestGroup' 11 | Members = 'source\jduffney' 12 | Ensure = 'Present' 13 | Credential = $Credential 14 | } 15 | } 16 | 17 | LocalConfigurationManager { 18 | CertificateID = $node.Thumbprint 19 | } 20 | } 21 | 22 | $configdata = @{ 23 | AllNodes = @( 24 | @{ 25 | NodeName = 'S3' 26 | PSDSCAllowPlainTextPassword = $false 27 | Certificatefile = 'c:\Certs\S3.cer' 28 | Thumbprint = 'BB791ED7FD50ADA3C38C5CBB28F8888CB34D717F' 29 | } 30 | ) 31 | } 32 | 33 | CredentialEncryptExample -configurationdata $configdata ` 34 | -Credential (Get-Credential -Message 'Enter Credential for configuration') 35 | 36 | Set-DscLocalConfigurationManager -Path c:\DSC\CredentialEncryptExample -ComputerName S3 -Verbose 37 | 38 | Start-DscConfiguration -Path c:\DSC\CredentialEncryptExample -ComputerName S3 -Wait -Verbose -------------------------------------------------------------------------------- /DSC/DSCBookCodeSnippets/LCMConfig.ps1: -------------------------------------------------------------------------------- 1 | [DSCLocalConfigurationManager()] 2 | 3 | Configuration LCM_Pull { 4 | 5 | Node Pull { 6 | 7 | Settings { 8 | ConfigurationMode = 'ApplyAndAutoCorrect' 9 | RefreshMode = 'Pull' 10 | } 11 | 12 | ConfigurationRepositoryWeb PullServer { 13 | ServerURL = 'https://pull:8080/PsDscPullserver.svc' 14 | AllowUnsecureConnection = $false 15 | RegistrationKey = 'ff7e4129-5c8a-4f23-bbeb-30a85aafb708' 16 | ConfigurationNames = @('WebServerConfig') 17 | } 18 | 19 | ResourceRepositoryWeb PullServerModules { 20 | ServerURL = 'https://pull:8080/PsDscPullserver.svc' 21 | AllowUnsecureConnection = $false 22 | RegistrationKey = 'ff7e4129-5c8a-4f23-bbeb-30a85aafb708' 23 | } 24 | } 25 | } 26 | 27 | LCM_Pull 28 | 29 | Set-DscLocalConfigurationManager -ComputerName pull -Path .\LCM_Pull -Verbose -Force 30 | 31 | Update-DscConfiguration -ComputerName pull -Verbose -Wait 32 | 33 | -------------------------------------------------------------------------------- /DSC/DSCBookCodeSnippets/LCM_Pull/Pull.meta.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/DSCBookCodeSnippets/LCM_Pull/Pull.meta.mof -------------------------------------------------------------------------------- /DSC/DSCBookCodeSnippets/ParisTZ.ps1: -------------------------------------------------------------------------------- 1 | Configuration ParisTZ { 2 | 3 | Import-DscResource -ModuleName "xTimeZone" -ModuleVersion "1.6.0.0" 4 | 5 | Node TimeZoneConfig { 6 | 7 | xTimeZone Paris { 8 | IsSingleInstance = 'Yes' 9 | TimeZone = 'Central European Standard Time' 10 | } 11 | } 12 | } 13 | 14 | ParisTZ 15 | 16 | new-dscchecksum -path ./ParisTZ/TimeZoneConfig.mof -------------------------------------------------------------------------------- /DSC/DSCBookCodeSnippets/WebServer.ps1: -------------------------------------------------------------------------------- 1 | Configuration WebServer { 2 | 3 | Import-DscResource -ModuleName 'PSDesiredStateConfiguration' 4 | Import-DscResource -ModuleName "xWebAdministration" 5 | 6 | Node WebServerConfig { 7 | 8 | WindowsFeature WindowsServer { 9 | Name = 'Web-Server' 10 | } 11 | 12 | File GlobomanticsPath { 13 | DestinationPath = $env:SystemDrive+'\Globomantics' 14 | Type = 'Directory' 15 | Ensure = 'Present' 16 | } 17 | 18 | xWebVirtualDirectory Globomantics { 19 | Name = 'Globomantics' 20 | PhysicalPath = $env:SystemDrive+'\Globomantics' 21 | WebApplication = '' 22 | Website = 'Default Web Site' 23 | Ensure = 'Present' 24 | DependsOn = '[File]GlobomanticsPath' 25 | } 26 | } 27 | } 28 | 29 | WebServer -OutputPath $env:SystemDrive'\dsc\WebServer' 30 | 31 | new-dscchecksum -path $env:SystemDrive'\dsc\WebServer\WebServerConfig.mof' -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/DomainController/Assert-DCVM.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## Setup a VM for DC and DHCP role 3 | ## 4 | Configuration DCVM 5 | { 6 | Node "localhost" 7 | { 8 | OptionalFeature HyperV 9 | { 10 | Ensure = "Present" 11 | Name = "Microsoft-Hyper-V-All" 12 | } 13 | 14 | VMSwitch VirtualSwitch 15 | { 16 | Ensure = "Present" 17 | Name = "Internal" 18 | Type = "Internal" 19 | Requires = "[OptionalFeature]HyperV" 20 | } 21 | 22 | File VhdParentFile 23 | { 24 | Ensure = "Present" 25 | DestinationPath = "C:\Demo\VHD\Library\LibDC.vhd" 26 | Type = "File" 27 | Requires = "[OptionalFeature]HyperV" 28 | } 29 | 30 | File VHDFolder 31 | { 32 | Ensure = "Present" 33 | DestinationPath = "C:\Demo\VHD" 34 | Type = "Directory" 35 | Requires = "[File]VHDParentFile" 36 | } 37 | 38 | VHD DCVhd 39 | { 40 | Ensure = "Present" 41 | Name = "DC" 42 | Path = "C:\Demo\VHD" 43 | ParentPath = "C:\Demo\VHD\Library\LibDC.vhd" 44 | Requires = @("[OptionalFeature]HyperV", 45 | "[File]VHDFolder") 46 | } 47 | 48 | VM DCVM 49 | { 50 | Ensure = "Present" 51 | Name = "DC" 52 | VhDPath = "C:\Demo\VHD\DC" 53 | SwitchName = "Internal" 54 | StartupMemoryMB = 1024 55 | State = "Running" 56 | WaitForIP = $true 57 | Requires = @("[OptionalFeature]HyperV", 58 | "[VMSwitch]VirtualSwitch", 59 | "[VHD]DCVhd") 60 | } 61 | } 62 | } 63 | 64 | # Create the MOF file for the configuration 65 | DCVM 66 | 67 | # Make it happen 68 | Start-DSCConfiguration -Path $PSScriptRoot\DCVM -Wait -Verbose -Force -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/DomainController/Assert-Network.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## Sets the networking between DC VM and Hyper-V Host 3 | ## 4 | Configuration Network 5 | { 6 | # Find the DCVM ipaddress dynamically, 7 | # since we don't know the VM IPAddress a priori. 8 | Node (Get-VMIPAddress DC) 9 | { 10 | $Node = Get-VMIPAddress DC 11 | IPAddress DCNetwork 12 | { 13 | Ensure = "Present" 14 | IPAddress = "192.168.10.1" 15 | InterfaceAlias = "*Ethernet*" 16 | PrefixLength = 24 17 | DefaultGateway = "192.168.10.1" 18 | } 19 | } 20 | 21 | Node "Localhost" 22 | { 23 | IPAddress LocalNetwork 24 | { 25 | Ensure = "Present" 26 | IPAddress = "192.168.10.2" 27 | InterfaceAlias = "*vEthernet*" 28 | PrefixLength = 24 29 | DefaultGateway = "192.168.10.1" 30 | } 31 | } 32 | } 33 | 34 | # Create the MOF file for the configuration 35 | Network 36 | 37 | # Make it happen for DC first and then localhost 38 | $dcIP = Get-VMIPAddress DC 39 | Start-DSCConfiguration -Path $PSScriptRoot\Network -Wait -Verbose -ComputerName $dcIP 40 | Start-DSCConfiguration -Path $PSScriptRoot\Network -Wait -Verbose -ComputerName localhost -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/About.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Page.Title = "About Us"; 3 | } 4 | 14 |
15 |

A little bit about Fourth Coffee

16 |

17 | Fourth Coffee was founded in 2010 and delivers coffee and fresh baked goods right to your door. 18 | In another life, Bill Baker was a developer by day and pastry chef by night. 19 | But soon Bill's innate skills with all things involving butter, flour and sugar put him 20 | even more in demand than his programming talents and what started out as a way to satisfy 21 | his own sweet tooth became all-consuming. Fourth Coffee is not only a candy-coated wonderland 22 | of coffee, pastries, cookies and cakes, it also honors his tech background by employing a state 23 | of the art online ordering system that makes it easy for anybody with internet access to 24 | order his all natural, locally-sourced confections and have them delivered to their 25 | door within 24 hours. 26 |

27 |
28 | -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/App_Data/bakery.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/App_Data/bakery.sdf -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/App_Data/packages/microsoft-web-helpers.1.0/microsoft-web-helpers.1.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/App_Data/packages/microsoft-web-helpers.1.0/microsoft-web-helpers.1.0.nupkg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Default.cshtml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Default.cshtml -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/bread.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/bread.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/carrot_cake.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/carrot_cake.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/chocolate_cake.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/chocolate_cake.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/cupcakes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/cupcakes.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/lemon_tart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/lemon_tart.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/pear_tart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/Thumbnails/pear_tart.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/bread.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/bread.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/carrot_cake.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/carrot_cake.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/chocolate_cake.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/chocolate_cake.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/cupcakes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/cupcakes.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/lemon_tart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/lemon_tart.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/pear_tart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Products/pear_tart.jpg -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/Thumbs.db -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/bkg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/bkg.png -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/brand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Images/brand.png -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/OrderSuccess.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Page.Title = "Order Succeeded!"; 3 | var emailNotSetUp = Request["NoEmail"] != null; 4 | } 5 |
    6 |
  1. 1Choose Item
  2. 7 |
  3. 2Details & Submit
  4. 8 |
  5. 3Receipt
  6. 9 |
10 |

Order Confirmation

11 | 12 | @if (emailNotSetUp) { 13 |
14 |

Please set up Mail!

15 |

Please set your Hotmail Username, Password, and From Address in Order.cshtml to send mail

16 |
17 | } else { 18 |
19 |

Thank you for your order!

20 |

We are processing your order and have sent a confirmation email. Thank you for your business and enjoy!

21 |
22 | } 23 | 24 | -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Website/Images/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/Website/Images/Thumbs.db -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/_PageStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/_SiteLayout.cshtml"; 3 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/_SiteLayout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Fourth Coffee - Bakery 6 | 7 | 8 | 9 | 10 |
11 | 18 |
19 | @RenderBody() 20 |
21 | 24 |
25 | 26 | -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/Microsoft.Web.Helpers.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/Microsoft.Web.Helpers.dll -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/Microsoft.Web.Infrastructure.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/Microsoft.Web.Infrastructure.dll -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/System.Web.Razor.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/System.Web.Razor.dll -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/System.Web.WebPages.Deployment.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/System.Web.WebPages.Deployment.dll -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/System.Web.WebPages.Razor.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/System.Web.WebPages.Razor.dll -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/System.Web.WebPages.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/bin/System.Web.WebPages.dll -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/favicon.ico -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/BakeryWebsite/robots.txt: -------------------------------------------------------------------------------- 1 | 2 | # WebMatrix 1.0 3 | -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Get-VMIP/Get-VMIP.psm1: -------------------------------------------------------------------------------- 1 | function Get-VMIPAddress 2 | { 3 | param 4 | ( 5 | [Parameter(Mandatory)] 6 | [string]$Name 7 | ) 8 | 9 | $ErrorActionPreference = "SilentlyContinue" 10 | 11 | $vm = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem | ? ElementName -eq $Name 12 | $vm.GetRelated("Msvm_KvpExchangeComponent").GuestIntrinsicExchangeItems | % ` 13 | { 14 | $GuestExchangeItemXml = ([XML]$_).SelectSingleNode("/INSTANCE/PROPERTY[@NAME='Name']/VALUE[child::text()='NetworkAddressIPv4']") 15 | if ($GuestExchangeItemXml) 16 | { 17 | $GuestExchangeItemXml.SelectSingleNode("/INSTANCE/PROPERTY[@NAME='Data']/VALUE/child::text()").Value 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_Computer/Demo_Computer.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | # RootModule = '' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '1.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'a280c1e4-9b60-4074-b280-36aede287b1f' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2013 Microsoft Corporation. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '4.0' 26 | 27 | # Minimum version of the common language runtime (CLR) required by this module 28 | CLRVersion = '4.0' 29 | 30 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 31 | NestedModules = @("Demo_Computer.psm1") 32 | 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_Computer/Demo_Computer.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("Computer")] 2 | class Demo_Computer : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string Name; 5 | [Write] string DomainName; 6 | [Write,EmbeddedInstance("MSFT_Credential")] string Credential; 7 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 8 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_DCPromo/Demo_DCPromo.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | # RootModule = '' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '1.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'a280c1e4-9b60-4074-b280-36aede287b1f' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2013 Microsoft Corporation. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '4.0' 26 | 27 | # Minimum version of the common language runtime (CLR) required by this module 28 | CLRVersion = '4.0' 29 | 30 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 31 | NestedModules = @("Demo_DCPromo.psm1") 32 | 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_DCPromo/Demo_DCPromo.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("DCPromo")] 2 | class Demo_DCPromo : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string DomainName; 5 | [Key,EmbeddedInstance("MSFT_Credential")] string SafeModeAdministratorPassword; 6 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 7 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_DHCPOption/Demo_DHCPOption.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | # RootModule = '' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '1.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'a280c1e4-9b60-4074-b280-36aede287b1f' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2013 Microsoft Corporation. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '4.0' 26 | 27 | # Minimum version of the common language runtime (CLR) required by this module 28 | CLRVersion = '4.0' 29 | 30 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 31 | NestedModules = @("Demo_DHCPOption.psm1") 32 | 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_DHCPOption/Demo_DHCPOption.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("DHCPOption")] 2 | class Demo_DHCPOption : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string DNSServerName; 5 | [Key] string DomainName; 6 | [Key] string Router; 7 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 8 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_DHCPScope/Demo_DHCPScope.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | # RootModule = '' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '1.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'a280c1e4-9b60-4074-b280-36aede287b1f' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2013 Microsoft Corporation. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '4.0' 26 | 27 | # Minimum version of the common language runtime (CLR) required by this module 28 | CLRVersion = '4.0' 29 | 30 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 31 | NestedModules = @("Demo_DHCPScope.psm1") 32 | 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_DHCPScope/Demo_DHCPScope.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("DHCPScope")] 2 | class Demo_DHCPScope: MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string Name; 5 | [Key] string ID; 6 | [Key] string StartRange; 7 | [Key] string EndRange; 8 | [write] string SubnetMask; 9 | [write] uint32 LeaseDurationDays; 10 | [write,ValueMap{"Bootp", "Both", "Dhcp"},Values{"Bootp", "Both", "Dhcp"}] string Type; 11 | [write,ValueMap{"Active", "InActive"},Values{"Active", "Inactive"}] string State; 12 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 13 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_DHCPServerInDC/Demo_DHCPServerInDC.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | # RootModule = '' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '1.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'a280c1e4-9b60-4074-b280-36aede287b1f' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2013 Microsoft Corporation. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '4.0' 26 | 27 | # Minimum version of the common language runtime (CLR) required by this module 28 | CLRVersion = '4.0' 29 | 30 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 31 | NestedModules = @("Demo_DHCPServerInDC.psm1") 32 | 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_DHCPServerInDC/Demo_DHCPServerInDC.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("DHCPServerInDC")] 2 | class Demo_DHCPServerInDC : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string DNSName; 5 | [Key] string IPAddress; 6 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 7 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_IISWebsite/Demo_IISWebsite.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'Demo.IIS.Website' 3 | # 4 | # Generated on: 1/10/2013 5 | # 6 | 7 | @{ 8 | 9 | # Script module or binary module file associated with this manifest. 10 | # RootModule = '' 11 | 12 | # Version number of this module. 13 | ModuleVersion = '1.0' 14 | 15 | # ID used to uniquely identify this module 16 | GUID = '6AB5ED33-E923-41d8-A3A4-5ADDA2B301DE' 17 | 18 | # Author of this module 19 | Author = 'Contoso' 20 | 21 | # Company or vendor of this module 22 | CompanyName = 'Contoso' 23 | 24 | # Copyright statement for this module 25 | Copyright = '(c) 2013 Contoso. All rights reserved.' 26 | 27 | # Description of the functionality provided by this module 28 | Description = 'This Module is used to support the creation and configuration of IIS Websites through Get, Set and Test API on the DSC managed nodes.' 29 | 30 | # Minimum version of the Windows PowerShell engine required by this module 31 | PowerShellVersion = '4.0' 32 | 33 | # Minimum version of the common language runtime (CLR) required by this module 34 | CLRVersion = '4.0' 35 | 36 | # Modules that must be imported into the global environment prior to importing this module 37 | # RequiredModules = @("WebAdministration") 38 | 39 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 40 | NestedModules = @("Demo_IISWebsite.psm1") 41 | 42 | # Functions to export from this module 43 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 44 | 45 | # Cmdlets to export from this module 46 | #CmdletsToExport = '*' 47 | 48 | # HelpInfo URI of this module 49 | # HelpInfoURI = '' 50 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_IISWebsite/Demo_IISWebsite.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_IISWebsite/Demo_IISWebsite.schema.mof -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_IPAddress/Demo_IPAddress.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | # RootModule = '' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '1.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'a280c1e4-9b60-4074-b280-36aede287b1f' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2013 Microsoft Corporation. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '4.0' 26 | 27 | # Minimum version of the common language runtime (CLR) required by this module 28 | CLRVersion = '4.0' 29 | 30 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 31 | NestedModules = @("Demo_IPAddress.psm1") 32 | 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_IPAddress/Demo_IPAddress.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("IPAddress")] 2 | class Demo_IPAddress : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string IPAddress; 5 | [Key] string InterfaceAlias; 6 | [write] string DefaultGateway; 7 | [Write] uint32 PrefixLength; 8 | [Write,ValueMap{"IPv4", "IPv6"},Values{"IPv4", "IPv6"}] string AddressFamily; 9 | [Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 10 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_OptionalFeature/Demo_OptionalFeature.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'MSFT_OptionalFeature' 3 | # 4 | # Generated on: 12/17/2012 5 | # 6 | 7 | @{ 8 | 9 | # Script module or binary module file associated with this manifest. 10 | # RootModule = '' 11 | 12 | # Version number of this module. 13 | ModuleVersion = '1.0' 14 | 15 | # ID used to uniquely identify this module 16 | GUID = 'b005fca4-1c69-46cd-ae3a-4c5d3d5c6d7d' 17 | # Author of this module 18 | Author = 'Microsoft Corporation' 19 | # Company or vendor of this module 20 | CompanyName = 'Microsoft Corporation' 21 | # Copyright statement for this module 22 | Copyright = '(c) 2012 Microsoft Corporation. All rights reserved.' 23 | # Description of the functionality provided by this module 24 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 25 | 26 | # Minimum version of the Windows PowerShell engine required by this module 27 | PowerShellVersion = '4.0' 28 | 29 | # Minimum version of the common language runtime (CLR) required by this module 30 | CLRVersion = '4.0' 31 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 32 | NestedModules = @("Demo_OptionalFeature.psm1") 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_OptionalFeature/Demo_OptionalFeature.psm1: -------------------------------------------------------------------------------- 1 | # 2 | # Generated using tool 3 | # Powershell resource provider for DSC tests. 4 | # 5 | # 6 | # The Get-TargetResource cmdlet. 7 | # 8 | function Get-TargetResource 9 | { 10 | param 11 | ( 12 | 13 | [parameter(Mandatory = $true)] 14 | [ValidateNotNullOrEmpty()] 15 | [System.String] 16 | $Name, 17 | 18 | [System.String] 19 | $Ensure 20 | ) 21 | # Add the logic here and at the end return hashtable of properties. 22 | } 23 | # 24 | # The Set-TargetResource cmdlet. 25 | # 26 | function Set-TargetResource 27 | { 28 | param 29 | ( 30 | 31 | [parameter(Mandatory = $true)] 32 | [ValidateNotNullOrEmpty()] 33 | [System.String] 34 | $Name, 35 | 36 | [System.String] 37 | [ValidateSet("Present","Absent")] 38 | $Ensure="Present" 39 | ) 40 | # Add the logic here. 41 | if($Ensure -eq "Present") 42 | { 43 | Write-Verbose -Message "Enabling feature $Name ..." 44 | Enable-WindowsOptionalFeature -FeatureName $Name -Online -Verbose:$false 45 | Write-Verbose -Message "Feature $Name enabled" 46 | } 47 | else 48 | { 49 | Write-Verbose -Message "Disabling feature $Name ..." 50 | Disable-WindowsOptionalFeature -FeatureName $Name -Online -Verbose:$false 51 | Write-Verbose -Message "Feature $Name disabled" 52 | } 53 | } 54 | # 55 | # The Test-TargetResource cmdlet. 56 | # 57 | function Test-TargetResource 58 | { 59 | param 60 | ( 61 | 62 | [parameter(Mandatory = $true)] 63 | [ValidateNotNullOrEmpty()] 64 | [System.String] 65 | $Name, 66 | 67 | [System.String] 68 | [ValidateSet("Present","Absent")] 69 | $Ensure = "Present" 70 | ) 71 | # Add the logic here and at the end return either $true or $false. 72 | If($Ensure -eq "Present"){$State = "Enabled"} 73 | else{$State = "Disabled"} 74 | try 75 | { 76 | Write-Verbose -Message "Checking if $Name feature is $State ..." 77 | $feature = Get-WindowsOptionalFeature -Online -FeatureName $Name -Verbose:$false 78 | Write-Verbose -Message "$Name feature is $($feature.State)" 79 | ($feature.State -eq $State) 80 | } 81 | catch 82 | { 83 | Write-Error -Message "Cannot find feature $Name" 84 | ($Ensure -ne "Present") 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_OptionalFeature/Demo_OptionalFeature.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("OptionalFeature")] 2 | class Demo_OptionalFeature : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string Name; 5 | [write,ValueMap{"Present","Absent"},Values{"Present","Absent"}] string Ensure; 6 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_VHD/Demo_VHD.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'MSFT_VM' 3 | # 4 | # Generated on: 12/17/2012 5 | # 6 | 7 | @{ 8 | 9 | # Script module or binary module file associated with this manifest. 10 | # RootModule = '' 11 | 12 | # Version number of this module. 13 | ModuleVersion = '1.0' 14 | 15 | # ID used to uniquely identify this module 16 | GUID = '9911117d-a186-4e3a-8539-f920d5f91d43' 17 | # Author of this module 18 | Author = 'Microsoft Corporation' 19 | # Company or vendor of this module 20 | CompanyName = 'Microsoft Corporation' 21 | # Copyright statement for this module 22 | Copyright = '(c) 2012 Microsoft Corporation. All rights reserved.' 23 | # Description of the functionality provided by this module 24 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 25 | 26 | # Minimum version of the Windows PowerShell engine required by this module 27 | PowerShellVersion = '4.0' 28 | 29 | # Minimum version of the common language runtime (CLR) required by this module 30 | CLRVersion = '4.0' 31 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 32 | NestedModules = @("Demo_VHD.psm1") 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_VHD/Demo_VHD.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("VHD")] 2 | class Demo_VHD : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string Name; 5 | [write] string Path; 6 | [write] string ParentPath; 7 | [write,ValueMap{"Present","Absent"},Values{"Present", "Absent"}] string Ensure; 8 | [read] string Format; 9 | [read] string Type; 10 | [read] uint32 Size; 11 | [read] uint32 TotalSize; 12 | [read] boolean Attached; 13 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_VM/Demo_VM.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'MSFT_VM' 3 | # 4 | # Generated on: 12/17/2012 5 | # 6 | 7 | @{ 8 | 9 | # Script module or binary module file associated with this manifest. 10 | # RootModule = '' 11 | 12 | # Version number of this module. 13 | ModuleVersion = '1.0' 14 | 15 | # ID used to uniquely identify this module 16 | GUID = '9911117d-a186-4e3a-8539-f920d5f91d43' 17 | # Author of this module 18 | Author = 'Microsoft Corporation' 19 | # Company or vendor of this module 20 | CompanyName = 'Microsoft Corporation' 21 | # Copyright statement for this module 22 | Copyright = '(c) 2012 Microsoft Corporation. All rights reserved.' 23 | # Description of the functionality provided by this module 24 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 25 | 26 | # Minimum version of the Windows PowerShell engine required by this module 27 | PowerShellVersion = '4.0' 28 | 29 | # Minimum version of the common language runtime (CLR) required by this module 30 | CLRVersion = '4.0' 31 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 32 | NestedModules = @("Demo_VM.psm1") 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_VM/Demo_VM.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("VM")] 2 | class Demo_VM : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string Name; 5 | [Key] string VhDPath; 6 | [Key] string SwitchName; 7 | [Write] boolean WaitForIP; 8 | [write] uint32 StartupMemoryMB; 9 | [write,ValueMap{"Running","Paused","Off"},Values{"Running","Paused","Off"}] string State; 10 | [write,ValueMap{"Present","Absent"},Values{"Present","Absent"}] string Ensure; 11 | [read] uint32 Id; 12 | [read] string Status; 13 | [read] uint32 CPUUsage; 14 | [read] real32 MemoryAssigned; 15 | [read] real32 MemoryStartup; 16 | [read] string Uptime; 17 | [read] datetime Creationtime; 18 | [read] boolean DynamicMemoryEnabled; 19 | [read] uint32 ProcessorCount; 20 | [read] string NetworkAdapters[]; 21 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_VMSwitch/Demo_VMSwitch.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'MSFT_VMSwitch' 3 | # 4 | # Generated on: 12/17/2012 5 | # 6 | 7 | @{ 8 | 9 | # Script module or binary module file associated with this manifest. 10 | # RootModule = '' 11 | 12 | # Version number of this module. 13 | ModuleVersion = '1.0' 14 | 15 | # ID used to uniquely identify this module 16 | GUID = 'a280c1e4-9b60-4074-b280-36aede287b1f' 17 | # Author of this module 18 | Author = 'Microsoft Corporation' 19 | # Company or vendor of this module 20 | CompanyName = 'Microsoft Corporation' 21 | # Copyright statement for this module 22 | Copyright = '(c) 2012 Microsoft Corporation. All rights reserved.' 23 | # Description of the functionality provided by this module 24 | Description = 'This Module is used to support the execution of query, install & uninstall functionalities on Windows features through Get, Set and Test API on the DSC managed nodes.' 25 | 26 | # Minimum version of the Windows PowerShell engine required by this module 27 | PowerShellVersion = '4.0' 28 | 29 | # Minimum version of the common language runtime (CLR) required by this module 30 | CLRVersion = '4.0' 31 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 32 | NestedModules = @("Demo_VMSwitch.psm1") 33 | # Functions to export from this module 34 | FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource") 35 | 36 | # Cmdlets to export from this module 37 | #CmdletsToExport = '*' 38 | 39 | # HelpInfo URI of this module 40 | 41 | # HelpInfoURI = '' 42 | } -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PreReq/Resources/Demo_VMSwitch/Demo_VMSwitch.schema.mof: -------------------------------------------------------------------------------- 1 | [version("1.0.0"), FriendlyName("VMSwitch")] 2 | class Demo_VMSwitch : MSFT_BaseResourceConfiguration 3 | { 4 | [Key] string Name; 5 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 6 | [write,ValueMap{"Internal", "Private"},Values{"Internal", "Private"}] string Type; 7 | [read] boolean AllowManagementOS; 8 | }; -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Configuration/8cac052d-d3d4-423e-b088-f93979094d11.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Configuration/8cac052d-d3d4-423e-b088-f93979094d11.mof -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Configuration/8cac052d-d3d4-423e-b088-f93979094d11.mof.checksum: -------------------------------------------------------------------------------- 1 | 4d3z0JUeILuuNsQtP5J4bgJwx1QrX0kNEnqArs4l3hA= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Configuration/e349d5e6-337b-48e6-b381-6dcc4d707750.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Configuration/e349d5e6-337b-48e6-b381-6dcc4d707750.mof -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Configuration/e349d5e6-337b-48e6-b381-6dcc4d707750.mof.checksum: -------------------------------------------------------------------------------- 1 | 4d3z0JUeILuuNsQtP5J4bgJwx1QrX0kNEnqArs4l3hA= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_Computer.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_Computer.zip -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_Computer.zip.checksum: -------------------------------------------------------------------------------- 1 | CqiMnIsuZ+xTtUKoxdQriOgOVWFM5xMn0hEMpB995jM= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DCPromo.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DCPromo.zip -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DCPromo.zip.checksum: -------------------------------------------------------------------------------- 1 | aig4Jm5xSEWMLNZ1aNUvqssIKJ0VND4RGja2g83WBwI= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPOption.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPOption.zip -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPOption.zip.checksum: -------------------------------------------------------------------------------- 1 | MNEXClM4lhHfkHYS4nwupPSmfJcimSgcB7j1mm6uvqk= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPScope.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPScope.zip -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPScope.zip.checksum: -------------------------------------------------------------------------------- 1 | vgHR2rUMGkCDHH8nmAqDAhCyx/YRpBLu0P7BhKc/qMc= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPServerInDC.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPServerInDC.zip -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_DHCPServerInDC.zip.checksum: -------------------------------------------------------------------------------- 1 | 5jH1/JZtEiJsmHXzbEZm+Q2aXQi+ZURAko0f+36BEIY= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_IISWebsite.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_IISWebsite.zip -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_IISWebsite.zip.checksum: -------------------------------------------------------------------------------- 1 | WWRi49xVm3dpGMkzIwIi5nCYpT9PnODd1R3wWh+GJn0= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_IPAddress.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_IPAddress.zip -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Content/Modules/Demo_IPAddress.zip.checksum: -------------------------------------------------------------------------------- 1 | tzhN2JvZmf+cEB7MxtPaZCAHlv2DyYLX0ZzR5hccwS0= -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Invoke-PullonNode.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory)] 4 | [String[]]$ComputerName, 5 | 6 | [ValidateRange(1,3)] 7 | [uint32]$flag = 3 8 | ) 9 | 10 | Invoke-CimMethod -ComputerName $ComputerName -Namespace root/microsoft/windows/desiredstateconfiguration ` 11 | -Class MSFT_DscLocalConfigurationManager -MethodName ConsistencyCheck ` 12 | -Arguments @{Flags=[uint32]$flag} -Verbose -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/PullServer/Setup/Scripts/PSWSIISEndpoint.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duffney/PowerShell/bad34bc7fef823d216720e14580a2cbe8bc1fe06/DSC/Demo_WindowServer2012R2/PullServer/Setup/Scripts/PSWSIISEndpoint.psm1 -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/ReadMe.txt: -------------------------------------------------------------------------------- 1 | # Run the demos from elevated PowerShell/ISE 2 | # Set-ExecutionPolicy to run .ps1 files (Set-ExecutionPolicy RemoteSigned -Force) 3 | # On client (windows 8.1): Turn on WSMan (Enable-PSRemoting -force) 4 | # Set WSMan trusted host to * (Set-Item WSMan:\localhost\Client\TrustedHosts * -Force) 5 | 6 | # Copy applicable custom DSC resources (in \PreReq\Resources folder) to $pshome\Modules on the nodes 7 | # * On the machine where configurations are authored, copy all the custom DSC resources 8 | # * On the WebServers, copy Demo_Computer and Demo_IISWebsite resources 9 | # * On the Domain controller, copy Demo_Computer, Demo_DCPromo, Demo_DHCPOption, Demo_DHCPScope, Demo_DHCPServerinDC resources 10 | # * On the Hyper-V host, copy Demo_OptionalFeature, Demo_VHD, Demo_VM, Demo_VMSwitch resources 11 | 12 | # Copy Get-VMIP and WebVM modules (in \PreReq folder) to PowerShell module path ($env:PSModulePath) 13 | # Copy website content folder ( \PreReq\BakeryWebsite folder) to webservers C: drive 14 | 15 | # For Pull Server setup 16 | # * Currently, works only on Full-Server SKU 17 | # * Invoke the InstallPullServerConfig.ps1 -DSCServiceSetup (in \PullServer\Setup\Scripts folder) from elevated prompt on Pull Server 18 | # * On successful completion of above script, copy the PullServer content (in \PullServer\Content folder) to C:\ProgramData\PSDSCPullServer folder of the Pull Server node -------------------------------------------------------------------------------- /DSC/Demo_WindowServer2012R2/Website/Assert-Website1.ps1: -------------------------------------------------------------------------------- 1 | ## 2 | ## Configures a node to be web server 3 | ## 4 | Configuration FourthCoffeeWebsite 5 | { 6 | Node ("WebServer1","WebServer2") 7 | { 8 | # Install the IIS role 9 | WindowsFeature IIS 10 | { 11 | Ensure = "Present" 12 | Name = "Web-Server" 13 | } 14 | 15 | # Install the ASP .NET 4.5 role 16 | WindowsFeature AspNet45 17 | { 18 | Ensure = "Present" 19 | Name = "Web-Asp-Net45" 20 | } 21 | } 22 | } 23 | 24 | # Create the MOF file using the configuration data 25 | FourthCoffeeWebSite 26 | 27 | # Make it happen - Copy the MOF files to appropriate nodes and invoke the configuration 28 | Start-DscConfiguration -Path $PSScriptRoot\FourthCoffeeWebsite -Wait -Verbose -Force -------------------------------------------------------------------------------- /DSC/GenPullServerCert.ps1: -------------------------------------------------------------------------------- 1 | $inf = @" 2 | [Version] 3 | Signature="`$Windows NT`$" 4 | 5 | [NewRequest] 6 | Subject = "CN=Pull, OU='IT, O=Globomantics, L=Omaha, S=NE, C=US" 7 | KeySpec = 1 8 | KeyLength = 2048 9 | Exportable = TRUE 10 | FriendlyName = PSDSCPullServerCert 11 | MachineKeySet = TRUE 12 | SMIME = False 13 | PrivateKeyArchive = FALSE 14 | UserProtected = FALSE 15 | UseExistingKeySet = FALSE 16 | ProviderName = "Microsoft RSA SChannel Cryptographic Provider" 17 | ProviderType = 12 18 | RequestType = PKCS10 19 | KeyUsage = 0xa0 20 | "@ 21 | 22 | $infFile = 'C:\temp\certrq.inf' 23 | $requestFile = 'C:\temp\request.req' 24 | $CertFileOut = 'c:\temp\certfile.cer' 25 | 26 | mkdir c:\temp 27 | $inf | Set-Content -Path $infFile 28 | 29 | & certreq.exe -new "$infFile" "$requestFile" 30 | 31 | & certreq.exe -submit -config Pull.globomantics.com\globomantics-PULL-CA -attrib "CertificateTemplate:WebServer" "$requestFile" "$CertFileOut" 32 | 33 | & certreq.exe -accept "$CertFileOut" -------------------------------------------------------------------------------- /DSC/HTTPSPull.ps1: -------------------------------------------------------------------------------- 1 | configuration HTTPSPull 2 | { 3 | param 4 | ( 5 | [string]$IPAddress, 6 | [string]$DefaultGateway, 7 | [string]$TimeZone = 'Central Standard Time' 8 | 9 | 10 | ) 11 | 12 | Import-DscResource -ModuleName xActiveDirectory,xPSDesiredStateConfiguration,xNetworking,xComputerManagement,xTimeZone 13 | 14 | node $AllNodes.Where{$_.Role -eq "HTTPSPull"}.NodeName 15 | { 16 | xTimeZone SystemTimeZone { 17 | TimeZone = $TimeZone 18 | IsSingleInstance = 'Yes' 19 | 20 | } 21 | 22 | xIPAddress NewIPAddress 23 | { 24 | IPAddress = $Node.IPAddress 25 | InterfaceAlias = "Ethernet" 26 | SubnetMask = 24 27 | AddressFamily = "IPV4" 28 | 29 | } 30 | 31 | xDefaultGatewayAddress NewDefaultGateway 32 | { 33 | AddressFamily = 'IPv4' 34 | InterfaceAlias = 'Ethernet' 35 | Address = $Node.DefaultGateway 36 | DependsOn = '[xIPAddress]NewIpAddress' 37 | 38 | } 39 | 40 | xComputer JoinDomain 41 | { 42 | Name = $Node.Name 43 | DomainName = $Node.Domain 44 | Credential = $Node.Credential 45 | } 46 | } 47 | 48 | $ConfigData = @{ 49 | AllNodes = @( 50 | @{ 51 | Nodename = 'S3' 52 | Role = "HTTPSPull" 53 | PsDscAllowPlainTextPassword = $true 54 | PSDscAllowDomainUser = $true 55 | IPAddress = '192.168.2.5' 56 | Credential = (Get-Credential -UserName 'source\administrator') 57 | DefaultGateway = '192.168.2.1' 58 | } 59 | ) 60 | } 61 | 62 | HTTPSPull -ConfigurationData $ConfigData 63 | 64 | Start-DscConfiguration -Wait -Force -Path C:\DSC\HTTPSPull\ -Verbose -------------------------------------------------------------------------------- /DSC/Helper-Functions/Copy-ItemResources.ps1: -------------------------------------------------------------------------------- 1 | $From = (Get-ChildItem -Path ${env:ProgramFiles}\WindowsPowerShell\Modules\x*).fullname 2 | $To = "${env:ProgramFiles}\WindowsPowerShell\Modules" 3 | 4 | $session = New-PSSession -ComputerName DSC -Credential zephyr\administrator 5 | 6 | Copy-Item -Path $From -Recurse -Destination $To -ToSession $session -Verbose -------------------------------------------------------------------------------- /DSC/Helper-Functions/Export-MachineCert.ps1: -------------------------------------------------------------------------------- 1 | Function Export-MachineCert { 2 | <# 3 | .SYNOPSIS 4 | Harvests a certificate from a remote system. 5 | .DESCRIPTION 6 | Invokes a command on a remote system to copy the certificate to the machine running the command. 7 | .PARAMETER Computername 8 | Specifies the name of the remote system to harvest the certificate. 9 | .PARAMETER Path 10 | Provides the path where the certificate is copied to on the host system. 11 | .PARAMETER Template 12 | Specifies the template used when generating the certificate on the remote system. 13 | .EXAMPLE 14 | 15 | Requires PowerShell version 4 16 | #> 17 | [cmdletbinding()] 18 | Param( 19 | [ValidateNotNullorEmpty()] 20 | [string]$computername = $env:COMPUTERNAME, 21 | [ValidateScript({Test-Path $_})] 22 | [string]$Path="$env:SystemDrive\Certs" 23 | 24 | 25 | ) 26 | 27 | Try { 28 | #assumes a single certificate so sort on NotAfter 29 | Write-Verbose "Querying $computername for Machine certificates" 30 | $cert = invoke-command -scriptblock { 31 | Get-ChildItem Cert:\LocalMachine\my | 32 | Where-Object {$_.EnhancedKeyUsageList.FriendlyName -eq 'Document Encryption'} 33 | } -computername $computername -ErrorAction Stop 34 | write-verbose ($cert | out-string) 35 | 36 | if (($cert.count) -gt '1'){$cert = $cert[0]} 37 | } 38 | Catch { 39 | Throw $_ 40 | } 41 | 42 | if ($cert) { 43 | 44 | #verify and export 45 | if (Test-Certificate $cert) { 46 | 47 | $exportPath = Join-path -Path $Path -ChildPath "$computername.cer" 48 | Write-Verbose "Exporting certificate for $($cert.subject.trim()) to $exportpath" 49 | [pscustomobject]@{ 50 | Computername = $cert.Subject.Substring(3) 51 | Thumbprint = $cert.Thumbprint 52 | Path = Export-Certificate -Cert $cert -FilePath $exportPath 53 | } 54 | 55 | } #if Test OK $cert 56 | else { 57 | Write-Warning "Failed to verify or find a certificate" 58 | } 59 | } #if $cert 60 | } #Export-MachineCert -------------------------------------------------------------------------------- /DSC/Helper-Functions/Export-Resources.ps1: -------------------------------------------------------------------------------- 1 | # 2 | function Export-Resources ($ISOPath, $VMName) 3 | { 4 | #mount .ISO to VM 5 | Set-VMDvdDrive -VMName $VMName -Path $ISOPath 6 | Invoke-Command -VMName $VMName -ScriptBlock {Copy-Item -Path D:\* -Recurse -Destination "$env:ProgramFiles\WindowsPowerShell\Modules" -Force} 7 | } 8 | 9 | Export-Resources -ISOPath 'C:\Users\Duffney\Documents\GitHub\IAC-DSC\DSCResources.iso' -VMName 'ZDC02' -------------------------------------------------------------------------------- /DSC/LCM v1 HTTPS Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration LCMPull 2 | { 3 | Node Localhost 4 | { 5 | LocalConfigurationManager{ 6 | ConfigurationMode = 'ApplyandAutoCorrect' 7 | ConfigurationID = [GUID]::NewGuid().Guid 8 | RefreshFrequencyMins = 120 9 | ConfigurationModeFrequencyMins = 240 10 | RefreshMode = 'Pull' 11 | RebootNodeIfNeeded = $false 12 | DownloadManagerName = 'WebDownloadManager' 13 | DownloadManagerCustomData = @{ 14 | ServerUrl = 'https://psv52012r2pull4.contoso.com:8080/PSDSCPullServer.svc' 15 | AllowUnsecureConnection = 'false' 16 | } 17 | 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /DSC/LCM v2 HTTPS Example.ps1: -------------------------------------------------------------------------------- 1 | [DscLocalConfigurationManager()] 2 | Configuration LCMPull { 3 | Node Localhost { 4 | Settings { 5 | ActionAfterReboot = 'ContinueConfiguration' 6 | AllowModuleOverwrite = $true 7 | ConfigurationID = [GUID]::NewGuid().Guid 8 | ConfigurationMode = 'ApplyAndAutoCorrect' 9 | ConfigurationModeFrequencyMins = 15 10 | RefreshFrequencyMins = 30 11 | StatusRetentionTimeInDays = 7 12 | RebootNodeIfNeeded = $true 13 | RefreshMode = 'Pull' 14 | } 15 | ConfigurationRepositoryWeb PullServer { 16 | ServerUrl = 'https://psv52012r2pull4.contoso.com:8080/PSDSCPullServer.svc' 17 | AllowUnsecureConnection = 'false' 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /DSC/PullServerv2.ps1: -------------------------------------------------------------------------------- 1 | configuration DscPullServer 2 | { 3 | param 4 | ( 5 | [string[]]$NodeName = 'localhost', 6 | 7 | [ValidateNotNullOrEmpty()] 8 | [string] $certificateThumbPrint, 9 | 10 | [Parameter(Mandatory)] 11 | [ValidateNotNullOrEmpty()] 12 | [string] $RegistrationKey 13 | ) 14 | 15 | Import-DSCResource -ModuleName PSDesiredStateConfiguration 16 | Import-DSCResource -ModuleName xPSDesiredStateConfiguration 17 | 18 | Node $NodeName 19 | { 20 | WindowsFeature DSCServiceFeature 21 | { 22 | Ensure = 'Present' 23 | Name = 'DSC-Service' 24 | } 25 | 26 | xDscWebService PSDSCPullServer 27 | { 28 | Ensure = 'present' 29 | EndpointName = 'PSDSCPullServer' 30 | Port = 8080 31 | PhysicalPath = "$env:SystemDrive\inetpub\PSDSCPullServer\" 32 | CertificateThumbPrint = $certificateThumbPrint 33 | ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules" 34 | ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" 35 | State = 'Started' 36 | DependsOn = '[WindowsFeature]DSCServiceFeature' 37 | UseSecurityBestPractices = $true 38 | } 39 | 40 | File RegistrationKeyFile 41 | { 42 | Ensure = 'Present' 43 | Type = 'File' 44 | DestinationPath = "$env:ProgramFiles\WindowsPowerShell\DscService\RegistrationKeys.txt" 45 | Contents = $RegistrationKey 46 | } 47 | } 48 | 49 | } 50 | 51 | 52 | $guid = [guid]::newGuid() 53 | 54 | $cert = Get-ChildItem Cert:\LocalMachine\My | where {$_.FriendlyName -eq 'PSDSCPullServerCert'} 55 | 56 | DscPullServer -certificateThumbPrint $cert.Thumbprint -RegistrationKey $guid -OutputPath c:\dsc 57 | 58 | Start-DscConfiguration -Path C:\dsc -Wait -Verbose -Force -------------------------------------------------------------------------------- /DotNet/Get_CurrentDomain.ps1: -------------------------------------------------------------------------------- 1 | [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 2 | [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() -------------------------------------------------------------------------------- /FileSystems/Examples.ps1: -------------------------------------------------------------------------------- 1 | Get-ChildItem –path C:\windows\system32\* | Where-object Length –gt 10MB | sort Length –Descending | select –first 10 | ft –property Name,@{n=’File Size (MB)’;e={$PSItem.Length / 1MB};formatstring=’N1’} -autosize 2 | -------------------------------------------------------------------------------- /FileSystems/Get-Icon.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Get-Icon extracts the icon image from an exe file 4 | and saves it as a .ico file in the same directory as 5 | the .exe file. 6 | .DESCRIPTION 7 | Get-DiskInventory will run on every .exe file in the specified 8 | directory by the folder PARAMETER then save a .ico file for 9 | every .exe discovered. 10 | .PARAMETER folder 11 | The directory containing the .exe files. 12 | .EXAMPLE 13 | Get-Icon -folder c:\exelocation -name 14 | #> 15 | 16 | Function Get-Icon { 17 | 18 | [CmdletBinding()] 19 | 20 | Param ( 21 | [Parameter(Mandatory=$True,HelpMessage="Enter the location of the .EXE file")] 22 | [string]$folder 23 | ) 24 | 25 | [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | Out-Null 26 | 27 | md $folder -ea 0 | Out-Null 28 | 29 | dir $folder *.exe -ea 0 -rec | 30 | ForEach-Object { 31 | $baseName = [System.IO.Path]::GetFileNameWithoutExtension($_.FullName) 32 | Write-Progress "Extracting Icon" $basename 33 | [System.Drawing.Icon]::ExtractAssociatedIcon($_.FullName).ToBitmap().Save("$folder\$basename.ico") 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /FileSystems/Get-MSIinfo.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | 4 | Gather MSI information 5 | 6 | .DESCRIPTION 7 | 8 | Invokes methods to query all msi files at a specific location. 9 | 10 | .PARAMETER Path 11 | 12 | Provide the location of the .MSI file. 13 | 14 | .PARAMETER Property 15 | 16 | Select one of the three properties to return from the .MSI file. 17 | ProductCode,ProductVersion,ProductName 18 | 19 | .Example 20 | 21 | Get-MSIinfo -Path C:\MSI -Property ProductCode 22 | 23 | .Link 24 | 25 | http://www.scconfigmgr.com/2014/08/22/how-to-get-msi-file-information-with-powershell/ 26 | 27 | 28 | #> 29 | 30 | function Get-MSIinfo { 31 | 32 | param( 33 | [parameter(Mandatory=$true)] 34 | [IO.FileInfo]$Path, 35 | [parameter(Mandatory=$true)] 36 | [ValidateSet("ProductCode","ProductVersion","ProductName")] 37 | [string]$Property 38 | ) 39 | try { 40 | $WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer 41 | $MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase","InvokeMethod",$Null,$WindowsInstaller,@($Path.FullName,0)) 42 | $Query = "SELECT Value FROM Property WHERE Property = '$($Property)'" 43 | $View = $MSIDatabase.GetType().InvokeMember("OpenView","InvokeMethod",$null,$MSIDatabase,($Query)) 44 | $null = $View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null) 45 | $Record = $View.GetType().InvokeMember("Fetch","InvokeMethod",$null,$View,$null) 46 | $Value = $Record.GetType().InvokeMember("StringData","GetProperty",$null,$Record,1) 47 | return $Value 48 | } 49 | catch { 50 | Write-Output $_.Exception.Message 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /FileSystems/UnblockFiles.ps1: -------------------------------------------------------------------------------- 1 | Function Unblock-Directory { 2 | <# 3 | .SYNOPSIS 4 | 5 | Unblocks files 6 | 7 | .DESCRIPTION 8 | 9 | This function unblocks files that are downloaded from the internet, preventing errors upon execution. 10 | 11 | .PARAMETER Path 12 | 13 | The path of the directory containing locked files. 14 | 15 | .EXAMPLE 16 | 17 | PS C:\> Unblock-Directory -Path "C:\ScriptDownloads" 18 | 19 | .Notes 20 | 21 | .LINK 22 | 23 | #> 24 | Param( 25 | [CmdletBinding()] 26 | 27 | [Parameter(Mandatory=$True)] 28 | [string]$Path 29 | 30 | ) 31 | 32 | Get-ChildItem "$path" -Recurse | Unblock-File 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Formatting-Output/Examples.ps1: -------------------------------------------------------------------------------- 1 | Get-process | ft ID,VM -autosize 2 | 3 | #Grabs only one result 4 | Get-aduser -filter * -properties * -resultsetsize 1 5 | 6 | Get-Process | format-table -Property Name,ID,@{n='VM(MB)';e={$PSItem.VM / 1MB};formatstring='N2' 7 | ;align='right'} -autosize 8 | 9 | Get-Process | Format-Table -Property Name,ID,@{n='VM(MB)';e={$PSItem.VM / 1MB};formatString='N2'},@{n='PM(MB)';e={$PSItem.PM / 1MB};formatString='N2'} -AutoSize | Out-File Procs.txt 10 | 11 | Get-process | sort baseproperity | ft -groupby basepriority 12 | 13 | Get-NetRoute | Format-Table -Property AddressFamily,RouteMetric,TypeOfRoute, @{n='DestinationPrefix';e={$PSItem.DestinationPrefix};align='right'} -AutoSize 14 | 15 | Get-ChildItem -Path C:\Windows\*.exe | Sort-Object -Property Length -Descending | Format-Table -Property Name,@{n='Size(KB)';e={$PSItem.Length / 1KB}; formatstring='N2'} -AutoSize 16 | 17 | Get-Eventlog -LogName Security -Newest 20 | Select-Object -Property *,@{n='TimeDifference';e={$PSItem.TimeWritten - $PSitem.TimeGenerated}} | sort-object -property TimeDifference -descending | Format-table -property EventID,TimeDifference -autosize 18 | -------------------------------------------------------------------------------- /Hyper-V/Clone-VM.ps1: -------------------------------------------------------------------------------- 1 | Invoke-Command -VMName Win10 -ScriptBlock {Set-Location $env:windir\System32\sysprep;cmd /c "Sysprep.exe /oobe /generalize /shutdown"} -Credential administrator 2 | -------------------------------------------------------------------------------- /Hyper-V/DSCLab-LCMconfig.ps1: -------------------------------------------------------------------------------- 1 | [DSCLocalConfigurationManager()] 2 | Configuration LCM_HTTPPULL 3 | { 4 | param 5 | ( 6 | [Parameter(Mandatory=$true)] 7 | [string[]]$ComputerName, 8 | 9 | [Parameter(Mandatory=$true)] 10 | [string]$guid 11 | ) 12 | Node $ComputerName { 13 | 14 | Settings{ 15 | 16 | AllowModuleOverwrite = $True 17 | ConfigurationMode = 'ApplyAndAutoCorrect' 18 | RefreshMode = 'Pull' 19 | ConfigurationID = $guid 20 | } 21 | 22 | ConfigurationRepositoryWeb DSCHTTP { 23 | #ConfigurationNames = 'DSCHTTP' 24 | ServerURL = 'http://zdc01.zephyr.org:8080/PSDSCPullServer.svc/' 25 | AllowUnsecureConnection = $true 26 | } 27 | 28 | } 29 | } 30 | 31 | # Computer list 32 | $ComputerName='DC02', 'DC03' 33 | 34 | # Create Guid for the computers 35 | $guid=[guid]::NewGuid() 36 | 37 | # Create the Computer.Meta.Mof in folder 38 | LCM_HTTPPULL -ComputerName $ComputerName -Guid $guid -OutputPath $env:SystemDrive\DSC\HTTP -------------------------------------------------------------------------------- /Hyper-V/DSCLabHFile01Config.ps1: -------------------------------------------------------------------------------- 1 | configuration HydraFileConfig { 2 | 3 | Import-DscResource -Module xTimeZone 4 | 5 | Node HTTPComputers { 6 | 7 | 8 | xTimeZone SystemTimeZone { 9 | TimeZone = 'Central Standard Time' 10 | IsSingleInstance = 'Yes' 11 | } 12 | } 13 | } 14 | 15 | HydraFileConfig -OutputPath C:\DSC\HTTP 16 | $guid=Get-DscLocalConfigurationManager -CimSession HFile01 | Select-Object -ExpandProperty ConfigurationID 17 | # Specify source folder of configuration 18 | $source = "C:\DSC\HTTP\HTTPComputers.mof" 19 | # Destination is the Share on the SMB pull server 20 | $dest = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration\$guid.mof" 21 | Copy-Item -Path $source -Destination $dest 22 | #Then on Pull server make checksum 23 | New-DSCChecksum $dest 24 | 25 | 26 | New-DscCheckSum -ConfigurationPath "C:\Program Files\WindowsPowerShell\DscService\Modules" -OutPath "C:\Program Files\WindowsPowerShell\DscService\Modules" -Verbose -Force 27 | Update-DscConfiguration -ComputerName HFile01 -Wait -Verbose -------------------------------------------------------------------------------- /Hyper-V/GW01Config.ps1: -------------------------------------------------------------------------------- 1 | #Rename Computer & Restart 2 | Rename-Computer GW01; Restart-Computer 3 | 4 | #Find External DHCP enabled interface 5 | $External = (Get-NetIPAddress -AddressFamily IPv4).Where{$_.PrefixOrigin -eq 'Dhcp'} 6 | #Rename DHCP adpter to External 7 | Rename-NetAdapter -Name $External.InterfaceAlias -NewName 'External' 8 | #Find Internal adpater 9 | $Internal = (Get-NetIPAddress -AddressFamily IPv4).Where{$_.PrefixOrigin -ne 'Dhcp' -and $_.InterfaceAlias -notmatch 'Loopback'} 10 | Rename-NetAdapter -Name $Internal.InterfaceAlias -NewName 'Internal' 11 | #Set Internal Static Address 12 | Get-NetAdapter -Name Internal | New-NetIPAddress -IPAddress 192.168.2.1 -AddressFamily IPv4 -PrefixLength 24 13 | #Install Routing Feature 14 | Install-WindowsFeature Routing 15 | #Configure Nat & Routing 16 | Install-RemoteAccess -VpnType Vpn 17 | 18 | $ExternalInterface="External" 19 | $InternalInterface="Internal" 20 | 21 | cmd.exe /c "netsh routing ip nat install" 22 | cmd.exe /c "netsh routing ip nat add interface $ExternalInterface" 23 | cmd.exe /c "netsh routing ip nat set interface $ExternalInterface mode=full" 24 | cmd.exe /c "netsh routing ip nat add interface $InternalInterface" -------------------------------------------------------------------------------- /Hyper-V/HydraLCMconfig.ps1: -------------------------------------------------------------------------------- 1 | [DSCLocalConfigurationManager()] 2 | Configuration LCM_HTTPPULL 3 | { 4 | param 5 | ( 6 | [Parameter(Mandatory=$true)] 7 | [string[]]$ComputerName, 8 | 9 | [Parameter(Mandatory=$true)] 10 | [string]$guid 11 | ) 12 | Node $ComputerName { 13 | 14 | Settings{ 15 | 16 | AllowModuleOverwrite = $True 17 | ConfigurationMode = 'ApplyAndAutoCorrect' 18 | RefreshMode = 'Pull' 19 | ConfigurationID = $guid 20 | } 21 | 22 | ConfigurationRepositoryWeb DSCHTTP { 23 | #ConfigurationNames = 'DSCHTTP' 24 | ServerURL = 'http://HDC01.Hydra.org:8080/PSDSCPullServer.svc/' 25 | AllowUnsecureConnection = $true 26 | } 27 | 28 | } 29 | } 30 | 31 | # Computer list 32 | $ComputerName='HFile01' 33 | 34 | # Create Guid for the computers 35 | $guid=[guid]::NewGuid() 36 | 37 | # Create the Computer.Meta.Mof in folder 38 | LCM_HTTPPULL -ComputerName $ComputerName -Guid $guid -OutputPath c:\DSC\HTTP 39 | 40 | Set-DSCLocalConfigurationManager -ComputerName 'HFile01' -Path c:\DSC\HTTP –Verbose -------------------------------------------------------------------------------- /Hyper-V/Hyper-v_Nat.ps1: -------------------------------------------------------------------------------- 1 | New-VMSwitch -Name "NATSwitch" -SwitchType NAT -NATSubnetAddress "172.91.92.0/24" 2 | New-NetNat -Name VMSwitchNat -InternalIPInterfaceAddressPrefix "172.91.92.0/24" 3 | 4 | Invoke-Command -VMName Win10 -ScriptBlock {New-NetIPAddress -InterfaceIndex (Get-NetAdapter).InterfaceIndex -IPAddress '172.91.92.2' -PrefixLength 24 -DefaultGateway '172.91.92.1'} -------------------------------------------------------------------------------- /Hyper-V/LabSetup.ps1: -------------------------------------------------------------------------------- 1 | Get-NetAdapter | Select Name,MacAddress #Select NetAdpter with internet access 2 | Get-NetAdapter | Select Name,InterfaceDescription 3 | 4 | $NetAdapterName = (Get-NetAdapter).Name 5 | New-VMSwitch -NetAdapterName $NetAdapterName[0] -Name 'External' #Create External internet providing Hyper-v adapter 6 | New-VMSwitch -SwitchType Internal -Name 'Internal' 7 | 8 | $Servers = 'ZDC01','HDC01' 9 | 10 | Foreach ($Server in $Servers){ 11 | $Name = $Server 12 | $SwitchName = 'Internal' 13 | $HardDiskSize = 32GB 14 | $HDPath = 'C:\Hyper-V\Virtual Hard Disks'+'\'+$Name+'.vhdx' 15 | $Generation = '2' 16 | $ISO_Path = 'C:\Hyper-V\ISO\WindowsServer2016TechnicalPreview4.ISO' 17 | 18 | New-VM -Name $Name -SwitchName $SwitchName ` 19 | -NewVHDSizeBytes $HardDiskSize ` 20 | -NewVHDPath $HDPath -Generation $Generation -MemoryStartupBytes 1024MB 21 | 22 | Add-VMDvdDrive -VMName $Name -Path $ISO_Path 23 | 24 | $MyDVD = Get-VMDvdDrive $Name 25 | $MyHD = Get-VMHardDiskDrive $Name 26 | $MyNIC = Get-VMNetworkAdapter $Name 27 | 28 | Set-VMFirmware $Name -BootOrder $MyDVD,$MyHD,$MyNIC 29 | Set-VMMemory $Name -DynamicMemoryEnabled $false 30 | 31 | If ($Server -eq 'GW01'){Add-VMNetworkAdapter -VMName $Server -SwitchName External} 32 | Start-VM -vm $Server 33 | } 34 | 35 | $Name = 'Win7' 36 | $SwitchName = 'Internal' 37 | $HardDiskSize = 32GB 38 | $HDPath = 'C:\Hyper-V\Virtual Hard Disks'+'\'+$Name+'.vhdx' 39 | $Generation = '1' 40 | $ISO_Path = 'C:\Hyper-V\ISO\Windows7ProfessionalSP1x64t.iso' 41 | 42 | New-VM -Name $Name -SwitchName $SwitchName ` 43 | -NewVHDSizeBytes $HardDiskSize ` 44 | -NewVHDPath $HDPath -Generation $Generation -MemoryStartupBytes 1024MB 45 | 46 | Add-VMDvdDrive -VMName $Name -Path $ISO_Path 47 | -------------------------------------------------------------------------------- /Hyper-V/LabUp-Master.ps1: -------------------------------------------------------------------------------- 1 | $VMS = 'ZDC01','ZPull01','ZCert01','ZSQL01' 2 | 3 | 4 | foreach ($VM in $VMs){ 5 | 6 | $Name = $VM 7 | $SwitchName = 'Internal' 8 | $HardDiskSize = 32GB 9 | $HDPath = 'E:\Hyper-V\Virtual Hard Disks'+'\'+$Name+'.vhdx' 10 | $Generation = '2' 11 | $ISO_Path = 'D:\ISOs\Windows Server 2016\WindowsServer2016TechnicalPreview4.ISO' 12 | 13 | New-VM -Name $Name -SwitchName $SwitchName ` 14 | -NewVHDSizeBytes $HardDiskSize ` 15 | -NewVHDPath $HDPath -Generation $Generation -MemoryStartupBytes 1024MB 16 | 17 | Add-VMDvdDrive -VMName $Name -Path $ISO_Path 18 | 19 | 20 | $MyDVD = Get-VMDvdDrive $Name 21 | $MyHD = Get-VMHardDiskDrive $Name 22 | $MyNIC = Get-VMNetworkAdapter $Name 23 | 24 | Set-VMFirmware $Name -BootOrder $MyDVD,$MyHD,$MyNIC 25 | Set-VMMemory $Name -DynamicMemoryEnabled $false 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Hyper-V/New-VM.ps1: -------------------------------------------------------------------------------- 1 | $Name = 'Hyper-V' 2 | $SwitchName = 'Internal' 3 | $HardDiskSize = 32GB 4 | $HDPath = 'E:\Hyper-V\Virtual Hard Disks'+'\'+$Name+'.vhdx' 5 | $Generation = '2' 6 | $ISO_Path = 'D:\ISOs\Windows Server 2016\WindowsServer2016TP5.ISO' 7 | 8 | New-VM -Name $Name -SwitchName $SwitchName ` 9 | -NewVHDSizeBytes $HardDiskSize ` 10 | -NewVHDPath $HDPath -Generation $Generation -MemoryStartupBytes 4096MB -Verbose 11 | 12 | Add-VMDvdDrive -VMName $Name -Path $ISO_Path -Verbose 13 | 14 | set-vm -ProcessorCount 2 -VMName $Name -Verbose 15 | 16 | $MyDVD = Get-VMDvdDrive $Name 17 | $MyHD = Get-VMHardDiskDrive $Name 18 | $MyNIC = Get-VMNetworkAdapter $Name 19 | 20 | Set-VMFirmware $Name -BootOrder $MyDVD,$MyHD,$MyNIC 21 | Set-VMMemory $Name -DynamicMemoryEnabled $false 22 | 23 | break -------------------------------------------------------------------------------- /Hyper-V/Set-NetworkSettings.ps1: -------------------------------------------------------------------------------- 1 | #Find InterfaceAlias,Name,and InterfaceIndex 2 | Get-NetAdapter | select Name,InterfaceAlias,InterfaceIndex 3 | #Set Default Gateway & IP Address 4 | New-NetIPAddress –InterfaceAlias "Ethernet" –PrefixLength 24 –DefaultGateway 192.168.16.1 -IPAddress 192.168.1.105 5 | #Set DNS 6 | Set-DNSClientServerAddress –InterfaceAlias "Ethernet" –ServerAddress 192.168.16.10, 192.168.16.11 7 | 8 | #Reference 9 | #http://www.falconitservices.com/support/KB/Lists/Posts/Post.aspx?ID=100 10 | -------------------------------------------------------------------------------- /Hyper-V/Set-VMNetworkAdapter.ps1: -------------------------------------------------------------------------------- 1 | #Source http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/17/change-virtual-machine-network-configuration-with-powershell.aspx 2 | GET-VM | GET-VMNetworkAdapter | Connect-VMNetworkAdapter –Switchname ‘New-cool-Hyper-V-Lan’ 3 | -------------------------------------------------------------------------------- /Hyper-V/VyOSConfig.ps1: -------------------------------------------------------------------------------- 1 | $Name = 'VyOS' 2 | $SwitchName = 'Internal' 3 | $HardDiskSize = 2GB 4 | $HDPath = 'E:\Hyper-V\Virtual Hard Disks'+'\'+$Name+'.vhdx' 5 | $Generation = '1' 6 | $ISO_Path = 'D:\ISOs\vyos-1.1.6-amd64.iso' 7 | 8 | New-VM -Name $Name -SwitchName $SwitchName ` 9 | -NewVHDSizeBytes $HardDiskSize ` 10 | -NewVHDPath $HDPath -Generation $Generation -MemoryStartupBytes 512MB 11 | 12 | Add-VMDvdDrive -VMName $Name -Path $ISO_Path 13 | 14 | Add-VMNetworkAdapter -VMName $Name -SwitchName External -------------------------------------------------------------------------------- /MISC/Automate_The_World.ps1: -------------------------------------------------------------------------------- 1 | function Automate_The_World{ 2 | 3 | for ($i = 1; $i -le 10; $i++) 4 | { 5 | $percent = $i * 10 6 | write-progress -id 1 -activity "Automating..." -status "$percent% Complete" -percentComplete ($i*10); 7 | sleep 1; 8 | #for ($j = 1; $j -le 10; $j++) 9 | #{ 10 | # write-progress -id 2 -parentId 1 -activity "Doing some child stuff" -status "yay" -percentComplete ($j*10) 11 | # #sleep 0.75 12 | #} 13 | } 14 | } 15 | Automate_The_World -------------------------------------------------------------------------------- /MISC/Profile.ps1: -------------------------------------------------------------------------------- 1 | $PSDefaultParameterValues = @{ 2 | 'Get-Help:Full' = $true 3 | } 4 | 5 | $PSDefaultParameterValues = @{ 6 | 'Get-Help:Full' = $true 7 | '*:Verbose' = $true 8 | } 9 | -------------------------------------------------------------------------------- /MISC/RenameResetLocalAdmin.ps1: -------------------------------------------------------------------------------- 1 | #-------Enable, Rename, & Reset Local Administrator Password-------# 2 | #################################################################### 3 | 4 | #Get Service Tag 5 | $servicetag = (gwmi win32_bios).SerialNumber 6 | 7 | #Rename Local Admin Account 8 | $admin=[adsi]"WinNT://./Administrator,user" 9 | $admin.psbase.rename("Ron.Johnson") 10 | 11 | #Enables & Sets User Password 12 | invoke-command { net user Ron.Johnson Adm.$servicetag /active:Yes } 13 | 14 | ######################################################################## 15 | #----------------------Creator - Joshua.Duffney------------------------# 16 | #---------------------- Sources ------------------------# 17 | #Sources 18 | #http://myitforum.com/cs2/blogs/yli628/archive/2010/05/19/mdt-create-a-task-sequence-using-powershell-to-rename-local-administrator-account.aspx 19 | #http://jdhitsolutions.com/blog/2014/04/set-local-user-account-with-powershell/ 20 | #https://community.spiceworks.com/topic/493143-trimming-variables-with-powershell?page=1#entry-3306064 21 | #---------------------- Notes ------------------------# 22 | #must run the following command in SCCM for the script to run 23 | #Powershell.exe -command "Set-ExecutionPolicy RemoteSigned; 24 | -------------------------------------------------------------------------------- /MISC/Test-RemoteSessionSettings.ps1: -------------------------------------------------------------------------------- 1 | $scriptblock = { if($env:Processor_Architecture -eq "x86"){write "32bit"}else{write "64bit"} } 2 | $scriptblock1 = {$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()} 3 | $secprin = New-Object Security.Principal.WindowsPrincipal $currentUser #2 4 | 5 | if ($secprin.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) 6 | {$admin = 'Administrator'} 7 | else {$admin = 'non-Administrator'};$admin; if($env:Processor_Architecture -eq "x86"){write "32bit"}else{write "64bit"} 8 | 9 | 10 | 11 | $block = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") -------------------------------------------------------------------------------- /Networking/Set-NetAdapterPrivate: -------------------------------------------------------------------------------- 1 | #http://blogs.msdn.com/b/powershell/archive/2009/04/03/setting-network-location-to-private.aspx 2 | 3 | # Skip network location setting for pre-Vista operating systems 4 | if([environment]::OSVersion.version.Major -lt 6) { return } 5 | 6 | # Skip network location setting if local machine is joined to a domain. 7 | if(1,3,4,5 -contains (Get-WmiObject win32_computersystem).DomainRole) { return } 8 | 9 | # Get network connections 10 | $networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")) 11 | $connections = $networkListManager.GetNetworkConnections() 12 | 13 | # Set network location to Private for all networks 14 | $connections | % {$_.GetNetwork().SetCategory(1)} 15 | 16 | -------------------------------------------------------------------------------- /PSRemoting/Examples.ps1: -------------------------------------------------------------------------------- 1 | Invoke-Command 2 | 3 | Invoke-command by default maxes out at 32 systems 4 | 5 | Invoke-Command -Scriptblock { get-process } -computername lon-cl1,lon-dc1 6 | 7 | $dc = New-PSSession -Computername LON-DC1 8 | Get-Module -listavailable -pssession $dc | where {$_.Name -like "*share*'} 9 | 10 | #Import Remote Module 11 | Import-Module -PSSession $dc -Name SMBShare -Prefix DC 12 | 13 | $Computers = New-PSSession -Computername LON-DC1,LON-CL1 14 | 15 | Get-ADComputer –filter * | % {Invoke-command $PSitem.Name –scriptblock { get-hotfix}} 16 | 17 | Invoke-Command -scriptblock { Get-ADComputer -Filter * | % {Get-Hotfix -ComputerName $PSItem.name | where HotFixID -eq KB2693643}} 18 | -------------------------------------------------------------------------------- /PSRemoting/Invoke-32bitPS.ps1: -------------------------------------------------------------------------------- 1 | #start-job -scriptblock $scriptblock -RunAs32 2 | 3 | $scriptblock = { if($env:Processor_Architecture -eq "x86"){write "running on 32bit"}else{write "running on 64bit"} } 4 | 5 | 6 | $sess = New-PSSession -computername admt01 -ConfigurationName microsoft.powershell32 7 | 8 | Invoke-Command -Session $sess -ScriptBlock $scriptblock -------------------------------------------------------------------------------- /PSRemoting/Test-PSSession.ps1: -------------------------------------------------------------------------------- 1 | $scriptblock = { if($env:Processor_Architecture -eq "x86"){write "32bit"}else{write "64bit"} } 2 | $scriptblock1 = {$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent() 3 | $secprin = New-Object Security.Principal.WindowsPrincipal $currentUser #2 4 | 5 | if ($secprin.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) 6 | {$admin = 'Administrator'} 7 | else {$admin = 'non-Administrator'};$admin; if($env:Processor_Architecture -eq "x86"){write "32bit"}else{write "64bit"}} -------------------------------------------------------------------------------- /Presentations/PowerShellandSQL/PreDemo.ps1: -------------------------------------------------------------------------------- 1 | Import-Module SQLcmdlets 2 | $ConnectionString = "server=SQL01\SQLEXPRESS;database=OmahaPSUG;trusted_connection=true" 3 | $ConnectionStringOmahaPSUGBK = "server=SQL01\SQLEXPRESS;database=OmahaPSUG_BK;trusted_connection=true" 4 | 5 | Invoke-DatabaseQuery -connectionString $ConnectionString -query "Delete From OmahaPSUG_Users" 6 | Invoke-DatabaseQuery -connectionString $ConnectionString -query "Delete From OmahaPSUG_Computers" 7 | Invoke-DatabaseQuery -connectionString $ConnectionString -query "Delete From OmahaPSUG_StaleGroups" 8 | Invoke-DatabaseQuery -connectionString $ConnectionStringOmahaPSUGBK -query "Delete From OmahaPSUG_Computers" 9 | Set-ADComputer -Identity DC01 -Location $null -Verbose 10 | 11 | $Computer = Get-ADComputer -Identity DC01 -Properties LastLogonDate,OperatingSystem,Description 12 | 13 | $query = "Insert Into OmahaPSUG_Computers (SamAccountName,Name,SID,DistinguishedName,Domain,LastLogonDate,Description,OperatingSystem) 14 | Values ('$($Computer.SamAccountName)','$($Computer.Name)','$($Computer.SID)','$($Computer.DistinguishedName)','Manticore.org','$($Computer.LastLogonDate)','$($Computer.Description)','$($Computer.OperatingSystem)')" 15 | 16 | Invoke-DatabaseQuery -connectionString $ConnectionString -query $query -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PowerShell 2 | ========== 3 | 4 | A PowerShell Repository for all the miscellaneous scripts I'm working on. 5 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/Add-DriverContentToDriverPackage.ps1: -------------------------------------------------------------------------------- 1 | Function Add-DriverContentToDriverPackage { 2 | <# 3 | .SYNOPSIS 4 | 5 | Add a configmgr drivers to driverpackages 6 | 7 | .DESCRIPTION 8 | 9 | Add a configmgr driver by ID to a driverpackage by name 10 | 11 | .PARAMETER SiteCode 12 | 13 | SiteCode of the Configuration Manager server 14 | 15 | .PARAMETER SiteServer 16 | 17 | Name of the configuration manager server 18 | 19 | .PARAMETER DriverCI 20 | 21 | The CI ID of the driver being added 22 | 23 | .PARAMETER DriverPackageName 24 | 25 | Name of the Configuration Manager driver package 26 | 27 | .EXAMPLE 28 | 29 | Add-DriverContentToDriverPackage -SiteCode PRI -SiteServer Server100 -DriverCI 16777351 -DriverPackageName "New Driver Package 30 | 31 | .Notes 32 | 33 | .LINK 34 | 35 | http://cm12sdk.net/?p=933 36 | 37 | #> 38 | 39 | [CmdLetBinding()] 40 | Param( 41 | [Parameter(Mandatory=$True,HelpMessage="Please Enter Site Server Site code")] 42 | $SiteCode, 43 | [Parameter(Mandatory=$True,HelpMessage="Please Enter Site Server Name")] 44 | $SiteServer, 45 | [Parameter(Mandatory=$True,HelpMessage="Please Enter Driver Name")] 46 | $DriverCI, 47 | [Parameter(Mandatory=$True,HelpMessage="Please Enter Driver Package Name")] 48 | $DriverPackageName 49 | ) 50 | 51 | $DriverPackageQuery = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_DriverPackage -ComputerName $SiteServer -Filter "Name='$DriverPackageName'" 52 | $DriverQuery = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_Driver -ComputerName $SiteServer -Filter "CI_ID='$DriverCI'" 53 | $DriverContentQuery = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_CIToContent -ComputerName $SiteServer -Filter "CI_ID='$($DriverQuery.CI_ID)'" 54 | 55 | $DriverPackageQuery.AddDriverContent($DriverContentQuery.ContentID,$DriverQuery.ContentSourcePath,$False) 56 | } 57 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/CreateCatalogCategories.ps1: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------- 2 | # Version: 1.0 3 | # Author: Joshua Duffney 4 | # Date: 07/18/2014 5 | # Description: Create CM Catalog Categories from a .txt file 6 | # Comments: Populate the names of the desired catalog categories line by line in catalogcategories.txt 7 | # --------------------------------------------------- 8 | 9 | Function NewCMCatalogCategories { 10 | 11 | Param( 12 | [string]$SiteServerName, 13 | [string]$SiteCode, 14 | [string]$Path 15 | ) 16 | # Connect to SCCM 17 | Try 18 | { 19 | Import-Module "$(Split-Path $env:SMS_ADMIN_UI_PATH -Parent)\ConfigurationManager.psd1" -ErrorAction Stop 20 | Set-Location "$($SiteCode):" 21 | } 22 | Catch [System.IO.FileNotFoundException] 23 | { 24 | "SCCM Admin Console not installed" 25 | } 26 | Catch 27 | { 28 | $ErrorMessage = $_.Exception.Message 29 | $FailedItem = $_.Exception.ItemName 30 | } 31 | Finally 32 | { 33 | "This Script attempted to import the SCCM module" 34 | } 35 | # Create Catalog Catagories 36 | ForEach ($Category in (Get-Content $Path)) 37 | { 38 | $CategoryTest = Get-CMCategory -Name "$Category" 39 | 40 | if ($CategoryTest -eq $null){ 41 | New-CMCategory -CategoryType CatalogCategories -Name $Category | Out-Null 42 | Write-Host -ForegroundColor Green "$Category Created" 43 | } 44 | else 45 | { 46 | Write-Host -ForegroundColor red "$Category already exists" 47 | } 48 | } 49 | 50 | } 51 | 52 | NewCMCatalogCategories -SiteServerName ServerName -SiteCode SiteCode -Path "C:\scripts\catalogcategories.txt" 53 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/CreateOUCollections.ps1: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------- 2 | # Version: 1.0 3 | # Author: Joshua Duffney 4 | # Date: 08/4/2014 5 | # Description: Creates System Center Configuration Manager collections based on OU information 6 | # Comments: Change "Domain.COM/WORKSTATIONS" in line 18 to the OU path of the OU you are specifying. 7 | # --------------------------------------------------- 8 | 9 | Function NewOUCollection { 10 | Param( 11 | [string]$SiteServerName, 12 | [string]$SiteCode, 13 | [string]$OU, 14 | [string]$CollectionFolder, 15 | [string]$CollectionName 16 | ) 17 | 18 | $QueryExpression = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.SystemOUName = 'Domain.COM/WORKSTATIONS/$OU'" 19 | 20 | ## Import SCCM Module ## 21 | Try 22 | { 23 | Import-Module "$(Split-Path $env:SMS_ADMIN_UI_PATH -Parent)\ConfigurationManager.psd1" -ErrorAction Stop 24 | Set-Location "$($SiteCode):" 25 | } 26 | Catch [System.IO.FileNotFoundException] 27 | { 28 | "SCCM Admin Console not installed" 29 | } 30 | Catch 31 | { 32 | $ErrorMessage = $_.Exception.Message 33 | $FailedItem = $_.Exception.ItemName 34 | } 35 | Finally 36 | { 37 | "This Script attempted to import the SCCM module" 38 | } 39 | 40 | ## Creates CM collection, add query rule and moves to the specified folder 41 | Try { 42 | New-CMDeviceCollection -LimitingCollectionName "All Desktop and Server Clients" -Name $CollectionName -RefreshType ConstantUpdate 43 | Add-CMDeviceCollectionQueryMembershipRule -CollectionName $CollectionName -RuleName "Query-$CollectionName" -QueryExpression $QueryExpression 44 | $Collection = Get-CMDeviceCollection -Name $CollectionName 45 | Move-CMObject -FolderPath ".\DeviceCollection\$CollectionFolder" -InputObject $Collection -ErrorAction Stop | Out-Null 46 | } 47 | Catch { 48 | } 49 | 50 | } 51 | 52 | NewOUCollection -SiteServerName "Server" -SiteCode "SiteCode" -OU "OU Name" -CollectionFolder "Software" -CollectionName "Collection'sName" 53 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/Enter-CMSession.ps1: -------------------------------------------------------------------------------- 1 | Function Enter-CMSession { 2 | <# 3 | .SYNOPSIS 4 | 5 | Imports the System Center Configuration Manager Module & Connects to Configuration Manager PS-Drive. 6 | 7 | .DESCRIPTION 8 | 9 | Imports the System Center Configuration Manager module and then changes location to the sitecode PS drive specified. 10 | 11 | .PARAMETER SiteCode 12 | 13 | Specifies the SiteCode of the SCCM server to connect to. 14 | 15 | .EXAMPLE 16 | 17 | Enter-CMSession -SiteCode PS1 18 | 19 | #> 20 | [CmdletBinding()] 21 | 22 | param ( 23 | [Parameter(Mandatory=$True,HelpMessage="Enter the SiteCode of the SCCM Server")] 24 | [String]$SiteCode 25 | ) 26 | 27 | Try 28 | { 29 | Write-Verbose "Connecting to $computername" 30 | Import-Module "$(Split-Path $env:SMS_ADMIN_UI_PATH -Parent)\ConfigurationManager.psd1" -ErrorAction Stop 31 | Set-Location "$($SiteCode):" 32 | } 33 | Catch [System.IO.FileNotFoundException] 34 | { 35 | "SCCM Admin Console not installed" 36 | } 37 | Catch 38 | { 39 | $ErrorMessage = $_.Exception.Message 40 | $FailedItem = $_.Exception.ItemName 41 | } 42 | Finally 43 | { 44 | Write-Verbose "Finished running command" 45 | "This Script attempted to import the SCCM module" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/OneLiners.ps1: -------------------------------------------------------------------------------- 1 | #Remove All Drivers within System Center Configuration Manager 2 | Get-CMDriverPackage | % {Get-CMDriver -DriverPackageName $PSItem.Name} | Remove-CMDriver -Confirm:$false -Force -Verbose 3 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/Remove-AllCMDriverCatagories.ps1: -------------------------------------------------------------------------------- 1 | $cats = (Get-CMCategory -CategoryType DriverCategories).LocalizedCategoryInstanceName 2 | foreach ($cat in $cats) { Remove-CMCategory -Name "$cat" -Force -Verbose -CategoryType DriverCategories} 3 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/SCCMCleanup.ps1: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------- 2 | # Version: 3.0 3 | # Author: Joshua Duffney 4 | # Date: 07/15/2014 5 | # Updated: 8/9/2014 6 | # Description: Using PowerShell to check for a list of devices in SCCM and AD then returning the results in a table format. 7 | # Comments: Populate computers.txt with a list of computer names then run the script. 8 | # References: @thesurlyadm1n, @adbertram 9 | # --------------------------------------------------- 10 | 11 | Function DeviceCheck { 12 | Param( 13 | [string]$SiteServerName = 'ServerName', 14 | [string]$SiteCode = 'SiteCode', 15 | [string]$ComputerList 16 | ) 17 | 18 | ## Connect to SCCM 19 | $ErrorActionPreference = "stop" 20 | 21 | if (!(Test-Path "$(Split-Path $env:SMS_ADMIN_UI_PATH -Parent)\ConfigurationManager.psd1")) { 22 | Write-Error 'Configuration Manager module not found. Is the admin console installed?' 23 | } elseif (!(Get-Module 'ConfigurationManager')) { 24 | Import-Module "$(Split-Path $env:SMS_ADMIN_UI_PATH -Parent)\ConfigurationManager.psd1" 25 | } 26 | Set-Location "$($SiteCode):" 27 | 28 | ## Looking for device in SCCM 29 | 30 | foreach ($computer in (Get-Content $ComputerList)) 31 | { 32 | $value = Get-CMDevice -Name $computer 33 | if ($value -eq $null){$Results = "NO"} 34 | else{$Results = "Yes"} 35 | 36 | ## Looking for device in Active Directory 37 | 38 | try { 39 | Get-ADComputer $computer -ErrorAction Stop | Out-Null 40 | $computerResults = $true 41 | } 42 | Catch { 43 | $computerResults = $false 44 | 45 | } 46 | 47 | [PSCustomObject]@{ 48 | Name = $computer 49 | SCCM = $Results 50 | AD = $computerResults 51 | } 52 | 53 | } 54 | 55 | } 56 | 57 | DeviceCheck -SiteServerName ServerName -SiteCode SiteCode -ComputerList "D:\Scripts\computers.txt" 58 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/Set-CCMCacheSize.ps1: -------------------------------------------------------------------------------- 1 | Function Set-CCMCacheSize { 2 | <# 3 | .SYNOPSIS 4 | 5 | Changes the size of the Configuration Manager cache folder. 6 | 7 | .DESCRIPTION 8 | 9 | This function will change the size of the Configuration Manager ccmcache folder. 10 | 11 | .PARAMETER CCMCacheSize 12 | 13 | Specify the size of the Cache. 14 | 15 | .EXAMPLE 16 | 17 | Set-CCMCacheSize -CCMCacheSize 10240 18 | 19 | .Notes 20 | 21 | .LINK 22 | 23 | http://blogs.msdn.com/b/helaw/archive/2014/01/07/configuration-manager-cache-management.aspx 24 | 25 | #> 26 | [CmdletBinding()] 27 | 28 | param ( 29 | [Parameter(Mandatory=$True,HelpMessage="Enter the size of the ccmcache folder")] 30 | [String]$CCMCacheSize 31 | ) 32 | 33 | Begin { 34 | 35 | $CCM = New-Object -com UIResource.UIResourceMGR 36 | 37 | #USe GetCacheInfo method to return Cache properties 38 | $CCMCache = $CCM.GetCacheInfo() 39 | 40 | #Get the current cache location 41 | $CCMCacheDrive = $CCMCache.Location.Split("\")[0] 42 | 43 | #Check Free space on drive 44 | $Drive = Get-WMIObject -query "Select * from Win32_LogicalDisk where DeviceID = '$CCMCacheDrive'" 45 | 46 | #Convert freespace to GB for easier check 47 | $FreeSpace = $Drive.FreeSpace/1GB 48 | 49 | } 50 | 51 | Process { 52 | 53 | #Check Sizes and set Cache 54 | If ($Freespace -ge 5 -and $Freespace -lt 15) 55 | { 56 | #Free space moderate 57 | $CacheSize = 5120 58 | } 59 | If ($Freespace -ge 15) 60 | { 61 | #Plenty of space 62 | $CacheSize = $CCMCacheSize 63 | } 64 | 65 | #Set Cache Size 66 | $CCMCache.TotalSize = $CacheSize 67 | 68 | } 69 | End { 70 | 71 | Write-Verbose (Get-WMIObject -namespace root\ccm\softmgmtAgent -class CacheConfig).Size 72 | 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /SCCM/ConfigMgrTools/Update-0KBDriverPacks.ps1: -------------------------------------------------------------------------------- 1 | $DriverPacks = (Get-CMDriverPackage | Where-Object PackageSize -EQ "0").PackageID 2 | $SiteCode = 'SiteCode' 3 | $CMServer = 'Server' 4 | 5 | Function Add-DriverContentToDriverPackage 6 | { 7 | [CmdLetBinding()] 8 | Param( 9 | [Parameter(Mandatory=$True,HelpMessage="Please Enter Site Server Site code")] 10 | $SiteCode, 11 | [Parameter(Mandatory=$True,HelpMessage="Please Enter Site Server Name")] 12 | $SiteServer, 13 | [Parameter(Mandatory=$True,HelpMessage="Please Enter Driver Name")] 14 | $DriverCI, 15 | [Parameter(Mandatory=$True,HelpMessage="Please Enter Driver Package Name")] 16 | $DriverPackageName 17 | ) 18 | 19 | $DriverPackageQuery = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_DriverPackage -ComputerName $SiteServer -Filter "Name='$DriverPackageName'" 20 | $DriverQuery = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_Driver -ComputerName $SiteServer -Filter "CI_ID='$DriverCI'" 21 | $DriverContentQuery = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_CIToContent -ComputerName $SiteServer -Filter "CI_ID='$($DriverQuery.CI_ID)'" 22 | 23 | $DriverPackageQuery.AddDriverContent($DriverContentQuery.ContentID,$DriverQuery.ContentSourcePath,$False) 24 | } 25 | 26 | 27 | 28 | Foreach ($DriverPack in $DriverPacks) { 29 | 30 | $DriverPackSize = (Get-CMDriverPackage -Id $DriverPack).PackageSize 31 | Write-Host $DriverPackSize -ForegroundColor Green 32 | 33 | $Drivers = (Get-CMDriver -DriverPackageId $DriverPack).CI_ID 34 | $Driver = $Drivers[2] 35 | Write-host $Driver -ForegroundColor Green 36 | 37 | $DriverPackName = (Get-CMDriverPackage -Id $DriverPack).Name 38 | Write-Host $DriverPackName -ForegroundColor Green 39 | 40 | Write-Host "Removing $Driver from $DriverPackName..." -ForegroundColor Green 41 | Remove-CMDriverFromDriverPackage -DriverId $Driver -DriverPackageId $DriverPack -Force -Confirm:$false 42 | 43 | Write-Host "Adding $Driver from $DriverPackName..." -ForegroundColor Green 44 | Add-DriverContentToDriverPackage -SiteCode $SiteCode -SiteServer $CMServer -DriverCI $Driver -DriverPackageName $DriverPackName 45 | 46 | $DriverPackSize = (Get-CMDriverPackage -Id $DriverPack).PackageSize 47 | Write-host $DriverPackSize -ForegroundColor Green 48 | 49 | } 50 | -------------------------------------------------------------------------------- /SCCM/DetectionMethods/CCMCacheSize.ps1: -------------------------------------------------------------------------------- 1 | #Initialize our CCM COM Objects 2 | $CCM = New-Object -com UIResource.UIResourceMGR 3 | 4 | #USe GetCacheInfo method to return Cache properties 5 | $CCMCache = $CCM.GetCacheInfo() 6 | 7 | if ($CCMCache.TotalSize -ge '10240') { Write-Host '10GB cache' } 8 | -------------------------------------------------------------------------------- /SCCM/DetectionMethods/CitrixReceiver14.1.200.13.ps1: -------------------------------------------------------------------------------- 1 | $osarch = (gwmi win32_operatingsystem).osarchitecture 2 | if ($osarch -eq "64-bit") { 3 | $ReceiverVersion = (Get-ItemProperty -Path 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\CitrixOnlinePluginPackWeb' -ErrorAction SilentlyContinue).DisplayVersion 4 | if ($ReceiverVersion -eq '14.1.200.13') { 5 | Write-Host 'Installed' 6 | } 7 | } else { 8 | $ReceiverVersion = (Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\CitrixOnlinePluginPackWeb' -ErrorAction SilentlyContinue).DisplayVersion 9 | if ($ReceiverVersion -eq '14.1.200.13') { 10 | Write-Host 'Installed' 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SCCM/DetectionMethods/Registry.ps1: -------------------------------------------------------------------------------- 1 | if ((Get-ItemProperty 'HKLM:\SOFTWARE\Classes\TypeLib\{656A82C9-0680-4299-81C7-C41ADD503BA2}\1.0\0\win32' -ErrorAction SilentlyContinue) -match 'KPItemTagA.dll'){ 2 | Write-Host 'Installed'} 3 | -------------------------------------------------------------------------------- /SCCM/DetectionMethods/SAPNetWeaverBusinessClient3.5P14.ps1: -------------------------------------------------------------------------------- 1 | $osarch = (gwmi win32_operatingsystem).osarchitecture 2 | if ($osarch -eq "64-bit") { 3 | $NWBCPatch = (Get-ItemProperty -Path 'C:\Program Files (x86)\SAP\NWBC35\NWBC.exe' -ErrorAction SilentlyContinue).VersionInfo.ProductVersion 4 | } else { 5 | $NWBCPatch = (Get-ItemProperty -Path 'C:\Program Files\SAP\NWBC35\NWBC.exe' -ErrorAction SilentlyContinue).VersionInfo.ProductVersion 6 | } 7 | 8 | if($NWBCPatch -ne $null) { Write-Host "Installed" } 9 | -------------------------------------------------------------------------------- /SCCM/DetectionMethods/WindowsUpdateAgentVersion.ps1: -------------------------------------------------------------------------------- 1 | $WindowsUpdateAgentVer = (Get-ItemProperty -Path 'C:\Windows\System32\wuaueng.dll' -ErrorAction SilentlyContinue).VersionInfo.ProductVersion 2 | if ($WindowsUpdateAgentVer -eq '7.6.7600.256' -or $WindowsUpdateAgentVer -eq '7.6.7600.320'){ 3 | Write-Host "Installed" 4 | } 5 | -------------------------------------------------------------------------------- /SCCM/PackageAutomation/CreateCMPackage.csv: -------------------------------------------------------------------------------- 1 | SourceFolder,Name,Description,Manufacturer,Version,CommandLine 2 | C:\InstallerSource,NotePad++,Code Editor Software,NotepadTM,6.6.7,npp.6.6.7.Installer.exe /S 3 | -------------------------------------------------------------------------------- /SCCM/README.md: -------------------------------------------------------------------------------- 1 | SCCMPowerShell 2 | ============== 3 | 4 | PowerShell Repository for System Center Configuration Manager Automation 5 | 6 | My name is Josh Duffney, I'm a Passionate IT Pro, PowerShell Addict, and Systems Engineer for a large enterprise. In this repo I'll be sharing the PowerShell scripts I'm working on to Automate configuration manager tasks. 7 | 8 | Blog www.powershellscripter.com 9 | -------------------------------------------------------------------------------- /SQL/Copy-SQLTable.ps1: -------------------------------------------------------------------------------- 1 | function Copy-SQLTable { 2 | <# 3 | .SYNOPSIS 4 | Copies a table from a source database and inserts it into the target database. 5 | .DESCRIPTION 6 | Takes all the data from the source database and inserts it into the target database with the same name. 7 | .PARAMETER TableName 8 | Specifies the table name to be copied from the source and inserted into the target. 9 | .PARAMETER SourceServer 10 | Specifies source server DNS name and instance, use ServerName\InstanceName. 11 | .PARAMETER SourceDataBase 12 | Specifies the source database name. 13 | .PARAMETER TargetDatabase 14 | Specifies the target database name. 15 | .PARAMETER TargetServer 16 | SPecifies the target server DNS name and instance, user ServerName\InstanceName. 17 | .EXAMPLE 18 | Copy-SQLTable -TableName 'OmahaPSUG_Computers' -SourceServer 'SQL01\SQLEXPRESS' -SourceDataBase 'OmahaPSUG' -TargetDatabase 'OmahaPSUG_BK' -TargetServer 'SQL01\SQLEXPRESS' 19 | #> 20 | [CmdletBinding()] 21 | 22 | Param( 23 | 24 | [string]$TableName, 25 | 26 | [string]$SourceServer, 27 | 28 | [string]$SourceDataBase, 29 | 30 | [string]$TargetServer, 31 | 32 | [string]$TargetDatabase 33 | ) 34 | 35 | 36 | $SourceConnectionString = "server=$SourceServer;database=$SourceDataBase;trusted_connection=true" 37 | $TargetConnectionString = "server=$TargetServer;database=$TargetDatabase;trusted_connection=true" 38 | 39 | $Data = Get-DatabaseData -connectionString $SourceConnectionString -query "Select * from $TableName" 40 | $Data = $Data[1..($Data.Count)] 41 | 42 | $Columns = (Get-DatabaseData -connectionString $SourceConnectionString -query "SELECT COLUMN_NAME FROM $SourceDataBase.information_schema.columns WHERE table_name = '$TableName' ORDER BY ORDINAL_POSITION").Column_Name 43 | 44 | foreach ($c in $Columns){$InsertColumns += $c+','} 45 | 46 | $InsertColumns=$InsertColumns.Trim(',') 47 | 48 | Foreach ($Value in $Data) { 49 | 50 | $array = $Value.ItemArray 51 | foreach ($a in $array){ 52 | $values += "'"+$a+"'"+',' 53 | } 54 | $Values = $Values.Trim(',') 55 | $query = "Insert Into $TableName ($InsertColumns) Values ($Values)" 56 | $Values = $null 57 | 58 | 59 | Invoke-DatabaseQuery -connectionString $TargetConnectionString -query $query 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /SQL/SMO.ps1: -------------------------------------------------------------------------------- 1 | [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo"); 2 | #Add-Type -AssemblyName "Microsoft.SqlServer.Smo" 3 | #Add-Type -path "C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Smo\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Smo.dll" 4 | 5 | 6 | $SQLSvr = 'SQL01\SQLEXPRESS' 7 | $MySQLObject = new-object Microsoft.SqlServer.Management.Smo.Server $SQLSvr 8 | #$SQLSvr = [Microsoft.SqlServer.Management.Smo.SmoApplication]::EnumAvailableSqlServers($false) | Select name; 9 | #$SQLSvr; 10 | $MySQLObject | gm | more -------------------------------------------------------------------------------- /Snippets/Create-Snippets.ps1: -------------------------------------------------------------------------------- 1 | New-Item (Join-Path (Split-Path $profile.CurrentUserCurrentHost) "Snippets") -ItemType Directory 2 | 3 | New-IseSnippet -Title 'Try Catch Get-ADUser' -Description 'Try Catch block with AD object not found catch block' -Text 'Try { 4 | Get-ADUser -Identity $User 5 | } 6 | Catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { 7 | Write-Warning "$User could not be found" 8 | }' -CaretOffset 4 9 | 10 | Try { 11 | Get-ADUser -Identity $User 12 | } 13 | Catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { 14 | Write-Warning "$User could not be found" 15 | } -------------------------------------------------------------------------------- /Tips-Tricks/Advanced_Function_Template.ps1: -------------------------------------------------------------------------------- 1 | function { 2 | <# 3 | .SYNOPSIS 4 | .DESCRIPTION 5 | .PARAMETER 6 | .EXAMPLE 7 | #> 8 | [CmdletBinding()] 9 | param( 10 | [string] 11 | ) 12 | BEGIN {} 13 | PROCESS {} 14 | END {} 15 | } 16 | 17 | 18 | Function set-function { 19 | [cmdletbinding(SupportsShouldProcess=$True,ConfirmImpact="High")] 20 | 21 | Param ( 22 | [Parameter(Position=0,Mandatory=$True,HelpMessage="Enter a computername")] 23 | [ValidateNotNullorEmpty()] 24 | [string]$Param 25 | 26 | ) 27 | Begin { 28 | 29 | } #Begin 30 | 31 | Process { 32 | 33 | } #Process 34 | 35 | End { 36 | 37 | } #end 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Tips-Tricks/Append-Begin&END.ps1: -------------------------------------------------------------------------------- 1 | $Lines = Get-Content .\AMDisabledComputers.txt 2 | $OutputPath = "C:\scripts\AMDisabledComputers.csv" 3 | foreach ($Line in $Lines) { 4 | $Line = $line.Insert(0,'"') 5 | $Line += '"' 6 | Write-Host $Line -ForegroundColor Green 7 | Write-Output $Line | Out-File $OutputPath -Append 8 | } 9 | -------------------------------------------------------------------------------- /Tips-Tricks/Convert-FirstCharToUpper.ps1: -------------------------------------------------------------------------------- 1 | 2 | $givenname = Read-Host "First Name:" 3 | 4 | 5 | $sn = Read-Host "Last Name:" 6 | 7 | 8 | 9 | 10 | #Converts first letter of First/Lastname to uppercase 11 | 12 | 13 | $givenname = $givenname.substring(0,1).toupper()+$givenname.substring(1).tolower() 14 | 15 | 16 | $sn = $sn.substring(0,1).toupper()+$sn.substring(1).tolower() 17 | 18 | #Source http://www.sysctr.info/2012/05/powershell-converting-first-character.html 19 | -------------------------------------------------------------------------------- /Tips-Tricks/Examples.ps1: -------------------------------------------------------------------------------- 1 | #ISE Shortcuts 2 | https://technet.microsoft.com/en-us/library/jj984298.aspx 3 | 4 | #Increase PowerShell Font Size 5 | $psISE.Options.Zoom = 145 6 | 7 | #Goes to Conosle 8 | Ctrl + D 9 | 10 | #Goes to Script Pane 11 | Ctrl + I 12 | 13 | #Return limited resutls 14 | Get-aduser -filter * -properties * -resultsetsize 1 15 | 16 | #Clip copies output from a cmdlet 17 | Ipconfig | clip 18 | 19 | #Ctrl + alt to select multipule lines 20 | 21 | #Removing characters from end of variable 22 | $string = $string -replace ".$" 23 | 24 | #Add or Removing characters from start of variable 25 | $var = "Blah" 26 | $var = $var.Insert(0,"01") 27 | 28 | #Open scripts within ISE 29 | psedit .\script1. 30 | 31 | #Ctrl + space to call out intlisense 32 | 33 | #v4 where 34 | $x = gps 35 | $x.where{$_.Name -like "*ss"} 36 | 37 | $x = gps 38 | $x.where{$_.Name -like "*ss"}.Name 39 | 40 | ##Awesome PS module | show-object 41 | Install-Module PowerShellCookbook 42 | gps | show-object 43 | -------------------------------------------------------------------------------- /Tips-Tricks/HashTables.ps1: -------------------------------------------------------------------------------- 1 | #Creating Hash table 2 | $hash=@{ 3 | Computername=$cs.Name 4 | Workgroup=$cs.WorkGroup 5 | AdminPassword=$aps 6 | Model=$cs.Model 7 | Manufacturer=$cs.Manufacturer 8 | } 9 | #Adding lines to hash table 10 | $os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer 11 | $hash.Add("Version",$os.Version) 12 | $hash.Add("ServicePackMajorVersion",$os.ServicePackMajorVersion) 13 | 14 | #add values to properties that dont exist 15 | $splat = @{Properties=('Managedby','whencreated');Identity='testgroup';server='domain.com'} 16 | if(!$splat.Properties.Contains('member')){$splat.Properties = $splat.Properties += 'member'} 17 | -------------------------------------------------------------------------------- /Tips-Tricks/debug.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param() 3 | $data = Import-Csv C:\scripts\data.csv 4 | Write-Debug "Imported CSV data" 5 | 6 | $totalqty = 0 7 | $totalsold = 0 8 | $totalbought = 0 9 | 10 | foreach ($line in $data) { 11 | if ($line.transaction -eq 'buy') { 12 | Write-Debug "ENDED BUY transaction (we sold)" 13 | $totalqty -= $line.qty 14 | $totalsold = $line.total 15 | } else { 16 | Write-Debug "ENDED SELL transaction (we bought)" 17 | $totalqty += $line.qty 18 | $totalbought = $line.total 19 | } 20 | } 21 | Write-Debug "OUTPUT: $totalqty,$totalbought,$totalsold,$($totalbought-$totalsold)" 22 | "totalqty,totalboght,totalsold,totalamt" | Out-File C:\scripts\summary.csv 23 | "$totalqty,$totalbought,$totalsold,$($totalbought-$totalsold)" | Out-File C:\scripts\summary.csv -Append 24 | -------------------------------------------------------------------------------- /Utilities/Convert-PullServerModules.ps1: -------------------------------------------------------------------------------- 1 | $Computer = 'HCD01' 2 | 3 | Get-DscResource | 4 | where path -match "c:\\Program Files\\WindowsPowerShell\\Modules" | 5 | Select -expandProperty Module -Unique | 6 | foreach { 7 | $out = "{0}_{1}.zip" -f $_.Name,$_.Version 8 | $zip = Join-Path -path "C:\Program Files\WindowsPowerShell\DscService\Modules" -ChildPath $out 9 | New-ZipArchive -path $_.ModuleBase -OutputPath $zip -Passthru 10 | #give file a chance to close 11 | start-sleep -Seconds 1 12 | If (Test-Path $zip) { 13 | Try { 14 | New-DSCCheckSum -ConfigurationPath $zip -ErrorAction Stop 15 | } 16 | Catch { 17 | Write-Warning "Failed to create checksum for $zip" 18 | } 19 | } 20 | else { 21 | Write-Warning "Failed to find $zip" 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Utilities/Create-PullServerModule.ps1: -------------------------------------------------------------------------------- 1 | $source = "C:\Program Files\WindowsPowerShell\Modules\xTimeZone" 2 | 3 | $destination = "$Env:PROGRAMFILES\WindowsPowerShell\DscService\Modules\" 4 | 5 | $Version = (Get-ChildItem -Path $source -Depth 1).Name[0] 6 | $ResoureName = (Get-ChildItem -Path $source -Depth 1).Parent.Name[0] 7 | $ModuleName = $ResoureName+'_'+$Version 8 | 9 | New-Item -Path ($destination+'\'+$ModuleName) -ItemType Directory 10 | 11 | Get-ChildItem ($source+'\'+$Version) | Copy-Item -Destination ($destination+'\'+$ModuleName) -Recurse 12 | 13 | $destinationZip = ($destination+'\'+$ModuleName)+'.zip' 14 | 15 | 16 | 17 | If(Test-path $destinationZip) {Remove-item $destinationZip -Force} 18 | 19 | Add-Type -assembly "system.io.compression.filesystem" 20 | 21 | [io.compression.zipfile]::CreateFromDirectory(($destination+'\'+$ModuleName), $destinationZip) 22 | 23 | Remove-Item -Path ($destination+'\'+$ModuleName) -Force 24 | 25 | New-DscCheckSum -ConfigurationPath $destinationZip -OutPath $destination -Verbose -Force 26 | -------------------------------------------------------------------------------- /Utilities/Get-MachineCert.ps1: -------------------------------------------------------------------------------- 1 | Function Export-MachineCert { 2 | <# 3 | .SYNOPSIS 4 | Harvests a certificate from a remote system. 5 | .DESCRIPTION 6 | Invokes a command on a remote system to copy the certificate to the machine running the command. 7 | .PARAMETER Computername 8 | Specifies the name of the remote system to harvest the certificate. 9 | .PARAMETER Path 10 | Provides the path where the certificate is copied to on the host system. 11 | .PARAMETER Template 12 | Specifies the template used when generating the certificate on the remote system. 13 | .EXAMPLE 14 | 15 | Requires PowerShell version 4 16 | #> 17 | [cmdletbinding()] 18 | Param( 19 | [ValidateNotNullorEmpty()] 20 | [string]$computername = $env:COMPUTERNAME, 21 | [ValidateScript({Test-Path $_})] 22 | [string]$Path="$env:SystemDrive\Certs", 23 | [ValidateSet("Client Authentication","Server Authentication")] 24 | [string]$Template 25 | 26 | 27 | ) 28 | 29 | Try { 30 | #assumes a single certificate so sort on NotAfter 31 | Write-Verbose "Querying $computername for Machine certificates" 32 | $cert = invoke-command -scriptblock { 33 | Get-ChildItem Cert:\LocalMachine\my | 34 | Where-Object {$_.EnhancedKeyUsageList.FriendlyName -contains $Template -AND $_.notAfter -gt (Get-Date) } | 35 | Sort-Object NotAfter -Descending | Select -first 1 36 | } -computername $computername -ErrorAction Stop 37 | write-verbose ($cert | out-string) 38 | } 39 | Catch { 40 | Throw $_ 41 | } 42 | 43 | if ($cert) { 44 | 45 | #verify and export 46 | if (Test-Certificate $cert) { 47 | 48 | $exportPath = Join-path -Path $Path -ChildPath "$computername.cer" 49 | Write-Verbose "Exporting certificate for $($cert.subject.trim()) to $exportpath" 50 | [pscustomobject]@{ 51 | Computername = $cert.Subject.Substring(3) 52 | Thumbprint = $cert.Thumbprint 53 | Path = Export-Certificate -Cert $cert -FilePath $exportPath 54 | } 55 | 56 | } #if Test OK $cert 57 | else { 58 | Write-Warning "Failed to verify or find a certificate" 59 | } 60 | } #if $cert 61 | } #Export-MachineCert -------------------------------------------------------------------------------- /Utilities/Get-MediaFileDuration.ps1: -------------------------------------------------------------------------------- 1 | #$path = 'C:\Users\duffney\Dropbox\josh-duffney\regular-expression-introduction\regular-expression-introduction-m1\regular-expression-introduction-m1-01.mp4' 2 | 3 | $Files = (Get-ChildItem -Path 'C:\Users\duffney\Dropbox\josh-duffney\regular-expression-introduction\*.mp4' -Recurse | where fullname -NotMatch 'old').fullname 4 | #$files = (Get-ChildItem -Path 'C:\Users\duffney\Dropbox\josh-duffney\regular-expression-introduction\regular-expression-introduction-m6\*.mp4' -Recurse | where fullname -NotMatch 'old').fullname 5 | $totaltime = $null 6 | 7 | foreach ($file in $Files){ 8 | 9 | $shell = New-Object -COMObject Shell.Application 10 | $folder = Split-Path $file 11 | $file = Split-Path $file -Leaf 12 | $shellfolder = $shell.Namespace($folder) 13 | $shellfile = $shellfolder.ParseName($file) 14 | 15 | #write-host $shellfolder.GetDetailsOf($shellfile, 27); 16 | 17 | $time = $shellfolder.GetDetailsOf($shellfile, 27) -replace '(\d+:0?)?([^0])','$2' 18 | $time = $time -replace ':','.' 19 | $time = [math]::round($time,2) 20 | 21 | Write-Host $time -ForegroundColor Green 22 | Write-Host $file -ForegroundColor red 23 | 24 | $totaltime += $time 25 | 26 | } 27 | 28 | $totaltime 29 | 30 | #$time = '4:07' 31 | #$timearry = $time.Split(':') 32 | # 33 | #$totaltime += New-TimeSpan -Minutes $timearry[0] 34 | #$totaltime += New-TimeSpan -Seconds $timearry[1] -------------------------------------------------------------------------------- /WMI/Examples.ps1: -------------------------------------------------------------------------------- 1 | Get-WmiObject -class Win32_LogicalDisk -Filter "DriveType=3" 2 | 3 | Get-WmiObject -Namespace root\cimv2 -list | where name -like "*configuration*" | sort name 4 | 5 | Get-WmiObject -Namespace root\cimv2 -list | where name -like "*operating*" | sort name 6 | 7 | Get-WmiObject -class Win32_ComputerSystem | Select Manufacturer,Model,@{n='RAM';e={$PSItem.TotalPhysicalMemory}} 8 | 9 | Get-WmiObject -Class Win32_Service -Filter "Name LIKE 'S%'" | select Name,State,StartName 10 | 11 | Get-WmiObject -class Win32_service -Filter "Name='WinRM'" | Invoke-WmiMethod -Name ChangeStartMode -Argument 'Automatic' 12 | 13 | Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | Format-Table -Property @{n='Drive Letter';e={$PSItem.DeviceID}},@{n='Free Space(GB)';e={$PSItem.FreeSpace / 1GB};formatstring='N0'},@{n='% Free Space';e={$PSItem.FreeSpace / $PSitem.Size * 100};formatstring='N0'} 14 | -------------------------------------------------------------------------------- /WMI/Get-OSVersion.ps1: -------------------------------------------------------------------------------- 1 | $Catalog = GC "C:\test\dp.txt" 2 | ForEach($Machine in $Catalog) 3 | {$QueryString = Gwmi Win32_OperatingSystem -Comp $Machine 4 | $QueryString = $QueryString.Caption 5 | Write-Host $QueryString} 6 | -------------------------------------------------------------------------------- /profile.ps1: -------------------------------------------------------------------------------- 1 | set-alias vi "C:\Program Files (x86)\Vim\vim74\vim.exe" 2 | set-alias vim "C:\Program Files (x86)\Vim\vim74\vim.exe" 3 | 4 | Set-Location -Path $env:SystemDrive\ 5 | Clear-Host 6 | 7 | $Error.Clear() 8 | Import-Module -Name posh-git -ErrorAction SilentlyContinue 9 | 10 | if (-not($Error[0])) { 11 | $DefaultTitle = $Host.UI.RawUI.WindowTitle 12 | $GitPromptSettings.BeforeText = '(' 13 | $GitPromptSettings.BeforeForegroundColor = [ConsoleColor]::Cyan 14 | $GitPromptSettings.AfterText = ')' 15 | $GitPromptSettings.AfterForegroundColor = [ConsoleColor]::Cyan 16 | 17 | function prompt { 18 | 19 | if (-not(Get-GitDirectory)) { 20 | $Host.UI.RawUI.WindowTitle = $DefaultTitle 21 | "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " 22 | } 23 | else { 24 | $realLASTEXITCODE = $LASTEXITCODE 25 | 26 | Write-Host 'PS ' -ForegroundColor Green -NoNewline 27 | Write-Host "$($executionContext.SessionState.Path.CurrentLocation) " -ForegroundColor Yellow -NoNewline 28 | 29 | Write-VcsStatus 30 | 31 | $LASTEXITCODE = $realLASTEXITCODE 32 | return "`n$('$' * ($nestedPromptLevel + 1)) " 33 | } 34 | 35 | } 36 | 37 | } 38 | else { 39 | Write-Warning -Message 'Unable to load the Posh-Git PowerShell Module' 40 | } -------------------------------------------------------------------------------- /test.ps1: -------------------------------------------------------------------------------- 1 | foreach ($item in $collection) 2 | { 3 | 4 | } --------------------------------------------------------------------------------