├── .github └── CODEOWNERS ├── .gitignore ├── .hgtags ├── CHANGELOG.md ├── Carbon.nuspec ├── Carbon ├── Carbon.format.ps1xml ├── Carbon.psd1 ├── Carbon.psm1 ├── Carbon.psm1.Import.Iis.ps1 ├── Carbon.psm1.Import.Lcm.ps1 ├── Carbon.psm1.Import.Obsolete.ps1 ├── Carbon.psm1.Import.Post.ps1 ├── DscResources │ ├── Carbon_EnvironmentVariable │ │ ├── Carbon_EnvironmentVariable.psm1 │ │ └── Carbon_EnvironmentVariable.schema.mof │ ├── Carbon_FirewallRule │ │ ├── Carbon_FirewallRule.psm1 │ │ └── Carbon_FirewallRule.schema.mof │ ├── Carbon_Group │ │ ├── Carbon_Group.psm1 │ │ └── Carbon_Group.schema.mof │ ├── Carbon_IniFile │ │ ├── Carbon_IniFile.psm1 │ │ └── Carbon_IniFile.schema.mof │ ├── Carbon_Permission │ │ ├── Carbon_Permission.psm1 │ │ └── Carbon_Permission.schema.mof │ ├── Carbon_Privilege │ │ ├── Carbon_Privilege.psm1 │ │ └── Carbon_Privilege.schema.mof │ ├── Carbon_ScheduledTask │ │ ├── Carbon_ScheduledTask.psm1 │ │ └── Carbon_ScheduledTask.schema.mof │ ├── Carbon_Service │ │ ├── Carbon_Service.psm1 │ │ └── Carbon_Service.schema.mof │ └── Initialize-CarbonDscResource.ps1 ├── Formats │ ├── Carbon.Security.HttpUrlAcl.format.ps1xml │ └── Schedule.Service.RegisteredTask.format.ps1xml ├── Functions │ ├── Add-GroupMember.ps1 │ ├── Add-TrustedHost.ps1 │ ├── Assert-AdminPrivilege.ps1 │ ├── Assert-FirewallConfigurable.ps1 │ ├── Assert-Service.ps1 │ ├── Assert-WindowsFeatureFunctionsSupported.ps1 │ ├── Clear-DscLocalResourceCache.ps1 │ ├── Clear-MofAuthoringMetadata.ps1 │ ├── Clear-TrustedHost.ps1 │ ├── Compress-Item.ps1 │ ├── Convert-XmlFile.ps1 │ ├── ConvertFrom-Base64.ps1 │ ├── ConvertTo-CArgValue.ps1 │ ├── Copy-DscResource.ps1 │ ├── Disable-AclInheritance.ps1 │ ├── Disable-FirewallStatefulFtp.ps1 │ ├── Disable-IEEnhancedSecurityConfiguration.ps1 │ ├── Disable-NtfsCompression.ps1 │ ├── Enable-AclInheritance.ps1 │ ├── Enable-FirewallStatefulFtp.ps1 │ ├── Enable-IEActivationPermission.ps1 │ ├── Enable-NtfsCompression.ps1 │ ├── Expand-Item.ps1 │ ├── Find-ADUser.ps1 │ ├── Format-ADSearchFilterValue.ps1 │ ├── Get-ADDomainController.ps1 │ ├── Get-CCimClass.ps1 │ ├── Get-CCimInstance.ps1 │ ├── Get-CertificateStore.ps1 │ ├── Get-ComPermission.ps1 │ ├── Get-ComSecurityDescriptor.ps1 │ ├── Get-DscError.ps1 │ ├── Get-DscWinEvent.ps1 │ ├── Get-FileShare.ps1 │ ├── Get-FileSharePermission.ps1 │ ├── Get-FileShareSecurityDescriptor.ps1 │ ├── Get-FirewallRule.ps1 │ ├── Get-Group.ps1 │ ├── Get-HttpUrlAcl.ps1 │ ├── Get-IPAddress.ps1 │ ├── Get-IdentityPrincipalContext.ps1 │ ├── Get-MsmqMessageQueue.ps1 │ ├── Get-MsmqMessageQueuePath.ps1 │ ├── Get-PathProvider.ps1 │ ├── Get-PathToHostsFile.ps1 │ ├── Get-PerformanceCounter.ps1 │ ├── Get-PowerShellModuleInstallPath.ps1 │ ├── Get-Principal.ps1 │ ├── Get-ProgramInstallInfo.ps1 │ ├── Get-ServiceAcl.ps1 │ ├── Get-ServiceConfiguration.ps1 │ ├── Get-ServicePermission.ps1 │ ├── Get-ServiceSecurityDescriptor.ps1 │ ├── Get-TrustedHost.ps1 │ ├── Get-User.ps1 │ ├── Get-WmiLocalUserAccount.ps1 │ ├── Grant-ComPermission.ps1 │ ├── Grant-HttpUrlPermission.ps1 │ ├── Grant-MsmqMessageQueuePermission.ps1 │ ├── Grant-ServiceControlPermission.ps1 │ ├── Grant-ServicePermission.ps1 │ ├── Initialize-Lcm.ps1 │ ├── Install-Directory.ps1 │ ├── Install-FileShare.ps1 │ ├── Install-Group.ps1 │ ├── Install-Junction.ps1 │ ├── Install-MsmqMessageQueue.ps1 │ ├── Install-PerformanceCounter.ps1 │ ├── Install-Service.ps1 │ ├── Install-User.ps1 │ ├── Invoke-CCimMethod.ps1 │ ├── Invoke-ConsoleCommand.ps1 │ ├── New-Credential.ps1 │ ├── New-Junction.ps1 │ ├── New-TempDirectory.ps1 │ ├── Read-File.ps1 │ ├── Remove-DotNetAppSetting.ps1 │ ├── Remove-EnvironmentVariable.ps1 │ ├── Remove-GroupMember.ps1 │ ├── Remove-HostsEntry.ps1 │ ├── Remove-IniEntry.ps1 │ ├── Remove-Junction.ps1 │ ├── Reset-HostsFile.ps1 │ ├── Reset-MsmqQueueManagerID.ps1 │ ├── Resolve-PathCase.ps1 │ ├── Resolve-RelativePath.ps1 │ ├── Restart-RemoteService.ps1 │ ├── Revoke-ComPermission.ps1 │ ├── Revoke-HttpUrlPermission.ps1 │ ├── Revoke-ServicePermission.ps1 │ ├── Set-DotNetAppSetting.ps1 │ ├── Set-DotNetConnectionString.ps1 │ ├── Set-EnvironmentVariable.ps1 │ ├── Set-HostsEntry.ps1 │ ├── Set-IniEntry.ps1 │ ├── Set-ServiceAcl.ps1 │ ├── Set-TrustedHost.ps1 │ ├── Split-Ini.ps1 │ ├── Start-DscPullConfiguration.ps1 │ ├── Start-PowerShellProcess.ps1 │ ├── Test-AdminPrivilege.ps1 │ ├── Test-CCimAvailable.ps1 │ ├── Test-DotNet.ps1 │ ├── Test-DscTargetResource.ps1 │ ├── Test-FileShare.ps1 │ ├── Test-FirewallStatefulFtp.ps1 │ ├── Test-Group.ps1 │ ├── Test-GroupMember.ps1 │ ├── Test-IPAddress.ps1 │ ├── Test-MsmqMessageQueue.ps1 │ ├── Test-NtfsCompression.ps1 │ ├── Test-PathIsJunction.ps1 │ ├── Test-PerformanceCounter.ps1 │ ├── Test-PerformanceCounterCategory.ps1 │ ├── Test-Service.ps1 │ ├── Test-TypeDataMember.ps1 │ ├── Test-UncPath.ps1 │ ├── Test-User.ps1 │ ├── Test-ZipFile.ps1 │ ├── Uninstall-Directory.ps1 │ ├── Uninstall-FileShare.ps1 │ ├── Uninstall-Group.ps1 │ ├── Uninstall-Junction.ps1 │ ├── Uninstall-MsmqMessageQueue.ps1 │ ├── Uninstall-PerformanceCounterCategory.ps1 │ ├── Uninstall-Service.ps1 │ ├── Uninstall-User.ps1 │ ├── Use-CallerPreference.ps1 │ ├── Write-CCimError.ps1 │ ├── Write-DscError.ps1 │ └── Write-File.ps1 ├── Import-Carbon.ps1 ├── bin │ ├── Ionic.Zip.dll │ ├── Protect-String.ps1 │ ├── Remove-DotNetAppSetting.ps1 │ ├── Remove-EnvironmentVariable.ps1 │ ├── Set-DotNetAppSetting.ps1 │ ├── Set-DotNetConnectionString.ps1 │ ├── Set-EnvironmentVariable.ps1 │ └── Use-CarbonPrefix.ps1 └── en-US │ ├── about_Carbon.help.txt │ ├── about_Carbon_2.0.help.txt │ ├── about_Carbon_Contributing.help.txt │ ├── about_Carbon_Extended_Type_Data.help.txt │ ├── about_Carbon_Installation.help.txt │ └── about_Carbon_Support.help.txt ├── Complete-CarbonTest.ps1 ├── Format-TestResult.ps1 ├── Get-CarbonZipArtifact.ps1 ├── Get-PrivilegeList.ps1 ├── Icon.pdn ├── Import-BitbucketIssueToGithub.ps1 ├── Initialize-Server.ps1 ├── Install-Website.ps1 ├── Invoke-CarbonBladeTest.ps1 ├── LICENSE.txt ├── Lib └── Microsoft.Web.XmlTransform.dll ├── NOTICE.txt ├── New-Website.ps1 ├── Publish-Carbon.ps1 ├── README.md ├── Save-CarbonSigningKey.ps1 ├── Source ├── Carbon.csproj ├── Carbon.sln ├── Certificates │ └── SslCertificateBinding.cs ├── Computer │ └── ProgramInstallInfo.cs ├── Firewall │ ├── Rule.cs │ ├── RuleAction.cs │ ├── RuleDirection.cs │ ├── RuleEdgeTraversalPolicy.cs │ ├── RuleInterfaceType.cs │ ├── RuleProfile.cs │ └── RuleSecurity.cs ├── IO │ ├── File.cs │ ├── FileInfo.cs │ ├── JunctionPoint.cs │ ├── Path.cs │ ├── ReparseData.cs │ ├── ReparsePoint.cs │ └── SymbolicLink.cs ├── Identity.cs ├── IdentityType.cs ├── Iis │ ├── Carbon.Iis.csproj │ ├── HttpHeader.cs │ ├── HttpRedirectConfigurationSection.cs │ ├── HttpResponseStatus.cs │ ├── MimeMap.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Ini │ └── IniNode.cs ├── Msi │ └── MsiInfo.cs ├── Properties │ └── AssemblyInfo.cs ├── Security │ ├── ComAccessRights.cs │ ├── ComAccessRule.cs │ ├── ContainerInheritanceFlags.cs │ ├── HttpUrlAccessRights.cs │ ├── HttpUrlAccessRule.cs │ ├── HttpUrlSecurity.cs │ ├── Privilege.cs │ ├── SecureStringConverter.cs │ ├── ServiceAccessRights.cs │ ├── ServiceAccessRule.cs │ ├── ShareAccessRule.cs │ └── ShareRights.cs ├── Service │ ├── ErrorControl.cs │ ├── FailureAction.cs │ ├── ServiceInfo.cs │ ├── ServiceSecurity.cs │ └── StartType.cs ├── Shell │ └── Command.cs ├── TaskScheduler │ ├── Months.cs │ ├── ScheduleInfo.cs │ ├── ScheduleType.cs │ ├── TaskInfo.cs │ └── WeekOfMonth.cs ├── Test │ ├── Carbon.Test.csproj │ ├── Certificates │ │ └── SslCertificateBindingTestFixture.cs │ ├── Firewall │ │ └── RuleTests.cs │ ├── IO │ │ ├── FileInfoTestFixture.cs │ │ ├── FileTestFixture.cs │ │ ├── JunctionPointTestFixture.cs │ │ └── ReparsePointTestFixture.cs │ ├── IdentityTest.cs │ ├── Installer │ │ ├── Carbon.Test.Installer.csproj │ │ ├── Installer1.Designer.cs │ │ ├── Installer1.cs │ │ └── Properties │ │ │ └── AssemblyInfo.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Security │ │ ├── PrivilegeTests.cs │ │ ├── SecureStringConverter.cs │ │ └── UrlSecurityTests.cs │ ├── Service │ │ ├── ServiceInfoTestFixture.cs │ │ └── ServiceSecurityTests.cs │ └── Xdt │ │ └── Merge.cs ├── Win32 │ └── Win32ErrorCodes.cs └── Xdt │ ├── Carbon.Xdt.csproj │ ├── PSHostUserInterfaceTransformationLogger.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── XdtTransformationException.cs ├── Start-CarbonTest.ps1 ├── System.Exception.format.ps1xml ├── System.Management.Automation.ErrorRecord.format.ps1xml ├── Test ├── ActiveDirectory │ ├── Test-FindADUser.ps1 │ ├── Test-FormatADSearchFilterValue.ps1 │ └── Test-GetADDomainController.ps1 ├── Add-GroupMember.Tests.ps1 ├── Add-TrustedHost.Tests.ps1 ├── Assert-FirewallConfigurable.Tests.ps1 ├── Bin.Tests.ps1 ├── Carbon.Shell.Command.Tests.ps1 ├── CarbonDscTest │ ├── CarbonDscTest.psm1 │ └── ScheduledTask.ps1 ├── CarbonTest.psm1 ├── CarbonVersion.Tests.ps1 ├── Carbon_EnvironmentVariable.Tests.ps1 ├── Carbon_FirewallRule.Tests.ps1 ├── Carbon_Group.Tests.ps1 ├── Carbon_IniFile.Tests.ps1 ├── Carbon_Permission.Tests.ps1 ├── Carbon_Privilege.Tests.ps1 ├── Carbon_ScheduledTask.Tests.ps1 ├── Carbon_Service.Tests.ps1 ├── Certificates │ ├── CarbonRsaCng.cer │ ├── CarbonRsaCng.pfx │ ├── CarbonTestCertificate.cer │ ├── CarbonTestCertificateWithPassword.cer │ ├── Test-GetCertificateStore.ps1 │ ├── Test-RemoveSslCertificateBinding.ps1 │ ├── Test-SetSslCertificateBinding.ps1 │ └── Test-X509StoreProperties.ps1 ├── Clear-MofAuthoringMetadata.Tests.ps1 ├── Clear-TrustedHost.Tests.ps1 ├── Compress-Item.Tests.ps1 ├── Convert-CXmlFile.Tests.ps1 ├── Copy-DscResource.Tests.ps1 ├── Cryptography │ ├── CarbonTestPrivateKey.pfx │ ├── CarbonTestPrivateKey2.pfx │ └── CarbonTestPublicKey.cer ├── DSC │ └── Test-InitializeLcm.ps1 ├── Disable-AclInheritance.Tests.ps1 ├── Disable-NtfsCompression.Tests.ps1 ├── Documentation.Tests.ps1 ├── DotNet │ ├── Test-SetDotNetAppSetting.ps1 │ └── Test-SetDotNetConnectionString.ps1 ├── Enable-AclInheritance.Tests.ps1 ├── Enable-NtfsCompression.Tests.ps1 ├── FileSystem │ ├── Test-DirectoryInfoTypeExtensions.ps1 │ ├── Test-ExpandItem.ps1 │ ├── Test-NewTempDirectory.ps1 │ ├── Test-TestNtfsCompression.ps1 │ └── Test-TestZipFile.ps1 ├── Firewall │ ├── Test-DisableFirewallStatefulFtp.ps1 │ └── Test-EnableFirewallStatefulFtp.ps1 ├── Get-CFileShare.Tests.ps1 ├── Get-CFileSharePermission.Tests.ps1 ├── Get-CFirewallRule.Tests.ps1 ├── Get-ComPermission.Tests.ps1 ├── Get-DscError.Tests.ps1 ├── Get-Group.Tests.ps1 ├── Get-HttpUrlAcl.Tests.ps1 ├── Get-PathProvider.Tests.ps1 ├── Get-PowerShellModuleInstallPath.Tests.ps1 ├── Get-ServiceConfiguration.Tests.ps1 ├── Get-SslCertificateBinding.Tests.ps1 ├── Get-User.Tests.ps1 ├── Grant-ComPermission.Tests.ps1 ├── Grant-ServicePermission.Tests.ps1 ├── Import-Carbon.Tests.ps1 ├── Ini │ └── Test-SplitIni.ps1 ├── Initialize-CarbonTest.ps1 ├── Install-CFileShare.Tests.ps1 ├── Install-Group.Tests.ps1 ├── Install-Junction.Tests.ps1 ├── Install-Service.Tests.ps1 ├── Install-User.Tests.ps1 ├── LicenseNotices.Tests.ps1 ├── MSMQ │ ├── Test-GetMSMQMessageQueue.ps1 │ ├── Test-InstallMSMQMessageQueue.ps1 │ ├── Test-RemoveMSMQMessageQueue.ps1 │ └── Test-TestMSMQMessageQueue.ps1 ├── Network │ ├── Test-GetIPAddress.ps1 │ └── Test-TestIPAddress.ps1 ├── New-Junction.Tests.ps1 ├── Path │ ├── Test-ResolveRelativePath.ps1 │ └── Test-TestUncPath.ps1 ├── PerformanceCounters │ ├── Test-GetPerformanceCounter.ps1 │ ├── Test-InstallPerformanceCounter.ps1 │ └── Test-UninstallPerformanceCounterCategory.ps1 ├── PowerShell │ ├── Get-PSVersionTable.ps1 │ └── Get-Username.ps1 ├── Read-File.Tests.ps1 ├── Remove-DotNetAppSetting.Tests.ps1 ├── Remove-EnvironmentVariable.Tests.ps1 ├── Remove-GroupMember.Tests.ps1 ├── Remove-HostsEntry.Tests.ps1 ├── Remove-Junction.Tests.ps1 ├── Reset-HostsFile.Tests.ps1 ├── Resolve-CPathCase.Tests.ps1 ├── ScheduledTasks │ ├── task.xml │ └── task_with_principal.xml ├── Security │ └── Test-NewCredential.ps1 ├── Service │ ├── NoOpService.exe │ ├── NoOpService.pdb │ └── Test-GrantServiceControlPermission.ps1 ├── Set-CIisHttpRedirect.Tests.ps1 ├── Set-EnvironmentVariable.Tests.ps1 ├── Set-HostsEntry.Tests.ps1 ├── Set-TrustedHost.Tests.ps1 ├── System.Diagnostics.Process.types.Tests.ps1 ├── System.IO.DirectoryInfo.types.ps1xml.Tests.ps1 ├── System.IO.FileInfo.types.ps1xml.Tests.ps1 ├── Test-CFileShare.Tests.ps1 ├── Test-CUser.Tests.ps1 ├── Test-GrantHttpUrlPermission.ps1 ├── Test-Group.Tests.ps1 ├── Test-GroupMember.Tests.ps1 ├── Test-InstallDirectory.ps1 ├── Test-PathIsJunction.Tests.ps1 ├── Test-RemoveIniEntry.ps1 ├── Test-RevokeHttpUrlPermission.ps1 ├── Test-Service.Tests.ps1 ├── Test-SetIniEntry.ps1 ├── Test-UninstallDirectory.ps1 ├── Test-UsesUseCallerPreference.ps1 ├── Text │ └── Test-ConvertFromBase64.ps1 ├── Uninstall-CFileShare.Tests.ps1 ├── Uninstall-Group.Tests.ps1 ├── Uninstall-Junction.Tests.ps1 ├── Uninstall-Service.Tests.ps1 ├── UsersAndGroups │ ├── Test-GetWmiLocalUserAccount.ps1 │ └── Test-UninstallUser.ps1 ├── Website.Tests.ps1 ├── Write-DscError.Tests.ps1 ├── Write-File.Tests.ps1 ├── X509Certificate2.Tests.ps1 ├── chocolateyInstall.Tests.ps1 └── chocolateyUninstall.Tests.ps1 ├── Tools ├── Blade │ ├── Blade.psd1 │ ├── Blade.psm1 │ ├── Convert-BladeFixtureToPester.ps1 │ ├── Formats │ │ ├── Blade.RunResult.format.ps1xml │ │ └── Blade.TestResult.format.ps1xml │ ├── Functions │ │ ├── Assert-CEqual.ps1 │ │ ├── Assert-Contains.ps1 │ │ ├── Assert-ContainsLike.ps1 │ │ ├── Assert-ContainsNotLike.ps1 │ │ ├── Assert-DirectoryDoesNotExist.ps1 │ │ ├── Assert-DirectoryExists.ps1 │ │ ├── Assert-DoesNotContain.ps1 │ │ ├── Assert-Empty.ps1 │ │ ├── Assert-Equal.ps1 │ │ ├── Assert-Error.ps1 │ │ ├── Assert-False.ps1 │ │ ├── Assert-FileContains.ps1 │ │ ├── Assert-FileDoesNotContain.ps1 │ │ ├── Assert-FileDoesNotExist.ps1 │ │ ├── Assert-FileExists.ps1 │ │ ├── Assert-GreaterThan.ps1 │ │ ├── Assert-Is.ps1 │ │ ├── Assert-LastError.ps1 │ │ ├── Assert-LastProcessFailed.ps1 │ │ ├── Assert-LastProcessSucceeded.ps1 │ │ ├── Assert-LessThan.ps1 │ │ ├── Assert-Like.ps1 │ │ ├── Assert-Match.ps1 │ │ ├── Assert-NoError.ps1 │ │ ├── Assert-NodeDoesNotExist.ps1 │ │ ├── Assert-NodeExists.ps1 │ │ ├── Assert-NotEmpty.ps1 │ │ ├── Assert-NotEqual.ps1 │ │ ├── Assert-NotNull.ps1 │ │ ├── Assert-Null.ps1 │ │ ├── Assert-That.ps1 │ │ ├── Assert-True.ps1 │ │ ├── Export-RunResultXml.ps1 │ │ ├── New-AssertionException.ps1 │ │ ├── New-TempDirectory.ps1 │ │ ├── New-TempDirectoryTree.ps1 │ │ ├── Remove-ItemWithRetry.ps1 │ │ └── Test-NodeExists.ps1 │ ├── Import-Blade.ps1 │ ├── LICENSE.txt │ ├── bin │ │ └── Blade.dll │ ├── blade.ps1 │ └── en-US │ │ ├── about_Blade.help.txt │ │ ├── about_Blade_Assertions.help.txt │ │ └── about_Blade_Objects.help.txt ├── DotNetZip.1.9.3 │ ├── DotNetZip.1.9.3.nupkg │ └── lib │ │ └── net20 │ │ ├── Ionic.Zip.dll │ │ └── Ionic.Zip.xml ├── MarkdownSharp │ └── MarkdownSharp.dll ├── NUnit │ └── 2.6.2 │ │ ├── nunit.framework.dll │ │ ├── nunit.framework.xml │ │ ├── nunit.mocks.dll │ │ └── pnunit.framework.dll ├── PowerShell │ ├── 2.0 │ │ └── System.Management.Automation.dll │ └── 3.0 │ │ └── System.Management.Automation.dll ├── Silk │ ├── Functions │ │ ├── Convert-AboutTopicToHtml.ps1 │ │ ├── Convert-HelpToHtml.ps1 │ │ ├── Convert-MarkdownToHtml.ps1 │ │ ├── Convert-ModuleHelpToHtml.ps1 │ │ ├── Convert-RelatedLinkToHtml.ps1 │ │ ├── Edit-HelpText.ps1 │ │ ├── Format-ForHtml.ps1 │ │ ├── Get-Function.ps1 │ │ ├── Get-ModuleReleaseNotes.ps1 │ │ ├── Get-ModuleVersion.ps1 │ │ ├── Get-TypeDocumentationLink.ps1 │ │ ├── New-ModuleHelpIndex.ps1 │ │ ├── Out-HtmlString.ps1 │ │ ├── Publish-BitbucketDownload.ps1 │ │ ├── Publish-NuGetPackage.ps1 │ │ ├── Publish-PowerShellGalleryPackage.ps1 │ │ ├── Set-ModuleManifestMetadata.ps1 │ │ ├── Set-ModuleNuspec.ps1 │ │ ├── Set-ModuleVersion.ps1 │ │ ├── Set-ReleaseNotesReleaseDate.ps1 │ │ ├── Split-MarkdownTopic.ps1 │ │ └── Test-ModuleVersion.ps1 │ ├── Import-Silk.ps1 │ ├── Resources │ │ └── silk.css │ ├── Silk.psd1 │ ├── Silk.psm1 │ ├── bin │ │ ├── MarkdownSharp.dll │ │ └── NuGet.exe │ └── en-US │ │ └── about_Silk.help.txt ├── VERIFICATION.md ├── chocolateyInstall.ps1 ├── chocolateyUninstall.ps1 └── xDSCResourceDesigner │ ├── xDSCResourceDesigner.psd1 │ ├── xDSCResourceDesigner.psm1 │ └── xDSCResourceDesigner.strings.psd1 ├── Update-SilkConfig.ps1 ├── appveyor.yml ├── build.ps1 ├── examples ├── Initialize-BuildServer.ps1 └── Initialize-WebServer.ps1 ├── global.json ├── tags.json └── whiskey.yml /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # These owners will be the default owners for everything in 2 | # the repo. The owners will be requested for review when 3 | # someone opens a pull request. 4 | * @webmd-health-services/devops -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Carbon/bin/coreclr 2 | /Carbon/bin/fullclr 3 | /Carbon/bin/args.exe 4 | /Carbon/*.md 5 | **/obj/** 6 | **/.vs/** 7 | Source/**/bin/** 8 | Source/*.suo 9 | Source/.*.user 10 | Source/_ReSharper* 11 | Source/Carbon.snk 12 | Source/**/*.user 13 | *.pdb 14 | Test\MSI\setup.exe 15 | *.snk 16 | *.nupkg 17 | .output/** 18 | PSModules/** 19 | packages/** 20 | Website/** 21 | /Test/MSI/*.tmp 22 | /Test/MSI/setup.exe 23 | /Test/MSI/*.msi 24 | /Test/bin 25 | /Source/CarbonTestInstaller/Debug 26 | /Source/CarbonTestInstaller/Release 27 | /Source/CarbonTestInstallerWithCustomActions/Debug 28 | /Source/CarbonTestInstallerWithCustomActions/Release 29 | Carbon/LICENSE.txt 30 | Carbon/NOTICE.txt 31 | *.orig 32 | /.vscode/** 33 | /.dotnet* -------------------------------------------------------------------------------- /Carbon/Carbon.psm1.Import.Lcm.ps1: -------------------------------------------------------------------------------- 1 | 2 | if( $IsWindows -and [Environment]::Is64BitOperatingSystem -and [Environment]::Is64BitProcess ) 3 | { 4 | Write-Timing ('Dot-sourcing Initialize-Lcm.ps1') 5 | . (Join-Path -Path $functionRoot -ChildPath 'Initialize-Lcm.ps1') 6 | } 7 | -------------------------------------------------------------------------------- /Carbon/DscResources/Carbon_EnvironmentVariable/Carbon_EnvironmentVariable.schema.mof: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | */ 14 | 15 | [ClassVersion("2.0.0.0"), FriendlyName("Carbon_EnvironmentVariable")] 16 | class Carbon_EnvironmentVariable : OMI_BaseResource 17 | { 18 | [Key] String Name; 19 | [Write] String Value; 20 | [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; 21 | }; 22 | 23 | 24 | -------------------------------------------------------------------------------- /Carbon/DscResources/Carbon_FirewallRule/Carbon_FirewallRule.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Carbon/DscResources/Carbon_FirewallRule/Carbon_FirewallRule.schema.mof -------------------------------------------------------------------------------- /Carbon/DscResources/Carbon_Group/Carbon_Group.schema.mof: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | */ 14 | 15 | [ClassVersion("1.0.0.0"), FriendlyName("Carbon_Group")] 16 | class Carbon_Group : OMI_BaseResource 17 | { 18 | [Key, Description("Name of the group to configure.")] String Name; 19 | [Write, Description("Description of the group.")] String Description; 20 | [Write, Description("Determines whether the group is created or deleted"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; 21 | [Write, Description("Members of the group. After configuration, only these members will be in the group.")] String Members[]; 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /Carbon/DscResources/Carbon_IniFile/Carbon_IniFile.schema.mof: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | */ 14 | 15 | [ClassVersion("2.0.0.0"), FriendlyName("Carbon_IniFile")] 16 | class Carbon_IniFile : OMI_BaseResource 17 | { 18 | [Key] 19 | String Path; 20 | 21 | [Write] 22 | String Section; 23 | 24 | [Key] 25 | String Name; 26 | 27 | [Write] 28 | String Value; 29 | 30 | [Write] 31 | boolean CaseSensitive; 32 | 33 | [Write] 34 | boolean Force; 35 | 36 | [Write, 37 | ValueMap{"Present","Absent"}, 38 | Values{"Present","Absent"}] 39 | String Ensure; 40 | }; 41 | 42 | 43 | -------------------------------------------------------------------------------- /Carbon/DscResources/Carbon_Permission/Carbon_Permission.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Carbon/DscResources/Carbon_Permission/Carbon_Permission.schema.mof -------------------------------------------------------------------------------- /Carbon/DscResources/Carbon_Privilege/Carbon_Privilege.schema.mof: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | */ 14 | 15 | [ClassVersion("2.0.0.0"), FriendlyName("Carbon_Privilege")] 16 | class Carbon_Privilege : OMI_BaseResource 17 | { 18 | [Key] 19 | string Identity; 20 | 21 | [Write] 22 | string Privilege[]; 23 | 24 | [Write, 25 | ValueMap{"Present","Absent"}, 26 | Values{"Present","Absent"}] 27 | string Ensure; 28 | }; 29 | -------------------------------------------------------------------------------- /Carbon/DscResources/Carbon_ScheduledTask/Carbon_ScheduledTask.schema.mof: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | */ 14 | 15 | [ClassVersion("2.0.0.0"), FriendlyName("Carbon_ScheduledTask")] 16 | class Carbon_ScheduledTask : OMI_BaseResource 17 | { 18 | [Key] 19 | string Name; 20 | 21 | [Write] 22 | string TaskXml; 23 | 24 | [Write, 25 | EmbeddedInstance("MSFT_Credential")] 26 | string TaskCredential; 27 | 28 | [Write, 29 | ValueMap{"Present","Absent"}, 30 | Values{"Present","Absent"}] 31 | String Ensure; 32 | }; 33 | -------------------------------------------------------------------------------- /Carbon/DscResources/Carbon_Service/Carbon_Service.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Carbon/DscResources/Carbon_Service/Carbon_Service.schema.mof -------------------------------------------------------------------------------- /Carbon/DscResources/Initialize-CarbonDscResource.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Configures PowerShell so that Carbon's DSC resources can use Carbon functions/commands. 4 | #> 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | [CmdletBinding()] 17 | param( 18 | ) 19 | 20 | #Requires -Version 4 21 | Set-StrictMode -Version 'Latest' 22 | 23 | Write-Verbose ('Checking if Carbon module loaded.') 24 | if( -not (Get-Module -Name 'Carbon') ) 25 | { 26 | Write-Verbose ('Loading Carbon module.') 27 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\Carbon.psd1' -Resolve) -Global 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Carbon/Functions/Add-TrustedHost.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Add-CTrustedHost 3 | { 4 | <# 5 | .SYNOPSIS 6 | Adds an item to the computer's list of trusted hosts. 7 | 8 | .DESCRIPTION 9 | Adds an entry to this computer's list of trusted hosts. If the item already exists, nothing happens. 10 | 11 | PowerShell Remoting needs to be turned on for this function to work. 12 | 13 | .LINK 14 | Enable-PSRemoting 15 | 16 | .EXAMPLE 17 | Add-CTrustedHost -Entry example.com 18 | 19 | Adds `example.com` to the list of this computer's trusted hosts. If `example.com` is already on the list of trusted hosts, nothing happens. 20 | #> 21 | [CmdletBinding(SupportsShouldProcess=$true)] 22 | param( 23 | [Parameter(Mandatory=$true)] 24 | [string[]] 25 | [Alias("Entries")] 26 | # The computer name(s) to add to the trusted hosts 27 | $Entry 28 | ) 29 | 30 | Set-StrictMode -Version 'Latest' 31 | 32 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 33 | 34 | $trustedHosts = @( Get-CTrustedHost ) 35 | $newEntries = @() 36 | 37 | $Entry | ForEach-Object { 38 | if( $trustedHosts -notcontains $_ ) 39 | { 40 | $trustedHosts += $_ 41 | $newEntries += $_ 42 | } 43 | } 44 | 45 | if( $pscmdlet.ShouldProcess( "trusted hosts", "adding $( ($newEntries -join ',') )" ) ) 46 | { 47 | Set-CTrustedHost -Entry $trustedHosts 48 | } 49 | } 50 | 51 | Set-Alias -Name 'Add-TrustedHosts' -Value 'Add-CTrustedHost' 52 | -------------------------------------------------------------------------------- /Carbon/Functions/Assert-AdminPrivilege.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Assert-CAdminPrivilege 3 | { 4 | <# 5 | .SYNOPSIS 6 | Writes an error and returns false if the user doesn't have administrator privileges. 7 | 8 | .DESCRIPTION 9 | Many scripts and functions require the user to be running as an administrator. This function checks if the user is running as an administrator or with administrator privileges and writes an error if the user doesn't. 10 | 11 | .LINK 12 | Test-CAdminPrivilege 13 | 14 | .EXAMPLE 15 | Assert-CAdminPrivilege 16 | 17 | Writes an error that the user doesn't have administrator privileges. 18 | #> 19 | [CmdletBinding()] 20 | param( 21 | ) 22 | 23 | Set-StrictMode -Version 'Latest' 24 | 25 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 26 | 27 | if( -not (Test-CAdminPrivilege) ) 28 | { 29 | Write-Error "You are not currently running with administrative privileges. Please re-start PowerShell as an administrator (right-click the PowerShell application, and choose ""Run as Administrator"")." 30 | return $false 31 | } 32 | return $true 33 | } 34 | 35 | Set-Alias -Name 'Assert-AdminPrivileges' -Value 'Assert-CAdminPrivilege' 36 | 37 | -------------------------------------------------------------------------------- /Carbon/Functions/Assert-FirewallConfigurable.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Assert-CFirewallConfigurable 3 | { 4 | <# 5 | .SYNOPSIS 6 | Asserts that the Windows firewall is configurable and writes an error if it isn't. 7 | 8 | .DESCRIPTION 9 | The Windows firewall can only be configured if it is running. This function checks test if it is running. If it isn't, it writes out an error and returns `False`. If it is running, it returns `True`. 10 | 11 | .OUTPUTS 12 | System.Boolean. 13 | 14 | .EXAMPLE 15 | Assert-CFirewallConfigurable 16 | 17 | Returns `True` if the Windows firewall can be configured, `False` if it can't. 18 | #> 19 | [CmdletBinding()] 20 | param( 21 | ) 22 | 23 | Set-StrictMode -Version 'Latest' 24 | 25 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 26 | 27 | if( (Get-Service 'Windows Firewall' -ErrorAction Ignore | Select-Object -ExpandProperty 'Status' -ErrorAction Ignore) -eq 'Running' ) 28 | { 29 | return $true 30 | } 31 | elseif( (Get-Service -Name 'MpsSvc').Status -eq 'Running' ) 32 | { 33 | return $true 34 | } 35 | 36 | Write-Error "Unable to configure firewall: Windows Firewall service isn't running." 37 | return $false 38 | } 39 | -------------------------------------------------------------------------------- /Carbon/Functions/Assert-Service.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Assert-CService 3 | { 4 | <# 5 | .SYNOPSIS 6 | Checks if a service exists, and writes an error if it doesn't. 7 | 8 | .DESCRIPTION 9 | Also returns `True` if the service exists, `False` if it doesn't. 10 | 11 | .OUTPUTS 12 | System.Boolean. 13 | 14 | .LINK 15 | Test-CService 16 | 17 | .EXAMPLE 18 | Assert-CService -Name 'Drivetrain' 19 | 20 | Writes an error if the `Drivetrain` service doesn't exist. 21 | #> 22 | [CmdletBinding()] 23 | param( 24 | [Parameter(Mandatory=$true)] 25 | [string] 26 | # The name of the service. 27 | $Name 28 | ) 29 | 30 | Set-StrictMode -Version 'Latest' 31 | 32 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 33 | 34 | if( -not (Test-CService $Name) ) 35 | { 36 | Write-Error ('Service {0} not found.' -f $Name) 37 | return $false 38 | } 39 | 40 | return $true 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Carbon/Functions/Clear-DscLocalResourceCache.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Clear-CDscLocalResourceCache 3 | { 4 | <# 5 | .SYNOPSIS 6 | Clears the local DSC resource cache. 7 | 8 | .DESCRIPTION 9 | DSC caches resources. This is painful when developing, since you're constantly updating your resources. This function allows you to clear the DSC resource cache on the local computer. What this function really does, is kill the DSC host process running DSC. 10 | 11 | `Clear-CDscLocalResourceCache` is new in Carbon 2.0. 12 | 13 | .EXAMPLE 14 | Clear-CDscLocalResourceCache 15 | #> 16 | [CmdletBinding()] 17 | param( 18 | ) 19 | 20 | Set-StrictMode -Version 'Latest' 21 | 22 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 23 | 24 | Get-CCimInstance -Class 'msft_providers' | 25 | Where-Object {$_.provider -like 'dsccore'} | 26 | Select-Object -ExpandProperty HostProcessIdentifier | 27 | ForEach-Object { Get-Process -ID $_ } | 28 | Stop-Process -Force 29 | } 30 | -------------------------------------------------------------------------------- /Carbon/Functions/Clear-TrustedHost.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Clear-CTrustedHost 3 | { 4 | <# 5 | .SYNOPSIS 6 | Removes all entries from PowerShell trusted hosts list. 7 | 8 | .DESCRIPTION 9 | The `Add-CTrustedHost` function adds new entries to the trusted hosts list. `Set-CTrustedHost` sets it to a new list. This function clears out the trusted hosts list completely. After you run it, you won't be able to connect to any computers until you add them to the trusted hosts list. 10 | 11 | .LINK 12 | Add-CTrustedHost 13 | 14 | .LINK 15 | Set-CTrustedHost 16 | 17 | .EXAMPLE 18 | Clear-CTrustedHost 19 | 20 | Clears everything from the trusted hosts list. 21 | #> 22 | [CmdletBinding(SupportsShouldProcess=$true)] 23 | param( 24 | ) 25 | 26 | Set-StrictMode -Version 'Latest' 27 | 28 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 29 | 30 | if( $pscmdlet.ShouldProcess( 'trusted hosts', 'clear' ) ) 31 | { 32 | Set-Item $TrustedHostsPath -Value '' -Force 33 | } 34 | 35 | } 36 | 37 | Set-Alias -Name 'Clear-TrustedHosts' -Value 'Clear-CTrustedHost' 38 | -------------------------------------------------------------------------------- /Carbon/Functions/ConvertTo-CArgValue.ps1: -------------------------------------------------------------------------------- 1 | 2 | function ConvertTo-CArgValue 3 | { 4 | [CmdletBinding()] 5 | param( 6 | [Parameter(Mandatory, ValueFromPipeline)] 7 | [AllowNull()] 8 | [AllowEmptyString()] 9 | [String] $InputObject 10 | ) 11 | 12 | process 13 | { 14 | Set-StrictMode -Version 'Latest' 15 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 16 | 17 | if (-not $InputObject) 18 | { 19 | # args.exe returns what you pass it. If it returns nothing, PowerShell isn't passing an empty string as 20 | # an argument, so force it to by using double-quotes. 21 | if (-not (& $script:argsExePath $InputObject | Measure-Object).Count) 22 | { 23 | return '""' 24 | } 25 | 26 | return $InputObject 27 | } 28 | 29 | if ($InputObject -eq (& $script:argsExePath $InputObject)) 30 | { 31 | return $InputObject 32 | } 33 | 34 | return $InputObject -replace '"', '\"' 35 | } 36 | } -------------------------------------------------------------------------------- /Carbon/Functions/Disable-FirewallStatefulFtp.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Disable-CFirewallStatefulFtp 3 | { 4 | <# 5 | .SYNOPSIS 6 | Disables the `StatefulFtp` Windows firewall setting. 7 | 8 | .DESCRIPTION 9 | Uses the `netsh` command to disable the `StatefulFtp` Windows firewall setting. 10 | 11 | If the firewall isn't configurable, writes an error and returns without making any changes. 12 | 13 | .LINK 14 | Assert-CFirewallConfigurable 15 | 16 | .EXAMPLE 17 | Disable-CFirewallStatefulFtp 18 | 19 | Disables the `StatefulFtp` Windows firewall setting. 20 | #> 21 | [CmdletBinding(SupportsShouldProcess=$true)] 22 | param( 23 | ) 24 | 25 | Set-StrictMode -Version 'Latest' 26 | 27 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 28 | 29 | if( -not (Assert-CFirewallConfigurable) ) 30 | { 31 | return 32 | } 33 | 34 | Invoke-ConsoleCommand -Target 'firewall' ` 35 | -Action 'disabling stateful FTP' ` 36 | -ScriptBlock { 37 | netsh advfirewall set global StatefulFtp disable 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /Carbon/Functions/Enable-FirewallStatefulFtp.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Enable-CFirewallStatefulFtp 3 | { 4 | <# 5 | .SYNOPSIS 6 | Enables the `StatefulFtp` Windows firewall setting. 7 | 8 | .DESCRIPTION 9 | Uses the `netsh` command to enable the `StatefulFtp` Windows firewall setting. 10 | 11 | If the firewall isn't configurable, writes an error and returns without making any changes. 12 | 13 | .LINK 14 | Assert-CFirewallConfigurable 15 | 16 | .EXAMPLE 17 | Enable-CFirewallStatefulFtp 18 | 19 | Enables the `StatefulFtp` Windows firewall setting. 20 | #> 21 | [CmdletBinding(SupportsShouldProcess=$true)] 22 | param( 23 | ) 24 | 25 | Set-StrictMode -Version 'Latest' 26 | 27 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 28 | 29 | if( -not (Assert-CFirewallConfigurable) ) 30 | { 31 | return 32 | } 33 | 34 | Invoke-ConsoleCommand -Target 'firewall' -Action 'enable stateful FTP' -ScriptBlock { 35 | netsh advfirewall set global StatefulFtp enable 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Carbon/Functions/Format-ADSearchFilterValue.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Format-CADSearchFilterValue 3 | { 4 | <# 5 | .SYNOPSIS 6 | Escapes Active Directory special characters from a string. 7 | 8 | .DESCRIPTION 9 | There are special characters in Active Directory queries/searches. This function escapes them so they aren't treated as AD commands/characters. 10 | 11 | .OUTPUTS 12 | System.String. The input string with any Active Directory-sensitive characters escaped. 13 | 14 | .LINK 15 | http://msdn.microsoft.com/en-us/library/aa746475.aspx#special_characters 16 | 17 | .EXAMPLE 18 | Format-CADSearchFilterValue -String "I have AD special characters (I think)." 19 | 20 | Returns 21 | 22 | I have AD special characters \28I think\29. 23 | #> 24 | [CmdletBinding()] 25 | param( 26 | [Parameter(Mandatory=$true)] 27 | [string] 28 | # The string to escape. 29 | $String 30 | ) 31 | 32 | Set-StrictMode -Version 'Latest' 33 | 34 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 35 | 36 | $string = $string.Replace('\', '\5c') 37 | $string = $string.Replace('*', '\2a') 38 | $string = $string.Replace('(', '\28') 39 | $string = $string.Replace(')', '\29') 40 | $string = $string.Replace('/', '\2f') 41 | $string.Replace("`0", '\00') 42 | } 43 | 44 | Set-Alias -Name 'Format-ADSpecialCharacters' -Value 'Format-CADSearchFilterValue' 45 | 46 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-CCimClass.ps1: -------------------------------------------------------------------------------- 1 | function Get-CCimClass 2 | { 3 | <# 4 | .SYNOPSIS 5 | Calls Get-CimClass, with a fallback to Get-WmiObject. 6 | 7 | .DESCRIPTION 8 | The `Get-CCimClass` function calls PowerShell's `Get-CimClass` cmdlet. If CIM isn't available, calls `Get-WmiObject` instead. 9 | 10 | .EXAMPLE 11 | Get-CCimClass -Class 'Win32_OperatingSystem' 12 | 13 | Demonstrates how to use `Get-CCimClass`. In this example, the function will call `Get-CimClass -ClassName 'Win32_OperatingSystem'`, except when that cmdlet doesn't exist, when it calls `Get-WmiObject -Class 'Win32_OperatingSystem' -List`. 14 | #> 15 | 16 | [CmdletBinding()] 17 | param( 18 | [Parameter(Mandatory)] 19 | [String] $Class 20 | ) 21 | 22 | Set-StrictMode -Version 'Latest' 23 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 24 | 25 | $useCim = Test-CCimAvailable 26 | 27 | if( $useCim ) 28 | { 29 | Get-CimClass -ClassName $Class 30 | } 31 | else 32 | { 33 | Get-WmiObject -Class $Class -List 34 | } 35 | } -------------------------------------------------------------------------------- /Carbon/Functions/Get-CCimInstance.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CCimInstance 3 | { 4 | <# 5 | .SYNOPSIS 6 | Calls Get-CimInstance, with a fallback to Get-WmiObject. 7 | 8 | .DESCRIPTION 9 | The `Get-CCimInstance` function calls PowerShell's `Get-CimInstance` cmdlet. If CIM isn't available, calls 10 | `Get-WmiObject` instead. 11 | 12 | .EXAMPLE 13 | Get-CCimInstance -Class 'Win32_OperatingSystem' 14 | 15 | Demonstrates how to use `Get-CCimInstance`. In this example, the function will call `Get-CimInstance -ClassName 16 | 'Win32_OperatingSystem'`, except when that cmdlet doesn't exist, when it calls 17 | `Get-WmiObject -Class 'Win32_OperatingSystem'`. 18 | #> 19 | 20 | [CmdletBinding()] 21 | param( 22 | [Parameter(Mandatory)] 23 | [String] $Class, 24 | 25 | [String] $Filter, 26 | 27 | [String] $Query, 28 | 29 | [switch] $AsWmiObject 30 | ) 31 | 32 | Set-StrictMode -Version 'Latest' 33 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 34 | 35 | $optionalArgs = @{ } 36 | 37 | if ($Filter) 38 | { 39 | $optionalArgs['Filter'] = $Filter 40 | } 41 | 42 | if ($Query) 43 | { 44 | $optionalArgs['Query'] = $Query 45 | } 46 | 47 | if ($AsWmiObject -or -not (Test-CCimAvailable)) 48 | { 49 | return Get-WmiObject -Class $Class @optionalArgs 50 | } 51 | 52 | return Get-CimInstance -ClassName $Class @optionalArgs 53 | } -------------------------------------------------------------------------------- /Carbon/Functions/Get-FileShareSecurityDescriptor.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CFileShareSecurityDescriptor 3 | { 4 | <# 5 | .SYNOPSIS 6 | INTERNAL 7 | 8 | .DESCRIPTION 9 | INTERNAL 10 | 11 | .EXAMPLE 12 | INTERNAL 13 | #> 14 | [CmdletBinding()] 15 | param( 16 | # The share's name. 17 | [Parameter(Mandatory=$true)] 18 | [String] $Name 19 | ) 20 | 21 | Set-StrictMode -Version 'Latest' 22 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 23 | 24 | $share = Get-CFileShare -Name $Name 25 | if( -not $share ) 26 | { 27 | return 28 | } 29 | 30 | $lsss = Get-CCimInstance -Class 'Win32_LogicalShareSecuritySetting' -Filter "name='$($Name)'" 31 | if( -not $lsss ) 32 | { 33 | return 34 | } 35 | 36 | if( Test-CCimAvailable ) 37 | { 38 | $result = Invoke-CimMethod -InputObject $lsss -MethodName 'GetSecurityDescriptor' 39 | } 40 | else 41 | { 42 | $result = $lsss.GetSecurityDescriptor() 43 | } 44 | 45 | if( -not $result ) 46 | { 47 | return 48 | } 49 | 50 | if( $result.ReturnValue ) 51 | { 52 | $win32lsssErrors = @{ 53 | [uint32]2 = 'Access Denied'; 54 | [uint32]8 = 'Unknown Failure'; 55 | [uint32]9 = 'Privilege Missing'; 56 | [uint32]21 = 'Invalid Parameter'; 57 | } 58 | 59 | $msg = "Failed to get ""$($Name)"" share''s security descriptor: WMI error code $($result.ReturnValue): " + 60 | "$($win32lsssErrors[$result.ReturnValue])." 61 | Write-Error -Message $msg -ErrorAction $ErrorActionPreference 62 | return 63 | } 64 | 65 | return $result.Descriptor 66 | } 67 | 68 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-IdentityPrincipalContext.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-IdentityPrincipalContext 3 | { 4 | <# 5 | .SYNOPSIS 6 | **INTERNAL.** Do not use. 7 | .DESCRIPTION 8 | **INTERNAL.** Do not use. 9 | .EXAMPLE 10 | **INTERNAL.** Do not use. 11 | #> 12 | [CmdletBinding()] 13 | [OutputType([DirectoryServices.AccountManagement.PrincipalContext])] 14 | param( 15 | [Parameter(Mandatory=$true)] 16 | [Carbon.Identity] 17 | # The identity whose principal context to get. 18 | $Identity 19 | ) 20 | 21 | Set-StrictMode -Version 'Latest' 22 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 23 | 24 | # First, check for a local match 25 | $machineCtx = New-Object 'DirectoryServices.AccountManagement.PrincipalContext' 'Machine',$env:COMPUTERNAME 26 | if( [DirectoryServices.AccountManagement.Principal]::FindByIdentity( $machineCtx, 'Sid', $Identity.Sid.Value ) ) 27 | { 28 | return $machineCtx 29 | } 30 | 31 | $domainCtx = New-Object 'DirectoryServices.AccountManagement.PrincipalContext' 'Domain',$Identity.Domain 32 | if( [DirectoryServices.AccountManagement.PRincipal]::FindByIdentity( $domainCtx, 'Sid', $Identity.Sid.Value ) ) 33 | { 34 | return $domainCtx 35 | } 36 | 37 | Write-Error -Message ('Unable to determine if principal ''{0}'' (SID: {1}; Type: {2}) is a machien or domain principal.' -f $Identity.FullName,$Identity.Sid.Value,$Identity.Type) 38 | } 39 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-MsmqMessageQueuePath.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CMsmqMessageQueuePath 3 | { 4 | <# 5 | .SYNOPSIS 6 | Gets the path to an MSMQ message queue. 7 | 8 | .DESCRIPTION 9 | The MSMQ APIs expect paths when identifying a queue. This function converts a queue name into its path so that logic isn't spread across all your scripts. 10 | 11 | Private queue paths are constructed differently. If you need to get the path to a private MSMQ, use the `Private` switch. 12 | 13 | .OUTPUTS 14 | System.String. 15 | 16 | .EXAMPLE 17 | Get-CMsmqMessageQueuePath -Name MovieQueue 18 | 19 | Returns the path to the `MovieQueue` queue. 20 | 21 | .EXAMPLE 22 | Get-CMsmqMessageQueuePath -Name MovieQueue -Private 23 | 24 | Returns the path to the private `MovieQueue`. Must be for the critics. Early access for the win! 25 | #> 26 | [CmdletBinding(SupportsShouldProcess=$true)] 27 | param( 28 | [Parameter(Mandatory=$true)] 29 | [string] 30 | # The queue's name. 31 | $Name, 32 | 33 | [Switch] 34 | # Is the queue private? 35 | $Private 36 | ) 37 | 38 | Set-StrictMode -Version 'Latest' 39 | 40 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 41 | 42 | $path = ".\$Name" 43 | if( $Private ) 44 | { 45 | $path = ".\private`$\$Name" 46 | } 47 | return $path 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-PathToHostsFile.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CPathToHostsFile 3 | { 4 | <# 5 | .SYNOPSIS 6 | Gets the path to this computer's hosts file. 7 | 8 | .DESCRIPTION 9 | This is a convenience method so you don't have to have the path to the hosts file hard-coded in your scripts. 10 | 11 | .EXAMPLE 12 | Get-CPathToHostsFile 13 | 14 | Returns `C:\Windows\system32\drivers\etc\hosts`. Uses the environment variable to find the root to the Windows directory. 15 | #> 16 | [CmdletBinding()] 17 | param( 18 | ) 19 | 20 | Set-StrictMode -Version 'Latest' 21 | 22 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 23 | 24 | return Join-Path $env:windir system32\drivers\etc\hosts 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-PerformanceCounter.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CPerformanceCounter 3 | { 4 | <# 5 | .SYNOPSIS 6 | Gets the performance counters for a category. 7 | 8 | .DESCRIPTION 9 | Returns `PerformanceCounterCategory` objects for the given category name. If not counters exist for the category exits, an empty array is returned. 10 | 11 | .OUTPUTS 12 | System.Diagnostics.PerformanceCounterCategory. 13 | 14 | .EXAMPLE 15 | Get-CPerformanceCounter -CategoryName Processor 16 | 17 | Gets all the `Processor` performance counters. 18 | #> 19 | [CmdletBinding()] 20 | param( 21 | [Parameter(Mandatory=$true)] 22 | [string] 23 | # The category's name whose performance counters will be returned. 24 | $CategoryName 25 | ) 26 | 27 | Set-StrictMode -Version 'Latest' 28 | 29 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 30 | 31 | if( (Test-CPerformanceCounterCategory -CategoryName $CategoryName) ) 32 | { 33 | $category = New-Object Diagnostics.PerformanceCounterCategory $CategoryName 34 | return $category.GetCounters("") 35 | } 36 | } 37 | 38 | Set-Alias -Name 'Get-PerformanceCounters' -Value 'Get-CPerformanceCounter' 39 | 40 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-ServiceAcl.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CServiceAcl 3 | { 4 | <# 5 | .SYNOPSIS 6 | Gets the discretionary access control list (i.e. DACL) for a service. 7 | 8 | .DESCRIPTION 9 | You wanted it, you got it! You probably want to use `Get-CServicePermission` instead. If you want to chagne a service's permissions, use `Grant-CServicePermission` or `Revoke-ServicePermissions`. 10 | 11 | .LINK 12 | Get-CServicePermission 13 | 14 | .LINK 15 | Grant-CServicePermission 16 | 17 | .LINK 18 | Revoke-CServicePermission 19 | 20 | .EXAMPLE 21 | Get-CServiceAcl -Name Hyperdrive 22 | 23 | Gets the `Hyperdrive` service's DACL. 24 | #> 25 | [CmdletBinding()] 26 | param( 27 | [Parameter(Mandatory=$true)] 28 | [string] 29 | # The service whose DACL to return. 30 | $Name 31 | ) 32 | 33 | Set-StrictMode -Version 'Latest' 34 | 35 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 36 | 37 | $rawSD = Get-CServiceSecurityDescriptor -Name $Name 38 | $rawDacl = $rawSD.DiscretionaryAcl 39 | New-Object Security.AccessControl.DiscretionaryAcl $false,$false,$rawDacl 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-ServiceSecurityDescriptor.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CServiceSecurityDescriptor 3 | { 4 | <# 5 | .SYNOPSIS 6 | Gets the raw security descriptor for a service. 7 | 8 | .DESCRIPTION 9 | You probably don't want to mess with the raw security descriptor. Try `Get-CServicePermission` instead. Much more useful. 10 | 11 | .OUTPUTS 12 | System.Security.AccessControl.RawSecurityDescriptor. 13 | 14 | .LINK 15 | Get-CServicePermission 16 | 17 | .LINK 18 | Grant-ServicePermissions 19 | 20 | .LINK 21 | Revoke-ServicePermissions 22 | 23 | .EXAMPLE 24 | Get-CServiceSecurityDescriptor -Name 'Hyperdrive' 25 | 26 | Gets the hyperdrive service's raw security descriptor. 27 | #> 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory=$true)] 31 | [string] 32 | # The name of the service whose permissions to return. 33 | $Name 34 | ) 35 | 36 | Set-StrictMode -Version 'Latest' 37 | 38 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 39 | 40 | $sdBytes = [Carbon.Service.ServiceSecurity]::GetServiceSecurityDescriptor($Name) 41 | New-Object Security.AccessControl.RawSecurityDescriptor $sdBytes,0 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-TrustedHost.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CTrustedHost 3 | { 4 | <# 5 | .SYNOPSIS 6 | Returns the current computer's trusted hosts list. 7 | 8 | .DESCRIPTION 9 | PowerShell stores its trusted hosts list as a comma-separated list of hostnames in the `WSMan` drive. That's not very useful. This function reads that list, splits it, and returns each item. 10 | 11 | .OUTPUTS 12 | System.String. 13 | 14 | .EXAMPLE 15 | Get-CTrustedHost 16 | 17 | If the trusted hosts lists contains `example.com`, `api.example.com`, and `docs.example.com`, returns the following: 18 | 19 | example.com 20 | api.example.com 21 | docs.example.com 22 | #> 23 | [CmdletBinding()] 24 | param( 25 | ) 26 | 27 | Set-StrictMode -Version 'Latest' 28 | 29 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 30 | 31 | $trustedHosts = (Get-Item $TrustedHostsPath -Force).Value 32 | if( $trustedHosts ) 33 | { 34 | return $trustedHosts -split ',' 35 | } 36 | } 37 | 38 | Set-Alias -Name 'Get-TrustedHosts' -Value 'Get-CTrustedHost' 39 | -------------------------------------------------------------------------------- /Carbon/Functions/Get-WmiLocalUserAccount.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-CWmiLocalUserAccount 3 | { 4 | <# 5 | .SYNOPSIS 6 | Gets a WMI `Win32_UserAccount` object for a *local* user account. 7 | 8 | .DESCRIPTION 9 | Man, there are so many ways to get a user account in Windows. This function uses WMI to get a local user account. It returns a `Win32_UserAccount` object. The username has to be less than 20 characters. We don't remember why anymore, but it's probaly a restriction of WMI. Or Windows. Or both. 10 | 11 | You can do this with `Get-WmiObject`, but when you try to get a `Win32_UserAccount`, PowerShell reaches out to your domain and gets all the users it finds, even if you filter by name. This is slow! This function stops WMI from talking to your domain, so it is faster. 12 | 13 | .LINK 14 | http://msdn.microsoft.com/en-us/library/windows/desktop/aa394507(v=vs.85).aspx 15 | 16 | .EXAMPLE 17 | Get-CWmiLocalUserAccount -Username Administrator 18 | 19 | Gets the local Administrator account as a `Win32_UserAccount` WMI object. 20 | #> 21 | [CmdletBinding(SupportsShouldProcess=$true)] 22 | param( 23 | [Parameter(Mandatory=$true)] 24 | [ValidateLength(0,20)] 25 | [string] 26 | # The username of the local user to get. 27 | $Username 28 | ) 29 | 30 | Set-StrictMode -Version 'Latest' 31 | 32 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 33 | 34 | return Get-CCimInstance -Class 'Win32_UserAccount' -Filter "Domain='$($env:ComputerName)' and Name='$Username'" 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Carbon/Functions/Install-Directory.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Install-CDirectory 3 | { 4 | <# 5 | .SYNOPSIS 6 | Creates a directory, if it doesn't exist. 7 | 8 | .DESCRIPTION 9 | The `Install-CDirectory` function creates a directory. If the directory already exists, it does nothing. If any parent directories don't exist, they are created, too. 10 | 11 | `Install-CDirectory` was added in Carbon 2.1.0. 12 | 13 | .EXAMPLE 14 | Install-CDirectory -Path 'C:\Projects\Carbon' 15 | 16 | Demonstrates how to use create a directory. In this case, the directories `C:\Projects` and `C:\Projects\Carbon` will be created if they don't exist. 17 | #> 18 | [CmdletBinding()] 19 | param( 20 | [Parameter(Mandatory=$true)] 21 | [string] 22 | # The path to the directory to create. 23 | $Path 24 | ) 25 | 26 | Set-StrictMode -Version 'Latest' 27 | 28 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 29 | 30 | if( -not (Test-Path -Path $Path -PathType Container) ) 31 | { 32 | New-Item -Path $Path -ItemType 'Directory' | Out-String | Write-Verbose 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Carbon/Functions/Invoke-ConsoleCommand.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Invoke-ConsoleCommand 3 | { 4 | <# 5 | .SYNOPSIS 6 | INTERNAL. 7 | 8 | .DESCRIPTION 9 | INTERNAL. 10 | 11 | .EXAMPLE 12 | INTERNAL. 13 | #> 14 | [CmdletBinding(SupportsShouldProcess=$true)] 15 | param( 16 | [Parameter(Mandatory=$true)] 17 | [string] 18 | # The target of the action. 19 | $Target, 20 | 21 | [Parameter(Mandatory=$true)] 22 | [string] 23 | # The action/command being performed. 24 | $Action, 25 | 26 | [Parameter(Mandatory=$true)] 27 | [scriptblock] 28 | # The command to run. 29 | $ScriptBlock 30 | ) 31 | 32 | Set-StrictMode -Version 'Latest' 33 | 34 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 35 | 36 | if( -not $PSCmdlet.ShouldProcess( $Target, $Action ) ) 37 | { 38 | return 39 | } 40 | 41 | $output = Invoke-Command -ScriptBlock $ScriptBlock 42 | if( $LASTEXITCODE ) 43 | { 44 | $output = $output -join [Environment]::NewLine 45 | Write-Error ('Failed action ''{0}'' on target ''{1}'' (exit code {2}): {3}' -f $Action,$Target,$LASTEXITCODE,$output) 46 | } 47 | else 48 | { 49 | $output | Where-Object { $_ -ne $null } | Write-Verbose 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Carbon/Functions/New-Junction.ps1: -------------------------------------------------------------------------------- 1 | 2 | function New-CJunction 3 | { 4 | <# 5 | .SYNOPSIS 6 | Creates a new junction. 7 | 8 | .DESCRIPTION 9 | Creates a junction given by `-Link` which points to the path given by `-Target`. If something already exists at `Link`, an error is written. 10 | 11 | Returns a `System.IO.DirectoryInfo` object for the junction, if one is created. 12 | 13 | .OUTPUTS 14 | System.IO.DirectoryInfo. 15 | 16 | .LINK 17 | Install-CJunction 18 | 19 | .LINK 20 | Remove-CJunction 21 | 22 | .EXAMPLE 23 | New-CJunction -Link 'C:\Windows\system32Link' -Target 'C:\Windows\system32' 24 | 25 | Creates the `C:\Windows\system32Link` directory, which points to `C:\Windows\system32`. 26 | #> 27 | [CmdletBinding()] 28 | param( 29 | [Parameter(Mandatory=$true)] 30 | [Alias("Junction")] 31 | [string] 32 | # The new junction to create 33 | $Link, 34 | 35 | [Parameter(Mandatory=$true)] 36 | [string] 37 | # The target of the junction, i.e. where the junction will point to 38 | $Target 39 | ) 40 | 41 | Set-StrictMode -Version 'Latest' 42 | 43 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 44 | 45 | if( Test-Path -LiteralPath $Link -PathType Container ) 46 | { 47 | Write-Error "'$Link' already exists." 48 | } 49 | else 50 | { 51 | Write-Verbose -Message "Creating junction $Link <=> $Target" 52 | [Carbon.IO.JunctionPoint]::Create( $Link, $Target, $false ) 53 | if( Test-Path $Link -PathType Container ) 54 | { 55 | Get-Item $Link 56 | } 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /Carbon/Functions/Revoke-ServicePermission.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Revoke-CServicePermission 3 | { 4 | <# 5 | .SYNOPSIS 6 | Removes all permissions an identity has to manage a service. 7 | 8 | .DESCRIPTION 9 | No permissions are left behind. This is an all or nothing operation, baby! 10 | 11 | .LINK 12 | Get-CServicePermission 13 | 14 | .LINK 15 | Grant-CServicePermission 16 | 17 | .EXAMPLE 18 | Revoke-CServicePermission -Name 'Hyperdrive` -Identity 'CLOUDCITY\LCalrissian' 19 | 20 | Removes all of Lando's permissions to control the `Hyperdrive` service. 21 | #> 22 | [CmdletBinding()] 23 | param( 24 | [Parameter(Mandatory=$true)] 25 | [string] 26 | # The service. 27 | $Name, 28 | 29 | [Parameter(Mandatory=$true)] 30 | [string] 31 | # The identity whose permissions are being revoked. 32 | $Identity 33 | ) 34 | 35 | Set-StrictMode -Version 'Latest' 36 | 37 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 38 | 39 | $account = Resolve-CIdentity -Name $Identity -NoWarn 40 | if( -not $account ) 41 | { 42 | return 43 | } 44 | 45 | if( -not (Assert-CService -Name $Name) ) 46 | { 47 | return 48 | } 49 | 50 | if( (Get-CServicePermission -Name $Name -Identity $account.FullName) ) 51 | { 52 | Write-Verbose ("Revoking {0}'s {1} service permissions." -f $account.FullName,$Name) 53 | 54 | $dacl = Get-CServiceAcl -Name $Name 55 | $dacl.Purge( $account.Sid ) 56 | 57 | Set-CServiceAcl -Name $Name -Dacl $dacl 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /Carbon/Functions/Set-TrustedHost.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Set-CTrustedHost 3 | { 4 | <# 5 | .SYNOPSIS 6 | Sets the current computer's trusted hosts list. 7 | 8 | .DESCRIPTION 9 | Clears the current trusted hosts list, and sets it to contain only the entries given by the `Entries` parameter. 10 | 11 | To clear the trusted hosts list, use `Clear-CTrustedHost`. 12 | 13 | .LINK 14 | Clear-CTrustedHost 15 | 16 | .EXAMPLE 17 | Set-CTrustedHost -Entry example.com,api.example.com,docs.example.com 18 | 19 | Sets the trusted hosts list to contain just the values `example.com`, `api.example.com`, and `docs.example.com`. 20 | #> 21 | [CmdletBinding(SupportsShouldProcess=$true)] 22 | param( 23 | [Parameter(Mandatory=$true)] 24 | [string[]] 25 | # An array of trusted host entries. 26 | [Alias("Entries")] 27 | $Entry 28 | ) 29 | 30 | Set-StrictMode -Version 'Latest' 31 | 32 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 33 | 34 | $value = $Entry -join ',' 35 | if( $pscmdlet.ShouldProcess( 'trusted hosts', 'set' ) ) 36 | { 37 | Set-Item $TrustedHostsPath -Value $Value -Force 38 | } 39 | } 40 | 41 | Set-Alias -Name 'Set-TrustedHosts' -Value 'Set-CTrustedHost' 42 | 43 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-AdminPrivilege.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CAdminPrivilege 3 | { 4 | <# 5 | .SYNOPSIS 6 | Checks if the current user is an administrator or has administrative privileges. 7 | 8 | .DESCRIPTION 9 | Many tools, cmdlets, and APIs require administative privileges. Use this function to check. Returns `True` if the current user has administrative privileges, or `False` if he doesn't. Or she. Or it. 10 | 11 | This function handles UAC and computers where UAC is disabled. 12 | 13 | .EXAMPLE 14 | Test-CAdminPrivilege 15 | 16 | Returns `True` if the current user has administrative privileges, or `False` if the user doesn't. 17 | #> 18 | [CmdletBinding()] 19 | param( 20 | ) 21 | 22 | Set-StrictMode -Version 'Latest' 23 | 24 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 25 | 26 | $identity = [Security.Principal.WindowsIdentity]::GetCurrent() 27 | Write-Debug -Message "Checking if current user '$($identity.Name)' has administrative privileges." 28 | 29 | $hasElevatedPermissions = $false 30 | foreach ( $group in $identity.Groups ) 31 | { 32 | if ( $group.IsValidTargetType([Security.Principal.SecurityIdentifier]) ) 33 | { 34 | $groupSid = $group.Translate([Security.Principal.SecurityIdentifier]) 35 | if ( $groupSid.IsWellKnown("AccountAdministratorSid") -or $groupSid.IsWellKnown("BuiltinAdministratorsSid")) 36 | { 37 | return $true 38 | } 39 | } 40 | } 41 | 42 | return $false 43 | } 44 | 45 | Set-Alias -Name 'Test-AdminPrivileges' -Value 'Test-CAdminPrivilege' 46 | 47 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-CCimAvailable.ps1: -------------------------------------------------------------------------------- 1 | function Test-CCimAvailable 2 | { 3 | return ($null -ne (Get-Command -Name 'Get-CimInstance' -ErrorAction Ignore)) 4 | } -------------------------------------------------------------------------------- /Carbon/Functions/Test-FileShare.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CFileShare 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if a file/SMB share exists on the local computer. 7 | 8 | .DESCRIPTION 9 | The `Test-CFileShare` function uses WMI to check if a file share exists on the local computer. If the share exists, `Test-CFileShare` returns `$true`. Otherwise, it returns `$false`. 10 | 11 | `Test-CFileShare` was added in Carbon 2.0. 12 | 13 | .LINK 14 | Get-CFileShare 15 | 16 | .LINK 17 | Get-CFileSharePermission 18 | 19 | .LINK 20 | Install-CFileShare 21 | 22 | .LINK 23 | Uninstall-CFileShare 24 | 25 | .EXAMPLE 26 | Test-CFileShare -Name 'CarbonShare' 27 | 28 | Demonstrates how to test of a file share exists. 29 | #> 30 | [CmdletBinding()] 31 | param( 32 | [Parameter(Mandatory=$true)] 33 | [string] 34 | # The name of a specific share to check. 35 | $Name 36 | ) 37 | 38 | Set-StrictMode -Version 'Latest' 39 | 40 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 41 | 42 | $share = Get-CFileShare -Name ('{0}*' -f $Name) | 43 | Where-Object { $_.Name -eq $Name } 44 | 45 | return ($share -ne $null) 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-FirewallStatefulFtp.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CFirewallStatefulFtp 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if the firewall's `StatefulFtp` setting is enabled. 7 | 8 | .DESCRIPTION 9 | Returns `True` if the firewall's `StatefulFtp` setting is enabled, `False` otherwise. 10 | 11 | If the firewall isn't configurable, writes an error and returns nothing, which will probably be interpreted by your script as `False`. Can't help you there. At least you'll get an error message. 12 | 13 | .OUTPUTS 14 | System.Boolean. 15 | 16 | .LINK 17 | Assert-CFirewallConfigurable 18 | 19 | .EXAMPLE 20 | Test-CFirewallStatefulFtp 21 | 22 | Returns `True` if the firewall's `StatefulFtp` setting is enabled, `False` otherwise. 23 | #> 24 | [CmdletBinding()] 25 | param( 26 | ) 27 | 28 | Set-StrictMode -Version 'Latest' 29 | 30 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 31 | 32 | if( -not (Assert-CFirewallConfigurable) ) 33 | { 34 | return 35 | } 36 | 37 | $output = netsh advfirewall show global StatefulFtp 38 | $line = $output[3] 39 | return $line -match 'Enable' 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-Group.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CGroup 3 | { 4 | <# 5 | .SYNOPSIS 6 | Checks if a *local* group exists. 7 | 8 | .DESCRIPTION 9 | Uses .NET's AccountManagement API to check if a *local* group exists. Returns `True` if the *local* account exists, or `False` if it doesn't. 10 | 11 | .OUTPUTS 12 | System.Boolean 13 | 14 | .LINK 15 | Get-CGroup 16 | 17 | .LINK 18 | Install-CGroup 19 | 20 | .LINK 21 | Uninstall-CGroup 22 | 23 | .EXAMPLE 24 | Test-CGroup -Name RebelAlliance 25 | 26 | Checks if the `RebelAlliance` *local* group exists. Returns `True` if it does, `False` if it doesn't. 27 | #> 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory=$true)] 31 | [string] 32 | # The name of the *local* group to check. 33 | $Name 34 | ) 35 | 36 | Set-StrictMode -Version 'Latest' 37 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 38 | 39 | $group = Get-CGroup -Name $Name -ErrorAction Ignore 40 | if( $group ) 41 | { 42 | $group.Dispose() 43 | return $true 44 | } 45 | else 46 | { 47 | return $false 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-IPAddress.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CIPAddress 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests that an IP address is in use on the local computer. 7 | 8 | .DESCRIPTION 9 | Sometimes its useful to know if an IP address is being used on the local computer. This function does just that. 10 | 11 | .LINK 12 | Test-CIPAddress 13 | 14 | .EXAMPLE 15 | Test-CIPAddress -IPAddress '10.1.2.3' 16 | 17 | Returns `true` if the IP address `10.1.2.3` is being used on the local computer. 18 | 19 | .EXAMPLE 20 | Test-CIPAddress -IPAddress '::1' 21 | 22 | Demonstrates that you can use IPv6 addresses. 23 | 24 | .EXAMPLE 25 | Test-CIPAddress -IPAddress ([Net.IPAddress]::Parse('10.5.6.7')) 26 | 27 | Demonstrates that you can use real `System.Net.IPAddress` objects. 28 | #> 29 | [CmdletBinding()] 30 | param( 31 | [Parameter(Mandatory=$true)] 32 | [Net.IPAddress] 33 | # The IP address to check. 34 | $IPAddress 35 | ) 36 | 37 | Set-StrictMode -Version 'Latest' 38 | 39 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 40 | 41 | $ip = Get-CIPAddress | Where-Object { $_ -eq $IPAddress } 42 | if( $ip ) 43 | { 44 | return $true 45 | } 46 | else 47 | { 48 | return $false 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-MsmqMessageQueue.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CMsmqMessageQueue 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if an MSMQ message queue exists. 7 | 8 | .DESCRIPTION 9 | Returns `True` if a message queue with name `Name` exists. `False` otherwise. 10 | 11 | .OUTPUTS 12 | System.Boolean. 13 | 14 | .EXAMPLE 15 | Test-CMsmqMessageQueue -Name 'MovieQueue' 16 | 17 | Returns `True` if public queue `MovieQueue` exists, `False` otherwise. 18 | 19 | .EXAMPLE 20 | Test-CMsmqMessageQueue -Name 'MovieCriticsQueue' -Private 21 | 22 | Returns `True` if private queue `MovieCriticsQueue` exists, `False` otherwise. 23 | #> 24 | [CmdletBinding()] 25 | param( 26 | [Parameter(Mandatory=$true)] 27 | [string] 28 | # The queue name. 29 | $Name, 30 | 31 | [Switch] 32 | # If the queue is private, this switch must be set. 33 | $Private 34 | ) 35 | 36 | Set-StrictMode -Version 'Latest' 37 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 38 | 39 | $queueArgs = @{ Name = $Name ; Private = $Private } 40 | $path = Get-CMsmqMessageQueuePath @queueArgs 41 | return ( [Messaging.MessageQueue]::Exists( $path ) ) 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-NtfsCompression.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CNtfsCompression 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if NTFS compression is turned on. 7 | 8 | .DESCRIPTION 9 | Returns `$true` if compression is enabled, `$false` otherwise. 10 | 11 | .LINK 12 | Disable-CNtfsCompression 13 | 14 | .LINK 15 | Enable-CNtfsCompression 16 | 17 | .EXAMPLE 18 | Test-CNtfsCompression -Path C:\Projects\Carbon 19 | 20 | Returns `$true` if NTFS compression is enabled on `C:\Projects\CArbon`. If it is disabled, returns `$false`. 21 | #> 22 | [CmdletBinding()] 23 | param( 24 | [Parameter(Mandatory=$true)] 25 | [string] 26 | # The path where compression should be enabled. 27 | $Path 28 | ) 29 | 30 | Set-StrictMode -Version 'Latest' 31 | 32 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 33 | 34 | if( -not (Test-Path -Path $Path) ) 35 | { 36 | Write-Error ('Path {0} not found.' -f $Path) 37 | return 38 | } 39 | 40 | $attributes = Get-Item -Path $Path -Force | Select-Object -ExpandProperty Attributes 41 | if( $attributes ) 42 | { 43 | return (($attributes -band [IO.FileAttributes]::Compressed) -eq [IO.FileAttributes]::Compressed) 44 | } 45 | return $false 46 | } 47 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-PerformanceCounter.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CPerformanceCounter 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if a performance counter exists. 7 | 8 | .DESCRIPTION 9 | Returns `True` if counter `Name` exists in category `CategoryName`. `False` if it does not exist or the category doesn't exist. 10 | 11 | .EXAMPLE 12 | Test-CPerformanceCounter -CategoryName 'ToyotaCamry' -Name 'MilesPerGallon' 13 | 14 | Returns `True` if the `ToyotaCamry` performance counter category has a `MilesPerGallon` counter. `False` if the counter doesn't exist. 15 | #> 16 | [CmdletBinding()] 17 | param( 18 | [Parameter(Mandatory=$true)] 19 | [string] 20 | # The category's name where the performance counter exists. Or might exist. As the case may be. 21 | $CategoryName, 22 | 23 | [Parameter(Mandatory=$true)] 24 | [string] 25 | # The performance counter's name. 26 | $Name 27 | ) 28 | 29 | Set-StrictMode -Version 'Latest' 30 | 31 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 32 | 33 | if( (Test-CPerformanceCounterCategory -CategoryName $CategoryName) ) 34 | { 35 | return [Diagnostics.PerformanceCounterCategory]::CounterExists( $Name, $CategoryName ) 36 | } 37 | 38 | return $false 39 | } 40 | 41 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-PerformanceCounterCategory.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CPerformanceCounterCategory 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if a performance counter category exists. 7 | 8 | .DESCRIPTION 9 | Returns `True` if category `CategoryName` exists. `False` if it does not exist. 10 | 11 | .EXAMPLE 12 | Test-CPerformanceCounterCategory -CategoryName 'ToyotaCamry' 13 | 14 | Returns `True` if the `ToyotaCamry` performance counter category exists. `False` if the category doesn't exist. 15 | #> 16 | [CmdletBinding()] 17 | param( 18 | [Parameter(Mandatory=$true)] 19 | [string] 20 | # The name of the cateogry whose existence to check. 21 | $CategoryName 22 | ) 23 | 24 | Set-StrictMode -Version 'Latest' 25 | 26 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 27 | 28 | return [Diagnostics.PerformanceCounterCategory]::Exists( $CategoryName ) 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-Service.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CService 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if a service exists, without writing anything out to the error stream. 7 | 8 | .DESCRIPTION 9 | `Get-Service` writes an error when a service doesn't exist. This function tests if a service exists without writing anyting to the output stream. 10 | 11 | .OUTPUTS 12 | System.Boolean. 13 | 14 | .LINK 15 | Carbon_Service 16 | 17 | .LINK 18 | Install-CService 19 | 20 | .LINK 21 | Uninstall-CService 22 | 23 | .EXAMPLE 24 | Test-CService -Name 'Drive' 25 | 26 | Returns `true` if the `Drive` service exists. `False` otherwise. 27 | #> 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory=$true)] 31 | [string] 32 | # The name of the service to test. 33 | $Name 34 | ) 35 | 36 | Set-StrictMode -Version 'Latest' 37 | 38 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 39 | 40 | $service = Get-Service -Name $Name -ErrorAction Ignore 41 | if( $service ) 42 | { 43 | return $true 44 | } 45 | else 46 | { 47 | return $false 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-TypeDataMember.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CTypeDataMember 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if a type has an extended type member defined. 7 | 8 | .DESCRIPTION 9 | `Test-CTypeDataMember` tests if a type has an extended type member defined. If the type isn't found, you'll get an error. 10 | 11 | Returns `$true` if the type is found and the member is defined. Otherwise, returns `$false`. 12 | 13 | This function is new in Carbon 2.0. 14 | 15 | .EXAMPLE 16 | Test-CTypeDataMember -TypeName 'Microsoft.Web.Administration.Site' -MemberName 'PhysicalPath' 17 | 18 | Tests if the `Microsoft.Web.Administration.Site` type has a `PhysicalPath` extended type member defined. 19 | #> 20 | [CmdletBinding()] 21 | [OutputType([bool])] 22 | param( 23 | [Parameter(Mandatory=$true)] 24 | [string] 25 | # The type name to check. 26 | $TypeName, 27 | 28 | [Parameter(Mandatory=$true)] 29 | [string] 30 | # The name of the member to check. 31 | $MemberName 32 | ) 33 | 34 | Set-StrictMode -Version 'Latest' 35 | 36 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 37 | 38 | $typeData = Get-TypeData -TypeName $TypeName 39 | if( -not $typeData ) 40 | { 41 | # The type isn't defined or there is no extended type data on it. 42 | return $false 43 | } 44 | 45 | return $typeData.Members.ContainsKey( $MemberName ) 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-UncPath.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CUncPath 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if a path is a UNC path. 7 | 8 | .DESCRIPTION 9 | Converts the path to a URI and returns the value of its `IsUnc` property. 10 | 11 | This function does not test if path exists. Use `Test-Path` for that. 12 | 13 | .LINK 14 | Test-Path 15 | 16 | .LINK 17 | http://blogs.microsoft.co.il/blogs/ScriptFanatic//archive/2010/05/27/quicktip-how-to-validate-a-unc-path.aspx 18 | 19 | .EXAMPLE 20 | Test-CUncPath -Path '\\computer\share' 21 | 22 | Returns `true` since `\\computer\share` is a UNC path. Note that `Test-CUncPath` does not have to exist. 23 | 24 | .EXAMPLE 25 | Test-CUncPath -Path 'C:\Windows' 26 | 27 | Returns `false` since `C:\Windows` is not a UNC path. 28 | #> 29 | [CmdletBinding()] 30 | param( 31 | [Parameter(Mandatory=$true)] 32 | [string] 33 | # The path to test/check. 34 | $Path 35 | ) 36 | 37 | Set-StrictMode -Version 'Latest' 38 | 39 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 40 | 41 | ([Uri]$Path).IsUnc 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-User.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CUser 3 | { 4 | <# 5 | .SYNOPSIS 6 | Checks if a *local* user account exists. 7 | 8 | .DESCRIPTION 9 | Uses .NET's AccountManagement API to check if a *local* user account exists. Returns `True` if the *local* account exists, or `False` if it doesn't. 10 | 11 | .OUTPUTS 12 | System.Boolean 13 | 14 | .LINK 15 | Get-CUser 16 | 17 | .LINK 18 | Install-CUser 19 | 20 | .LINK 21 | Uninstall-CUser 22 | 23 | .EXAMPLE 24 | Test-CUser -Username HSolo 25 | 26 | Checks if the HSolo *local* account exists. Returns `True` if it does, `False` if it doesn't or its encased in carbonite. 27 | #> 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory=$true)] 31 | [ValidateLength(1,20)] 32 | [string] 33 | # The username of the *local* account to check 34 | $Username 35 | ) 36 | 37 | Set-StrictMode -Version 'Latest' 38 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 39 | 40 | $user = Get-CUser -UserName $Username -ErrorAction Ignore 41 | if( $user ) 42 | { 43 | $user.Dispose() 44 | return $true 45 | } 46 | else 47 | { 48 | return $false 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Carbon/Functions/Test-ZipFile.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Test-CZipFile 3 | { 4 | <# 5 | .SYNOPSIS 6 | Tests if a file is a ZIP file using the `DotNetZip` library. 7 | 8 | .DESCRIPTION 9 | Uses the `Ionic.Zip.ZipFile.IsZipFile` static method to determine if a file is a ZIP file. The file *must* exist. If it doesn't, an error is written and `$null` is returned. 10 | 11 | You can pipe `System.IO.FileInfo` (or strings) to this function to filter multiple items. 12 | 13 | .LINK 14 | https://www.nuget.org/packages/DotNetZip 15 | 16 | .LINK 17 | Compress-CItem 18 | 19 | .LINK 20 | Expand-CItem 21 | 22 | .EXAMPLE 23 | Test-CZipFile -Path 'MyCoolZip.zip' 24 | 25 | Demonstrates how to check the current directory if MyCoolZip.zip is really a ZIP file. 26 | #> 27 | [OutputType([bool])] 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory=$true)] 31 | [Alias('FullName')] 32 | [string] 33 | # The path to the file to test. 34 | $Path 35 | ) 36 | 37 | Set-StrictMode -Version 'Latest' 38 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 39 | 40 | Add-Type -Path (Join-Path -Path $CarbonBinDir -ChildPath 'Ionic.Zip.dll' -Resolve) 41 | 42 | $Path = Resolve-CFullPath -Path $Path -NoWarn 43 | if( -not (Test-Path -Path $Path -PathType Leaf) ) 44 | { 45 | Write-Error ('File ''{0}'' not found.' -f $Path) 46 | return 47 | } 48 | 49 | return [Ionic.Zip.ZipFile]::IsZipFile( $Path ) 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Carbon/Functions/Uninstall-Directory.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Uninstall-CDirectory 3 | { 4 | <# 5 | .SYNOPSIS 6 | Removes a directory, if it exists. 7 | 8 | .DESCRIPTION 9 | The `Uninstall-CDirectory` function removes a directory. If the directory doesn't exist, it does nothing. If the directory has any files or sub-directories, you will be prompted to confirm the deletion of the directory and all its contents. To avoid the prompt, use the `-Recurse` switch. 10 | 11 | `Uninstall-CDirectory` was added in Carbon 2.1.0. 12 | 13 | .EXAMPLE 14 | Uninstall-CDirectory -Path 'C:\Projects\Carbon' 15 | 16 | Demonstrates how to remove/delete a directory. In this case, the directory `C:\Projects\Carbon` will be deleted, if it exists. 17 | 18 | .EXAMPLE 19 | Uninstall-CDirectory -Path 'C:\Projects\Carbon' -Recurse 20 | 21 | Demonstrates how to remove/delete a directory that has items in it. In this case, the directory `C:\Projects\Carbon` *and all of its files and sub-directories* will be deleted, if the directory exists. 22 | #> 23 | [CmdletBinding()] 24 | param( 25 | [Parameter(Mandatory=$true)] 26 | [string] 27 | # The path to the directory to create. 28 | $Path, 29 | 30 | [Switch] 31 | # Delete the directory *and* everything under it. 32 | $Recurse 33 | ) 34 | 35 | Set-StrictMode -Version 'Latest' 36 | 37 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 38 | 39 | if( (Test-Path -Path $Path -PathType Container) ) 40 | { 41 | Remove-Item -Path $Path -Recurse:$Recurse 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Carbon/Functions/Uninstall-Group.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Uninstall-CGroup 3 | { 4 | <# 5 | .SYNOPSIS 6 | Removes a *local* group. 7 | 8 | .DESCRIPTION 9 | The `Uninstall-CGroup` function removes a *local* group using .NET's [DirectoryServices.AccountManagement API](https://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx). If the group doesn't exist, returns without doing any work or writing any errors. 10 | 11 | This function was added in Carbon 2.1.0. 12 | 13 | .LINK 14 | Add-CGroupMember 15 | 16 | .LINK 17 | Install-CGroup 18 | 19 | .LINK 20 | Remove-CGroupMember 21 | 22 | .LINK 23 | Test-CGroup 24 | 25 | .LINK 26 | Test-CGroupMember 27 | 28 | .INPUTS 29 | System.String 30 | 31 | .EXAMPLE 32 | Uninstall-WhsGroup -Name 'TestGroup1' 33 | 34 | Demonstrates how to uninstall a group. In this case, the `TestGroup1` group is removed. 35 | #> 36 | [CmdletBinding(SupportsShouldProcess=$true)] 37 | param( 38 | [Parameter(Mandatory=$true)] 39 | [ValidateNotNullOrEmpty()] 40 | [String] 41 | # The name of the group to remove/uninstall. 42 | $Name 43 | ) 44 | 45 | Set-StrictMode -Version 'Latest' 46 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 47 | 48 | if( -not (Test-CGroup -Name $Name) ) 49 | { 50 | return 51 | } 52 | 53 | $group = Get-CGroup -Name $Name 54 | if( -not $group ) 55 | { 56 | return 57 | } 58 | 59 | if( $PSCmdlet.ShouldProcess(('local group {0}' -f $Name), 'remove') ) 60 | { 61 | Write-Verbose -Message ('[{0}] -' -f $Name) 62 | $group.Delete() 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Carbon/Functions/Uninstall-PerformanceCounterCategory.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Uninstall-CPerformanceCounterCategory 3 | { 4 | <# 5 | .SYNOPSIS 6 | Removes an entire performance counter category. 7 | 8 | .DESCRIPTION 9 | Removes, with extreme prejudice, the performance counter category `CategoryName`. All its performance counters are also deleted. If the performance counter category doesn't exist, nothing happens. I hope you have good backups! 10 | 11 | .EXAMPLE 12 | Uninstall-CPerformanceCounterCategory -CategoryName 'ToyotaCamry' 13 | 14 | Removes the `ToyotaCamry` performance counter category and all its performance counters. So sad! 15 | #> 16 | [CmdletBinding(SupportsShouldProcess=$true)] 17 | param( 18 | [Parameter(Mandatory=$true)] 19 | [string] 20 | # The performance counter's category name that should be deleted. 21 | $CategoryName 22 | ) 23 | 24 | Set-StrictMode -Version 'Latest' 25 | 26 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 27 | 28 | if( (Test-CPerformanceCounterCategory -CategoryName $CategoryName) ) 29 | { 30 | if( $pscmdlet.ShouldProcess( $CategoryName, 'uninstall performance counter category' ) ) 31 | { 32 | [Diagnostics.PerformanceCounterCategory]::Delete( $CategoryName ) 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Carbon/Functions/Uninstall-User.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Uninstall-CUser 3 | { 4 | <# 5 | .SYNOPSIS 6 | Removes a user from the local computer. 7 | 8 | .DESCRIPTION 9 | Removes a *local* user account. If the account doesn't exist, nothing happens. 10 | 11 | .LINK 12 | Get-CUser 13 | 14 | .LINK 15 | Install-CUser 16 | 17 | .LINK 18 | Test-CUser 19 | 20 | .LINK 21 | Uninstall-CUser 22 | 23 | .EXAMPLE 24 | Uninstall-CUser -Username WTarkin 25 | 26 | Removes the `WTarkin` *local* user account. 27 | #> 28 | [CmdletBinding(SupportsShouldProcess=$true)] 29 | param( 30 | [Parameter(Mandatory=$true)] 31 | [ValidateLength(1,20)] 32 | [string] 33 | # The username of the account to remove. 34 | $Username 35 | ) 36 | 37 | Set-StrictMode -Version 'Latest' 38 | 39 | Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState 40 | 41 | if( Test-CUser -Username $username ) 42 | { 43 | $user = Get-CUser -Username $Username 44 | try 45 | { 46 | if( $pscmdlet.ShouldProcess( $Username, "remove local user" ) ) 47 | { 48 | $user.Delete() 49 | } 50 | } 51 | finally 52 | { 53 | $user.Dispose() 54 | } 55 | } 56 | } 57 | 58 | Set-Alias -Name 'Remove-User' -Value 'Uninstall-CUser' 59 | 60 | -------------------------------------------------------------------------------- /Carbon/bin/Ionic.Zip.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Carbon/bin/Ionic.Zip.dll -------------------------------------------------------------------------------- /Carbon/bin/Protect-String.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | **INTERNAL. DO NOT USE** 4 | #> 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | param( 17 | [Parameter(Mandatory=$true)] 18 | [string] 19 | $ProtectedString 20 | ) 21 | 22 | Set-StrictMode -Version 'Latest' 23 | 24 | # Keep cause this script is used by PowerShell 2. 25 | $PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition 26 | 27 | Add-Type -AssemblyName 'System.Security' 28 | 29 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\Carbon.psd1' -Resolve) 30 | 31 | $string = Unprotect-CString -ProtectedString $ProtectedString -NoWarn 32 | Protect-CString -String $string -ForUser -NoWarn 33 | 34 | -------------------------------------------------------------------------------- /Carbon/bin/Remove-DotNetAppSetting.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | [CmdletBinding()] 13 | param( 14 | [Parameter(Mandatory=$true,Position=0)] 15 | [string] 16 | $Name 17 | ) 18 | 19 | Set-StrictMode -Version 'Latest' 20 | 21 | $Name = [Text.Encoding]::Unicode.GetString( [Convert]::FromBase64String($Name) ) 22 | 23 | Add-Type -AssemblyName System.Configuration 24 | 25 | $config = [Configuration.ConfigurationManager]::OpenMachineConfiguration() 26 | $appSettings = $config.AppSettings.Settings 27 | if( $appSettings[$Name] ) 28 | { 29 | $appSettings.Remove( $Name ) 30 | $config.Save() 31 | } 32 | -------------------------------------------------------------------------------- /Carbon/bin/Remove-EnvironmentVariable.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | [CmdletBinding()] 14 | param( 15 | [Parameter(Mandatory=$true)] 16 | [string] 17 | $Name 18 | ) 19 | 20 | Set-StrictMode -Version 'Latest' 21 | 22 | $Name = [Text.Encoding]::Unicode.GetString( [Convert]::FromBase64String($Name) ) 23 | [Environment]::SetEnvironmentVariable( $Name, $null, [EnvironmentVariableTarget]::User ) 24 | -------------------------------------------------------------------------------- /Carbon/bin/Set-DotNetAppSetting.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | *Internal*. Use `Set-CDotNetAppSetting` function instead. 4 | .LINK 5 | Set-CDotNetAppSetting 6 | #> 7 | 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | [CmdletBinding()] 20 | param( 21 | [Parameter(Mandatory=$true,Position=0)] 22 | [string] 23 | $Name, 24 | 25 | [Parameter(Mandatory=$true,Position=1)] 26 | [string] 27 | $Value 28 | ) 29 | 30 | Set-StrictMode -Version 'Latest' 31 | 32 | $Name = [Text.Encoding]::Unicode.GetString( [Convert]::FromBase64String($Name) ) 33 | $Value = [Text.Encoding]::Unicode.GetString( [Convert]::FromBase64String($Value) ) 34 | 35 | Add-Type -AssemblyName System.Configuration 36 | 37 | $config = [Configuration.ConfigurationManager]::OpenMachineConfiguration() 38 | $appSettings = $config.AppSettings.Settings 39 | if( $appSettings[$Name] ) 40 | { 41 | $appSettings[$Name].Value = $Value 42 | } 43 | else 44 | { 45 | $appSettings.Add( $Name, $Value ) 46 | } 47 | $config.Save() 48 | 49 | -------------------------------------------------------------------------------- /Carbon/bin/Set-EnvironmentVariable.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | [CmdletBinding()] 14 | param( 15 | [Parameter(Mandatory=$true)] 16 | [string] 17 | $Name, 18 | 19 | [Parameter(Mandatory=$true)] 20 | [string] 21 | $Value 22 | ) 23 | 24 | Set-StrictMode -Version 'Latest' 25 | 26 | $Name,$Value = 27 | $Name,$Value | 28 | ForEach-Object { [Text.Encoding]::Unicode.GetString( [Convert]::FromBase64String($_) ) } 29 | 30 | [Environment]::SetEnvironmentVariable( $Name, $Value, [EnvironmentVariableTarget]::User ) 31 | -------------------------------------------------------------------------------- /Carbon/en-US/about_Carbon_Support.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_Carbon_Support 3 | 4 | SHORT DESCRIPTION 5 | This topic describes how you can get help using Carbon. 6 | 7 | OVERVIEW 8 | Remember, Carbon is open-source software, and comes "as is", ***without 9 | warranties or conditions of any kind, either express or implied***. The Carbon 10 | users and developers are volunteering to help you. Please respect their time and 11 | assistance. 12 | 13 | CHAT 14 | Carbon has a dedicated support channel on the [PowerShell Slack 15 | team](https://powershell.slack.com). The project owner/maintainer usually hangs out 16 | there Monday through Friday, during Pacific-time-zone business hours. To join the 17 | team, use [this form at slack.poshcode.org](http://slack.poshcode.org/) to get an 18 | invitation. 19 | 20 | E-MAIL 21 | Carbon has a public mailing list: 22 | [carbonps@googlegroups.com](mailto:carbonps@googlegroups.com). Anyone can ask 23 | questions. You do need to subscribe to be part of the community and answer questions. 24 | [Subscribe to the list.](https://groups.google.com/forum/#!forum/carbonps). 25 | 26 | REPORTING BUGS AND REQUESTING NEW FEATURES AND ENHANCEMENTS 27 | If you've found a bug or want to request an enhancement, create an issue on the 28 | project's [Bitbucket 29 | site](https://github.com/pshdo/Carbon/issues/new). 30 | 31 | SEE ALSO 32 | https://powershell.slack.com/ 33 | carbonps@googlegroups.com 34 | https://groups.google.com/forum/#!forum/carbonps 35 | https://github.com/pshdo/Carbon/issues/new 36 | -------------------------------------------------------------------------------- /Complete-CarbonTest.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Runs code to put your system back to its original state after running tests. 4 | 5 | .DESCRIPTION 6 | In order for DSC tests to run, Carbon must be in a known PSModulePath. On developer computers, the `Start-CarbonTest.ps1` script creates a junction in the module installation directory. This script removes that junction. 7 | 8 | #> 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | [CmdletBinding()] 21 | param( 22 | ) 23 | 24 | #Requires -Version 4 25 | Set-StrictMode -Version 'Latest' 26 | 27 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Carbon\Import-Carbon.ps1' -Resolve) 28 | 29 | $installRoot = Get-CPowerShellModuleInstallPath 30 | $carbonModuleRoot = Join-Path -Path $installRoot -ChildPath 'Carbon' 31 | Uninstall-CJunction -Path $carbonModuleRoot 32 | -------------------------------------------------------------------------------- /Get-PrivilegeList.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | #> 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | [CmdletBinding()] 15 | param( 16 | ) 17 | 18 | @( 'http://msdn.microsoft.com/en-us/library/windows/desktop/bb530716.aspx', 'http://msdn.microsoft.com/en-us/library/windows/desktop/bb545671.aspx' ) | 19 | ForEach-Object { Invoke-WebRequest -Uri $_ } | 20 | Select-Object -ExpandProperty 'RawContent' | 21 | Select-String -AllMatches 'TEXT\("([^"]+)"\)' | 22 | Select-Object -ExpandProperty 'Matches' | 23 | Select-Object -ExpandProperty 'Groups' | 24 | Select-Object -ExpandProperty 'Value' | 25 | Where-Object { $_ -notlike 'TEXT*' } | 26 | Select-Object -Unique | 27 | Sort-Object | 28 | ForEach-Object { ' * {0}' -f $_ } 29 | -------------------------------------------------------------------------------- /Icon.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Icon.pdn -------------------------------------------------------------------------------- /Initialize-Server.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Initializes a server and gets it ready to run Carbon tests. 4 | #> 5 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | [CmdletBinding()] 19 | param( 20 | ) 21 | 22 | Set-StrictMode -Version 'Latest' 23 | $PSCommandPath = $MyInvocation.MyCommand.Definition 24 | $PSScriptRoot = Split-Path -Parent -Path $PSCommandPath 25 | 26 | Install-WindowsFeature -Name 'Web-Server','MSMQ-Server','Web-Scripting-Tools' 27 | 28 | choco install 'sysinternals' -y 29 | choco install 'conemu' -y 30 | 31 | & (Join-Path -Path $PSScriptRoot -ChildPath '.\Carbon\Import-Carbon.ps1') 32 | 33 | Uninstall-IisWebsite -Name 'Default Web Site' 34 | 35 | # For tests that do stuff over remoting. 36 | Add-TrustedHost -Entry $env:COMPUTERNAME 37 | -------------------------------------------------------------------------------- /Install-Website.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Installs the get-carbon.org website on the local computer. 4 | #> 5 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | #Requires -Version 4 19 | Set-StrictMode -Version Latest 20 | 21 | & (Join-Path $PSScriptRoot Carbon\Import-Carbon.ps1 -Resolve) 22 | 23 | $websitePath = Join-Path $PSScriptRoot Website -Resolve 24 | Install-IisWebsite -Name 'get-carbon.org' -Path $websitePath -Bindings 'http/*:80:' 25 | Grant-Permission -Identity Everyone -Permission ReadAndExecute -Path $websitePath 26 | -------------------------------------------------------------------------------- /Lib/Microsoft.Web.XmlTransform.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Lib/Microsoft.Web.XmlTransform.dll -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Carbon 2 | 3 | Copyright Aaron Jensen and WebMD Health Services. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Carbon is a PowerShell module for automating the configuration and setup of Windows workstations and servers. More 2 | information is available at http://get-carbon.org. 3 | 4 | Contributions are welcomed and encouraged! -------------------------------------------------------------------------------- /Save-CarbonSigningKey.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Saves the Carbon signing key. 4 | 5 | .DESCRIPTION 6 | Carbon's signing key is required to build Carbon assemblies. On the build server, the key is stored in a secure environment variable. This script grabs the environment variable and saves it as the signing key. 7 | #> 8 | 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | 21 | [CmdletBinding()] 22 | param( 23 | 24 | ) 25 | 26 | #Requires -Version 4 27 | Set-StrictMode -Version 'Latest' 28 | $ErrorActionPreference = 'Stop' 29 | 30 | $base64Snk = $env:SNK 31 | if( -not $base64Snk ) 32 | { 33 | return 34 | } 35 | 36 | $snkPath = Join-Path -Path $PSScriptRoot -ChildPath 'Source\Carbon.snk' 37 | Write-Verbose -Message ('Saving signing key to "{0}".' -f $snkPath) 38 | [IO.File]::WriteAllBytes($snkPath, [Convert]::FromBase64String($base64Snk)) 39 | -------------------------------------------------------------------------------- /Source/Firewall/RuleAction.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Firewall 14 | { 15 | public enum RuleAction 16 | { 17 | Allow, 18 | Block, 19 | Bypass 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/Firewall/RuleDirection.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Firewall 14 | { 15 | public enum RuleDirection 16 | { 17 | In, 18 | Out 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/Firewall/RuleEdgeTraversalPolicy.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Firewall 14 | { 15 | public enum RuleEdgeTraversalPolicy 16 | { 17 | No = 0, 18 | Yes, 19 | DeferApp, 20 | DeferUser, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/Firewall/RuleInterfaceType.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | 15 | namespace Carbon.Firewall 16 | { 17 | [Flags] 18 | public enum RuleInterfaceType 19 | { 20 | Any = 0, 21 | Wireless = 0x1, 22 | Lan = 0x2, 23 | Ras = 0x4 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Source/Firewall/RuleProfile.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | 15 | namespace Carbon.Firewall 16 | { 17 | [Flags] 18 | public enum RuleProfile : uint 19 | { 20 | Any = 0, 21 | Domain = 0x1, 22 | Private = 0x2, 23 | Public = 0x4 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Firewall/RuleSecurity.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Firewall 14 | { 15 | public enum RuleSecurity 16 | { 17 | NotRequired = 0, 18 | Authenticate, 19 | AuthEnc, 20 | AuthDynEnc, 21 | AuthNoEncap 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Source/IO/File.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | using System.Runtime.InteropServices; 15 | 16 | namespace Carbon.IO 17 | { 18 | public sealed class File 19 | { 20 | [DllImport("Kernel32.dll", CharSet = CharSet.Unicode)] 21 | private static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes); 22 | 23 | public static void CreateHardLink(string path, string existingPath) 24 | { 25 | CreateHardLink(path, existingPath, IntPtr.Zero); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Source/IO/Path.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System.IO; 14 | using System.Runtime.InteropServices; 15 | using System.Text; 16 | 17 | namespace Carbon.IO 18 | { 19 | public class Path 20 | { 21 | [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] 22 | public static extern uint GetLongPathName( 23 | string shortPath, 24 | StringBuilder sb, 25 | int buffer); 26 | 27 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] 28 | public static extern uint GetShortPathName( 29 | string lpszLongPath, 30 | StringBuilder lpszShortPath, 31 | uint cchBuffer); 32 | 33 | [DllImport("shlwapi.dll", CharSet = CharSet.Auto)] 34 | public static extern bool PathRelativePathTo( 35 | [Out] StringBuilder pszPath, 36 | [In] string pszFrom, 37 | [In] FileAttributes dwAttrFrom, 38 | [In] string pszTo, 39 | [In] FileAttributes dwAttrTo 40 | ); 41 | 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Source/IdentityType.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon 14 | { 15 | // http://msdn.microsoft.com/en-us/library/windows/desktop/aa379601.aspx 16 | public enum IdentityType 17 | { 18 | User = 1, 19 | Group, 20 | Domain, 21 | Alias, 22 | WellKnownGroup, 23 | DeletedAccount, 24 | Invalid, 25 | Unknown, 26 | Computer, 27 | Label 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/Iis/Carbon.Iis.csproj: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | net452;netstandard2.0 18 | false 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | False 28 | C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll 29 | False 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source/Iis/HttpHeader.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | 15 | namespace Carbon.Iis 16 | { 17 | public sealed class HttpHeader 18 | { 19 | public HttpHeader(string name, string value) 20 | { 21 | Name = name; 22 | Value = value; 23 | } 24 | 25 | public string Name { get; private set; } 26 | 27 | public string Value { get; private set; } 28 | 29 | public override bool Equals(object obj) 30 | { 31 | var otherHeader = obj as HttpHeader; 32 | 33 | if (otherHeader == null) 34 | { 35 | return false; 36 | } 37 | 38 | return Name.Equals(otherHeader.Name, StringComparison.InvariantCultureIgnoreCase) && 39 | Value.Equals(otherHeader.Value, StringComparison.InvariantCultureIgnoreCase); 40 | } 41 | 42 | public override int GetHashCode() 43 | { 44 | return ToString().ToLowerInvariant().GetHashCode(); 45 | } 46 | 47 | public override string ToString() 48 | { 49 | return string.Format("{0}: {1}", Name, Value); 50 | } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Source/Iis/HttpResponseStatus.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Iis 14 | { 15 | public enum HttpResponseStatus : ushort 16 | { 17 | Found = 302, 18 | Permanent = 301, 19 | Temporary = 307 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Source/Iis/MimeMap.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | 15 | namespace Carbon.Iis 16 | { 17 | public sealed class MimeMap 18 | { 19 | public MimeMap(string fileExtension, string mimeType) 20 | { 21 | FileExtension = fileExtension; 22 | MimeType = mimeType; 23 | } 24 | 25 | public string FileExtension { get; private set; } 26 | 27 | public string MimeType { get; private set; } 28 | 29 | public override bool Equals(object obj) 30 | { 31 | var otherMimeMap = obj as MimeMap; 32 | 33 | if (otherMimeMap == null) 34 | { 35 | return false; 36 | } 37 | 38 | return FileExtension.Equals(otherMimeMap.FileExtension, StringComparison.InvariantCultureIgnoreCase) && 39 | MimeType.Equals(otherMimeMap.MimeType, StringComparison.InvariantCultureIgnoreCase); 40 | } 41 | 42 | public override int GetHashCode() 43 | { 44 | return ToString().ToLowerInvariant().GetHashCode(); 45 | } 46 | 47 | public override string ToString() 48 | { 49 | return string.Format("{0} -> {1}", FileExtension, MimeType); 50 | } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Source/Iis/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System.Reflection; 14 | using System.Runtime.InteropServices; 15 | 16 | 17 | // General Information about an assembly is controlled through the following 18 | // set of attributes. Change these attribute values to modify the information 19 | // associated with an assembly. 20 | [assembly: AssemblyTitle("Carbon IIS")] 21 | [assembly: AssemblyDescription("IIS assembly for Carbon, a PowerShell DevOps setup/configuration automation module.")] 22 | [assembly: AssemblyConfiguration("")] 23 | [assembly: AssemblyCompany("")] 24 | [assembly: AssemblyProduct("Carbon IIS")] 25 | [assembly: AssemblyTrademark("")] 26 | [assembly: AssemblyCulture("")] 27 | [assembly: AssemblyCopyright("Aaron Jensen and WebMD Health Services")] 28 | 29 | // Setting ComVisible to false makes the types in this assembly not visible 30 | // to COM components. If you need to access a type in this assembly from 31 | // COM, set the ComVisible attribute to true on that type. 32 | [assembly: ComVisible(false)] 33 | 34 | // The following GUID is for the ID of the typelib if this project is exposed to COM 35 | [assembly: Guid("93195104-8447-4c5f-91cb-8255a9a76b01")] 36 | -------------------------------------------------------------------------------- /Source/Ini/IniNode.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | 15 | namespace Carbon.Ini 16 | { 17 | public sealed class IniNode 18 | { 19 | public IniNode(string section, string name, string value, int lineNumber) 20 | { 21 | Section = section; 22 | Name = name; 23 | Value = value; 24 | LineNumber = lineNumber; 25 | } 26 | 27 | public string FullName 28 | { 29 | get 30 | { 31 | if( String.IsNullOrEmpty(Section)) 32 | { 33 | return Name; 34 | } 35 | return string.Format("{0}.{1}", Section, Name); 36 | } 37 | } 38 | 39 | public int LineNumber { get; set; } 40 | public string Name { get; set; } 41 | public string Section { get; set; } 42 | public string Value { get; set; } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Source/Security/ComAccessRights.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | 15 | namespace Carbon.Security 16 | { 17 | [Flags] 18 | public enum ComAccessRights : uint 19 | { 20 | Execute = 1, 21 | ExecuteLocal = 2, 22 | ExecuteRemote = 4, 23 | ActivateLocal = 8, 24 | ActivateRemote = 16 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Source/Security/HttpUrlAccessRights.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Security 14 | { 15 | public enum HttpUrlAccessRights 16 | { 17 | // https://msdn.microsoft.com/en-us/library/aa364653.aspx 18 | Read = -2147483648, // Because 0x80000000 isn't allowed!? 19 | Listen = 0x20000000, // GENERIC_EXECUTE 20 | Delegate = 0x40000000, // GENERIC_WRITE 21 | ListenAndDelegate = 0x10000000 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/Security/HttpUrlAccessRule.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System.Security.AccessControl; 14 | using System.Security.Principal; 15 | 16 | namespace Carbon.Security 17 | { 18 | public sealed class HttpUrlAccessRule : AccessRule 19 | { 20 | public HttpUrlAccessRule(IdentityReference identity, HttpUrlAccessRights accessMask) 21 | : base(identity, (int)accessMask, false, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow) 22 | { 23 | } 24 | 25 | public HttpUrlAccessRights HttpUrlAccessRights { get { return (HttpUrlAccessRights) AccessMask; } } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Source/Security/ServiceAccessRights.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | 15 | namespace Carbon.Security 16 | { 17 | [Flags] 18 | public enum ServiceAccessRights : uint 19 | { 20 | QueryConfig = 0x1, 21 | ChangeConfig = 0x2, 22 | QueryStatus = 0x4, 23 | EnumerateDependents = 0x8, 24 | Start = 0x10, 25 | Stop = 0x20, 26 | PauseContinue = 0x40, 27 | Interrogate = 0x80, 28 | UserDefinedControl = 0x100, 29 | Delete = 0x10000, 30 | ReadControl = 0x20000, 31 | WriteDac = 0x40000, 32 | WriteOwner = 0x80000, 33 | 34 | FullControl = 35 | QueryConfig | ChangeConfig | QueryStatus | EnumerateDependents | Start | Stop | PauseContinue | Interrogate | 36 | UserDefinedControl | Delete | ReadControl | WriteDac | WriteOwner 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Source/Service/ErrorControl.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Service 14 | { 15 | public enum ErrorControl 16 | { 17 | Ignore = 0, 18 | Normal, 19 | Severe, 20 | Critical 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Source/Service/FailureAction.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Service 14 | { 15 | public enum FailureAction 16 | { 17 | TakeNoAction = 0, 18 | Restart, 19 | Reboot, 20 | RunCommand 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Source/Service/StartType.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Service 14 | { 15 | public enum StartType 16 | { 17 | Boot = 0, 18 | System, 19 | Auto, 20 | Demand, 21 | Disabled 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Source/TaskScheduler/Months.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.TaskScheduler 14 | { 15 | public enum Month 16 | { 17 | January = 1, 18 | February, 19 | March, 20 | April, 21 | May, 22 | June, 23 | July, 24 | August, 25 | September, 26 | October, 27 | November, 28 | December, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Source/TaskScheduler/ScheduleType.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.TaskScheduler 14 | { 15 | public enum ScheduleType 16 | { 17 | Unknown, 18 | Minute, 19 | Hourly, 20 | Daily, 21 | Weekly, 22 | Monthly, 23 | Once, 24 | OnLogon, 25 | OnStart, 26 | OnIdle, 27 | OnEvent, 28 | Registration, 29 | SessionStateChange, 30 | OnDemand 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Source/TaskScheduler/WeekOfMonth.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.TaskScheduler 14 | { 15 | public enum WeekOfMonth 16 | { 17 | First = 1, 18 | Second, 19 | Third, 20 | Fourth, 21 | Last 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Source/Test/IO/ReparsePointTestFixture.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | using System.IO; 15 | using Carbon.IO; 16 | using NUnit.Framework; 17 | using IOPath = System.IO.Path; 18 | 19 | namespace Carbon.Test.IO 20 | { 21 | [TestFixture] 22 | public sealed class ReparsePointTestFixture 23 | { 24 | [Test] 25 | public void ShouldGetTargetPathForJunction() 26 | { 27 | var path = IOPath.Combine(IOPath.GetTempPath(), IOPath.GetRandomFileName()); 28 | Directory.CreateDirectory(path); 29 | var junctionPath = string.Format("{0}+junction", path); 30 | JunctionPoint.Create(junctionPath, path, true); 31 | Assert.That(ReparsePoint.GetTarget(junctionPath), Is.EqualTo(path)); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/Test/Installer/Installer1.Designer.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Test.Installer 14 | { 15 | partial class Installer1 16 | { 17 | /// 18 | /// Required designer variable. 19 | /// 20 | private System.ComponentModel.IContainer components = null; 21 | 22 | /// 23 | /// Clean up any resources being used. 24 | /// 25 | /// true if managed resources should be disposed; otherwise, false. 26 | protected override void Dispose(bool disposing) 27 | { 28 | if (disposing && (components != null)) 29 | { 30 | components.Dispose(); 31 | } 32 | base.Dispose(disposing); 33 | } 34 | 35 | #region Component Designer generated code 36 | 37 | /// 38 | /// Required method for Designer support - do not modify 39 | /// the contents of this method with the code editor. 40 | /// 41 | private void InitializeComponent() 42 | { 43 | components = new System.ComponentModel.Container(); 44 | } 45 | 46 | #endregion 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Source/Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System.Reflection; 14 | using System.Runtime.CompilerServices; 15 | using System.Runtime.InteropServices; 16 | 17 | // General Information about an assembly is controlled through the following 18 | // set of attributes. Change these attribute values to modify the information 19 | // associated with an assembly. 20 | [assembly: AssemblyTitle("Carbon.Test")] 21 | [assembly: AssemblyDescription("")] 22 | [assembly: AssemblyConfiguration("")] 23 | [assembly: AssemblyCompany("")] 24 | [assembly: AssemblyProduct("Carbon.Test")] 25 | [assembly: AssemblyTrademark("")] 26 | [assembly: AssemblyCulture("")] 27 | 28 | // Setting ComVisible to false makes the types in this assembly not visible 29 | // to COM components. If you need to access a type in this assembly from 30 | // COM, set the ComVisible attribute to true on that type. 31 | [assembly: ComVisible(false)] 32 | 33 | // The following GUID is for the ID of the typelib if this project is exposed to COM 34 | [assembly: Guid("29cfcfdb-d12b-43f6-9c7c-876dc8087da1")] 35 | -------------------------------------------------------------------------------- /Source/Test/Security/SecureStringConverter.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using NUnit.Framework; 14 | 15 | namespace Carbon.Test.Security 16 | { 17 | [TestFixture] 18 | public sealed class SecureStringConverterTestFixture 19 | { 20 | [Test] 21 | public void ShouldConvertSecureString() 22 | { 23 | const string password = "waffles"; 24 | var securePassword = new System.Security.SecureString(); 25 | foreach( var passwordChar in password.ToCharArray() ) 26 | { 27 | securePassword.AppendChar(passwordChar); 28 | } 29 | 30 | var securePasswordBytes = Carbon.Security.SecureStringConverter.ToBytes(securePassword); 31 | 32 | var passwordBytes = System.Text.Encoding.UTF8.GetBytes(password); 33 | Assert.That(passwordBytes.Length, Is.EqualTo(securePasswordBytes.Length)); 34 | for (var idx = 0; idx < passwordBytes.Length; ++idx) 35 | { 36 | Assert.That(passwordBytes[idx], Is.EqualTo(securePasswordBytes[idx])); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Source/Test/Security/UrlSecurityTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using Carbon.Security; 14 | using NUnit.Framework; 15 | 16 | namespace Carbon.Test.Security 17 | { 18 | [TestFixture] 19 | public sealed class UrlSecurityTests 20 | { 21 | [Test] 22 | public void ShouldReturnAllUrlSecurity() 23 | { 24 | var result = HttpUrlSecurity.GetHttpUrlSecurity(); 25 | Assert.That(result, Is.Not.Null); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/Test/Service/ServiceInfoTestFixture.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | using System.ComponentModel; 15 | using System.ServiceProcess; 16 | using Carbon.Service; 17 | using NUnit.Framework; 18 | 19 | namespace Carbon.Test.Service 20 | { 21 | [TestFixture] 22 | public sealed class ServiceInfoTestFixture 23 | { 24 | 25 | [Test] 26 | public void ShouldGetServices() 27 | { 28 | foreach (var service in ServiceController.GetServices()) 29 | { 30 | var info = new ServiceInfo(service.ServiceName, ""); 31 | Console.WriteLine(info.Name); 32 | Console.WriteLine(string.Format(" DelayedAutoStart {0}", info.DelayedAutoStart)); 33 | Assert.That(info, Is.Not.Null); 34 | } 35 | } 36 | 37 | [Test] 38 | public void ShouldNotGetInvalidService() 39 | { 40 | Assert.Throws(() => { new ServiceInfo(Guid.NewGuid().ToString(), ""); }); 41 | } 42 | 43 | [Test] 44 | public void ShouldSetDelayedAutoStart() 45 | { 46 | var info = new ServiceInfo("BITS"); 47 | Assert.That(info, Is.Not.Null); 48 | Assert.That(info.DelayedAutoStart, Is.True); 49 | } 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Source/Test/Service/ServiceSecurityTests.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using Carbon.Service; 14 | using NUnit.Framework; 15 | using System; 16 | using System.DirectoryServices.AccountManagement; 17 | using System.ServiceProcess; 18 | 19 | namespace Carbon.Test.Service 20 | { 21 | [TestFixture] 22 | public sealed class AdvApi32Tests 23 | { 24 | [Test] 25 | public void ShouldGetPermissions() 26 | { 27 | var service = ServiceController.GetServices()[0]; 28 | ServiceSecurity.GetServiceSecurityDescriptor(service.ServiceName); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Source/Win32/Win32ErrorCodes.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | namespace Carbon.Win32 14 | { 15 | internal static class Win32ErrorCodes 16 | { 17 | internal const int Ok = 0x000; 18 | internal const int NERR_Success = 0x000; 19 | internal const int AccessDenied = 0x005; 20 | internal const int InvalidHandle = 0x006; 21 | internal const int InvalidParameter = 0x057; 22 | internal const int InsufficientBuffer = 0x07A; 23 | internal const int AlreadyExists = 0x0B7; 24 | internal const int NoMoreItems = 0x103; 25 | internal const int InvalidFlags = 0x3EC; 26 | internal const int ServiceMarkedForDelete = 0x430; 27 | internal const int NoneMapped = 0x534; 28 | internal const int MemberNotInAlias = 0x561; 29 | internal const int MemberInAlias = 0x562; 30 | internal const int NoSuchMember = 0x56B; 31 | internal const int InvalidMember = 0x56C; 32 | internal const int NERR_GroupNotFound = 0x8AC; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Source/Xdt/Carbon.Xdt.csproj: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | net452;netstandard2.0 18 | 0.0.0 19 | false 20 | 21 | 22 | 23 | 24 | 6.1.2 25 | compile 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll 36 | false 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Source/Xdt/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System.Reflection; 14 | using System.Runtime.InteropServices; 15 | 16 | 17 | // General Information about an assembly is controlled through the following 18 | // set of attributes. Change these attribute values to modify the information 19 | // associated with an assembly. 20 | [assembly: AssemblyTitle("Carbon XDT")] 21 | [assembly: AssemblyDescription("XDT assembly for Carbon, a PowerShell DevOps setup/configuration automation module.")] 22 | [assembly: AssemblyConfiguration("")] 23 | [assembly: AssemblyCompany("")] 24 | [assembly: AssemblyProduct("Carbon XDT")] 25 | [assembly: AssemblyTrademark("")] 26 | [assembly: AssemblyCulture("")] 27 | [assembly: AssemblyCopyright("Aaron Jensen and WebMD Health Services")] 28 | 29 | // Setting ComVisible to false makes the types in this assembly not visible 30 | // to COM components. If you need to access a type in this assembly from 31 | // COM, set the ComVisible attribute to true on that type. 32 | [assembly: ComVisible(false)] 33 | 34 | // The following GUID is for the ID of the typelib if this project is exposed to COM 35 | [assembly: Guid("4903611d-cdfc-4853-bb5a-bb284f195a2f")] 36 | -------------------------------------------------------------------------------- /Source/Xdt/XdtTransformationException.cs: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | using System; 14 | 15 | namespace Carbon.Xdt 16 | { 17 | internal sealed class XdtTransformationException : Exception 18 | { 19 | public XdtTransformationException(string message) : base(message) 20 | { 21 | } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /System.Exception.format.ps1xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | Exception 19 | 20 | 21 | System.Exception 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | '{0}{1}' -f $_.ToString(),([Environment]::NewLine) 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Test/ActiveDirectory/Test-FindADUser.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | if( (Invoke-CPrivateCommand -Name 'Get-CCimInstance' -Parameter @{Class = 'Win32_ComputerSystem'}).Domain -eq 'WORKGROUP' ) 14 | { 15 | Write-Warning -Message ('Find-ADUser tests can''t run because this computer is not part of a domain.') 16 | } 17 | else 18 | { 19 | $domainUrl = '' 20 | 21 | function Start-TestFixture 22 | { 23 | & (Join-Path -Path $PSScriptRoot -ChildPath '..\Initialize-CarbonTest.ps1' -Resolve) 24 | } 25 | 26 | function Setup 27 | { 28 | $domainController = Get-ADDomainController -Domain $env:USERDOMAIN 29 | Assert-NotNull $domainController 30 | $domainUrl = "LDAP://{0}:389" -f $domainController 31 | } 32 | 33 | function Test-ShouldFindUser 34 | { 35 | $me = Find-ADUser -DomainUrl $domainUrl -sAMAccountName $env:USERNAME 36 | Assert-NotNull $me 37 | Assert-Equal $env:USERNAME $me.sAMAccountName 38 | } 39 | 40 | function Test-ShouldEscapeSpecialCharacters 41 | { 42 | $me = Find-ADUser -DomainUrl $domainUrl -sAMAccountName "(user*with\special/characters)" 43 | Assert-Null $me 44 | } 45 | } -------------------------------------------------------------------------------- /Test/ActiveDirectory/Test-FormatADSearchFilterValue.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | function Start-TestFixture 14 | { 15 | & (Join-Path -Path $PSScriptRoot -ChildPath '..\Initialize-CarbonTest.ps1' -Resolve) 16 | } 17 | 18 | function Test-ShouldEscapeADSpecialCharacters 19 | { 20 | $specialCharacters = "*()\`0/" 21 | $escapedCharacters = Format-ADSearchFilterValue -String $specialCharacters 22 | Assert-Equal '\2a\28\29\5c\00\2f' $escapedCharacters 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Test/Bin.Tests.ps1: -------------------------------------------------------------------------------- 1 | 2 | Set-StrictMode -Version 'Latest' 3 | 4 | Describe 'Bin Directory' { 5 | foreach( $clr in @( 'coreclr', 'fullclr' ) ) 6 | { 7 | $allowedAssemblies = &{ 8 | 'Carbon.dll' 9 | 'Carbon.Iis.dll' 10 | 'Carbon.Xdt.dll' 11 | if( $clr -eq 'coreclr' ) 12 | { 13 | 'Microsoft.Web.Administration.dll' 14 | } 15 | 'Microsoft.Web.XmlTransform.dll' 16 | } 17 | Context $clr { 18 | It 'should not include assemblies that ship with PowerShell' { 19 | $binPath = Join-Path -Path $PSScriptRoot -ChildPath '..\Carbon\bin' -Resolve 20 | $binPath = Join-Path -Path $binPath -ChildPath $clr 21 | $binPath = Join-Path -Path $BinPath -ChildPath '*' 22 | Get-ChildItem -Path $binPath -Exclude ($allowedAssemblies + '*.pdb') | Should -BeNullOrEmpty 23 | } 24 | } 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /Test/CarbonDscTest/ScheduledTask.ps1: -------------------------------------------------------------------------------- 1 | 2 | configuration CScheduledTaskTestCfg 3 | { 4 | param( 5 | $Ensure, 6 | $Name, 7 | $TaskXml 8 | ) 9 | 10 | Set-StrictMode -Off 11 | 12 | Import-DscResource -Name '*' -Module 'Carbon' 13 | 14 | node 'localhost' 15 | { 16 | Carbon_ScheduledTask set 17 | { 18 | Name = $Name; 19 | TaskXml = $TaskXml; 20 | Ensure = $Ensure; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Test/CarbonTest.psm1: -------------------------------------------------------------------------------- 1 | function Invoke-CPrivateCommand 2 | { 3 | [CmdletBinding()] 4 | param( 5 | [Parameter(Mandatory)] 6 | [String] $Name, 7 | 8 | [hashtable] $Parameter = @{} 9 | ) 10 | 11 | $Global:CTName = $Name 12 | $Global:CTParameter = $Parameter 13 | 14 | if( $VerbosePreference -eq 'Continue' ) 15 | { 16 | $Parameter['Verbose'] = $true 17 | } 18 | 19 | $Parameter['ErrorAction'] = $ErrorActionPreference 20 | 21 | try 22 | { 23 | InModuleScope 'Carbon' { 24 | & $CTName @CTParameter 25 | } 26 | } 27 | finally 28 | { 29 | Remove-Variable -Name 'CTParameter' -Scope 'Global' 30 | Remove-Variable -Name 'CTName' -Scope 'Global' 31 | } 32 | } -------------------------------------------------------------------------------- /Test/CarbonVersion.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1' -Resolve) 14 | 15 | $manifest = Test-ModuleManifest -Path (Join-Path -Path $PSScriptRoot -ChildPath '..\Carbon\Carbon.psd1' -Resolve) 16 | Describe 'CarbonVersion' { 17 | $expectedVersion = $null 18 | 19 | BeforeEach { 20 | } 21 | 22 | It 'carbon assembly version is correct' { 23 | $binPath = Join-Path -Path $PSScriptRoot -ChildPath '..\Carbon\bin\*' 24 | Get-ChildItem -Path $binPath -Include 'Carbon*.dll' | ForEach-Object { 25 | 26 | $_.VersionInfo.FileVersion | Should Be $manifest.Version 27 | $_.VersionInfo.ProductVersion.ToString().StartsWith($manifest.Version.ToString()) | Should Be $true 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Test/Certificates/CarbonRsaCng.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/Certificates/CarbonRsaCng.pfx -------------------------------------------------------------------------------- /Test/Certificates/CarbonTestCertificate.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/Certificates/CarbonTestCertificate.cer -------------------------------------------------------------------------------- /Test/Certificates/CarbonTestCertificateWithPassword.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/Certificates/CarbonTestCertificateWithPassword.cer -------------------------------------------------------------------------------- /Test/Certificates/Test-X509StoreProperties.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | function Start-TestFixture 14 | { 15 | & (Join-Path -Path $PSScriptRoot '..\Initialize-CarbonTest.ps1' -Resolve) 16 | } 17 | 18 | function Test-ShouldCreateDisplayNameProperty 19 | { 20 | $storeNameValues = [Enum]::GetValues( [Security.Cryptography.X509Certificates.StoreName] ) 21 | Get-Item cert:\*\* | ForEach-Object { 22 | Assert-NotNull $_.DisplayName 23 | 24 | $storeName = $null 25 | 26 | $enumValue= $_.Name 27 | if( $enumValue -eq 'CA' ) 28 | { 29 | $enumValue = 'CertificateAuthority' 30 | } 31 | if( $storeNameValues -contains $enumValue ) 32 | { 33 | Assert-NotEqual $_.Name $_.DisplayName 34 | } 35 | else 36 | { 37 | Assert-Equal '' $_.DisplayName 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Test/Clear-TrustedHost.Tests.ps1: -------------------------------------------------------------------------------- 1 | 2 | #Requires -Version 5.1 3 | #Requires -RunAsAdministrator 4 | Set-StrictMode -Version 'Latest' 5 | 6 | BeforeAll { 7 | Set-StrictMode -Version 'Latest' 8 | 9 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1' -Resolve) 10 | 11 | $script:originalTrustedHosts = $null 12 | } 13 | 14 | $skip = -not (Test-Path -Path 'WSMan:\localhost\Client\TrustedHosts') 15 | 16 | Describe 'Clear-CTrustedHost' -Skip:$skip { 17 | BeforeEach { 18 | $script:originalTrustedHosts = @( Get-CTrustedHost ) 19 | } 20 | 21 | AfterEach { 22 | if( $script:originalTrustedHosts ) 23 | { 24 | Set-CTrustedHost -Entry $script:originalTrustedHosts 25 | } 26 | } 27 | 28 | It 'should remove trusted hosts' { 29 | Set-CTrustedHost 'example.com' 30 | (Get-CTrustedHost) | Should -Be 'example.com' 31 | Clear-CTrustedHost 32 | (Get-CTrustedHost) | Should -BeNullOrEmpty 33 | } 34 | 35 | It 'should support what if' { 36 | Set-CTrustedHost 'example.com' 37 | (Get-CTrustedHost) | Should -Be 'example.com' 38 | Clear-CTrustedHost -WhatIf 39 | (Get-CTrustedHost) | Should -Be 'example.com' 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Test/Cryptography/CarbonTestPrivateKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/Cryptography/CarbonTestPrivateKey.pfx -------------------------------------------------------------------------------- /Test/Cryptography/CarbonTestPrivateKey2.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/Cryptography/CarbonTestPrivateKey2.pfx -------------------------------------------------------------------------------- /Test/Cryptography/CarbonTestPublicKey.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/Cryptography/CarbonTestPublicKey.cer -------------------------------------------------------------------------------- /Test/FileSystem/Test-DirectoryInfoTypeExtensions.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | $junctionName = $null 14 | $junctionPath = $null 15 | 16 | function Start-TestFixture 17 | { 18 | & (Join-Path -Path $PSScriptRoot '..\Initialize-CarbonTest.ps1' -Resolve) 19 | } 20 | 21 | function Start-Test 22 | { 23 | $junctionName = [IO.Path]::GetRandomFilename() 24 | $junctionPath = Join-Path $env:Temp $junctionName 25 | New-Junction -Link $junctionPath -Target $TestDir 26 | } 27 | 28 | function Stop-Test 29 | { 30 | Remove-Junction -Path $junctionPath 31 | } 32 | 33 | function Test-ShouldAddIsJunctionProperty 34 | { 35 | $dirInfo = Get-Item $junctionPath 36 | Assert-True $dirInfo.IsJunction 37 | 38 | $dirInfo = Get-Item $TestDir 39 | Assert-False $dirInfo.IsJunction 40 | } 41 | 42 | function Test-ShouldAddTargetPathProperty 43 | { 44 | $dirInfo = Get-Item $junctionPath 45 | Assert-Equal $TestDir $dirInfo.TargetPath 46 | 47 | $dirInfo = Get-Item $Testdir 48 | Assert-Null $dirInfo.TargetPath 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /Test/FileSystem/Test-NewTempDirectory.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | 14 | function Start-TestFixture 15 | { 16 | & (Join-Path -Path $PSScriptRoot '..\Initialize-CarbonTest.ps1' -Resolve) 17 | } 18 | 19 | function Test-NewTempDir 20 | { 21 | $tmpDir = New-TempDir 22 | try 23 | { 24 | Assert-DirectoryExists $tmpDir 25 | } 26 | finally 27 | { 28 | Uninstall-Directory -Path $tmpDir -Recurse 29 | } 30 | } 31 | 32 | function Test-ShouldSupportPrefix 33 | { 34 | $tempDir = New-TempDir -Prefix 'fubar' 35 | try 36 | { 37 | Assert-DirectoryExists $tempDir 38 | Assert-Like $tempDir.Name 'fubar*' 39 | } 40 | finally 41 | { 42 | Uninstall-Directory -Path $tempDir -Recurse 43 | } 44 | } 45 | 46 | function Test-ShouldSupportPathsForPrefix 47 | { 48 | $tempDir = New-TempDirectory -Prefix $PSCommandPath 49 | try 50 | { 51 | Assert-DirectoryExists $tempDir 52 | Assert-Like $tempDir.Name ('{0}*' -f (Split-Path -Leaf -Path $PSCommandPath)) 53 | } 54 | finally 55 | { 56 | Uninstall-Directory -Path $tempDir -Recurse 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /Test/Firewall/Test-DisableFirewallStatefulFtp.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | $alreadyEnabled = $false 14 | 15 | function Start-TestFixture 16 | { 17 | & (Join-Path -Path $PSScriptRoot -ChildPath '..\Initialize-CarbonTest.ps1' -Resolve) 18 | } 19 | 20 | function Start-Test 21 | { 22 | $alreadyEnabled = Test-FirewallStatefulFtp 23 | 24 | if( -not $alreadyEnabled ) 25 | { 26 | Enable-FirewallStatefulFtp 27 | } 28 | } 29 | 30 | function Stop-Test 31 | { 32 | if( $alreadyEnabled ) 33 | { 34 | Enable-FirewallStatefulFtp 35 | } 36 | else 37 | { 38 | Disable-FirewallStatefulFtp 39 | } 40 | } 41 | 42 | function Test-ShouldDisableStatefulFtp 43 | { 44 | Disable-FirewallStatefulFtp 45 | $enabled = Test-FirewallStatefulFtp 46 | Assert-False $enabled 'StatefulFtp not enabled on firewall.' 47 | } 48 | 49 | function Test-ShouldSupportWhatIf 50 | { 51 | $enabled = Test-FirewallStatefulFtp 52 | Assert-True $enabled 'StatefulFTP not enabled' 53 | Disable-FirewallStatefulFtp -WhatIf 54 | $enabled = Test-FirewallStatefulFtp 55 | Assert-True $enabled 'StatefulFTP disable with -WhatIf parameter given.' 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Test/Firewall/Test-EnableFirewallStatefulFtp.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | $alreadyEnabled = $false 14 | 15 | function Start-TestFixture 16 | { 17 | & (Join-Path -Path $PSScriptRoot '..\Initialize-CarbonTest.ps1' -Resolve) 18 | } 19 | 20 | function Start-Test 21 | { 22 | $alreadyEnabled = Test-FirewallStatefulFtp 23 | 24 | if( $alreadyEnabled ) 25 | { 26 | Disable-FirewallStatefulFtp 27 | } 28 | } 29 | 30 | function Stop-Test 31 | { 32 | if( $alreadyEnabled ) 33 | { 34 | Enable-FirewallStatefulFtp 35 | } 36 | else 37 | { 38 | Disable-FirewallStatefulFtp 39 | } 40 | } 41 | 42 | function Test-ShouldEnableStatefulFtp 43 | { 44 | Enable-FirewallStatefulFtp 45 | $enabled = Test-FirewallStatefulFtp 46 | Assert-True $enabled 'StatefulFtp not enabled on firewall.' 47 | } 48 | 49 | function Test-ShouldSupportWhatIf 50 | { 51 | Enable-FirewallStatefulFtp -WhatIf 52 | $enabled = Test-FirewallStatefulFtp 53 | Assert-False $enabled 'StatefulFTP enabled with -WhatIf parameter given.' 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Test/Path/Test-TestUncPath.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | function Start-TestFixture 14 | { 15 | & (Join-Path -Path $PSScriptRoot -ChildPath '..\Initialize-CarbonTest.ps1' -Resolve) 16 | } 17 | 18 | function Test-ShouldTestUncPath 19 | { 20 | Assert-True (Test-UncPath -Path '\\computer\share') 21 | } 22 | 23 | function Test-ShouldTestRelativePath 24 | { 25 | Assert-False (Test-UncPath -Path '..\..\foo\bar') 26 | } 27 | 28 | function Test-ShouldTestNtfsPath 29 | { 30 | Assert-False (Test-UncPath -Path 'C:\foo\bar\biz\baz\buz') 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Test/PerformanceCounters/Test-GetPerformanceCounter.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | function Start-TestFixture 14 | { 15 | & (Join-Path -Path $PSScriptRoot -ChildPath '..\Initialize-CarbonTest.ps1' -Resolve) 16 | } 17 | 18 | function Test-ShouldGetPerformanceCounters 19 | { 20 | $categories = [Diagnostics.PerformanceCounterCategory]::GetCategories() 21 | foreach( $category in $categories ) 22 | { 23 | $countersExpected = @( $category.GetCounters("") ) 24 | $countersActual = @( Get-PerformanceCounter -CategoryName $category.CategoryName ) 25 | Assert-Equal $countersExpected.Length $countersActual.Length 26 | } 27 | 28 | } 29 | 30 | function Test-ShouldGetNoPerformanceCountersForNonExistentCategory 31 | { 32 | $counters = Get-PerformanceCounter -CategoryName 'IDoNotExist' 33 | Assert-Null $counters 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Test/PerformanceCounters/Test-UninstallPerformanceCounterCategory.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | $CategoryName = 'Carbon-PerformanceCounters-UninstallCategory' 14 | 15 | function Start-TestFixture 16 | { 17 | & (Join-Path -Path $PSScriptRoot -ChildPath '..\Initialize-CarbonTest.ps1' -Resolve) 18 | } 19 | 20 | function Start-Test 21 | { 22 | [Diagnostics.PerformanceCounterCategory]::Create( $CategoryName, '', (New-Object Diagnostics.CounterCreationDataCollection) ) 23 | Assert-True (Test-PerformanceCounterCategory -CAtegoryName $CAtegoryName) 24 | } 25 | 26 | function Stop-Test 27 | { 28 | Uninstall-PerformanceCounterCategory -CategoryName $CategoryName 29 | Assert-False (Test-PerformanceCounterCategory -CAtegoryName $CAtegoryName) 30 | } 31 | 32 | function Test-ShouldSupportWhatIf 33 | { 34 | Uninstall-PerformanceCounterCategory -CategoryName $CategoryName -WhatIf 35 | Assert-True (Test-PerformanceCounterCategory -CategoryName $CategoryName) 36 | } 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Test/PowerShell/Get-PSVersionTable.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | param( 14 | [string] 15 | $Message 16 | ) 17 | 18 | $Message 19 | 20 | $PSVersionTable 21 | 22 | $env:PROCESSOR_ARCHITECTURE 23 | -------------------------------------------------------------------------------- /Test/PowerShell/Get-Username.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | param( 14 | $InputObject 15 | ) 16 | 17 | $InputObject 18 | 19 | $env:USERNAME -------------------------------------------------------------------------------- /Test/ScheduledTasks/task.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/ScheduledTasks/task.xml -------------------------------------------------------------------------------- /Test/ScheduledTasks/task_with_principal.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/ScheduledTasks/task_with_principal.xml -------------------------------------------------------------------------------- /Test/Service/NoOpService.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/Service/NoOpService.exe -------------------------------------------------------------------------------- /Test/Service/NoOpService.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Test/Service/NoOpService.pdb -------------------------------------------------------------------------------- /Test/Set-TrustedHost.Tests.ps1: -------------------------------------------------------------------------------- 1 | 2 | #Requires -Version 5.1 3 | #Requires -RunAsAdministrator 4 | Set-StrictMode -Version 'Latest' 5 | 6 | BeforeAll { 7 | Set-StrictMode -Version 'Latest' 8 | 9 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1' -Resolve) 10 | 11 | $script:originalTrustedHosts = $null 12 | } 13 | 14 | $skip = -not (Test-Path -Path 'WSMan:\localhost\Client\TrustedHosts') 15 | 16 | Describe 'Set-CTrustedHost' -Skip:$skip { 17 | BeforeEach { 18 | $script:originalTrustedHosts = @( Get-CTrustedHost ) 19 | Clear-CTrustedHost 20 | } 21 | 22 | AfterEach { 23 | if( $script:originalTrustedHosts ) 24 | { 25 | Set-CTrustedHost -Entry $script:originalTrustedHosts 26 | } 27 | } 28 | 29 | It 'should set trusted hosts' { 30 | Set-CTrustedHost 'example.com' 31 | (Get-CTrustedHost) | Should -Be 'example.com' 32 | Set-CTrustedHost 'example.com','sub.example.com' 33 | $hosts = @( Get-CTrustedHost ) 34 | $hosts[0] | Should -Be 'example.com' 35 | $hosts[1] | Should -Be 'sub.example.com' 36 | } 37 | 38 | It 'should support what if' { 39 | Set-CTrustedHost 'example.com' 40 | (Get-CTrustedHost) | Should -Be 'example.com' 41 | Set-CTrustedHost 'badexample.com' -WhatIf 42 | (Get-CTrustedHost) | Should -Be 'example.com' 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Test/System.Diagnostics.Process.types.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1' -Resolve) 14 | 15 | Describe 'System.Diagnostics.Process' { 16 | It 'processes have ParentProcessID' { 17 | $parents = @{} 18 | Invoke-CPrivateCommand -Name 'Get-CCimInstance' -Parameter @{Class = 'Win32_Process'} | ForEach-Object { $parents[$_.ProcessID] = $_.ParentProcessID } 19 | $foundSome = $false 20 | Get-Process | 21 | Where-Object { $parents.ContainsKey( [UInt32]$_.Id ) -and $_.ParentProcessID } | 22 | ForEach-Object { 23 | $foundSome = $true 24 | $expectedID = $parents[ [UInt32]$_.Id ] 25 | $_.ParentProcessID | Should -Be $expectedID 26 | } 27 | $foundSome | Should -Be $true 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Test/System.IO.FileInfo.types.ps1xml.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1' -Resolve) 14 | 15 | function GivenANormalFile 16 | { 17 | $file = Join-Path -Path $TestDrive.FullName -ChildPath 'file' 18 | '' | Set-Content -Path $file 19 | Get-Item -Path $file 20 | } 21 | 22 | Describe 'Carbon.when getting normal files' { 23 | $file = GivenANormalFile 24 | 25 | It 'should not be a symbolic link' { 26 | $file.IsSymbolicLink | Should Be $false 27 | } 28 | It 'should not have a target path' { 29 | $file.TargetPath | Should Be $null 30 | } 31 | } 32 | 33 | Describe 'Carbon.when getting symoblic link files' { 34 | $file = GivenANormalFile 35 | $symFilePath = Join-Path -Path $TestDrive.FullName -ChildPath 'destination' 36 | $symFile = [Carbon.IO.SymbolicLink]::Create($symFilePath, $File.FullName, $false) 37 | 38 | $fileInfo = Get-Item -Path $symFilePath 39 | 40 | It 'should be a symbolic link' { 41 | $fileInfo.IsSymbolicLink | Should Be $true 42 | } 43 | It 'should have a target path' { 44 | $fileInfo.TargetPath | Should Be $file.FullName 45 | } 46 | } -------------------------------------------------------------------------------- /Test/Test-CUser.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | #Requires -Version 5.1 14 | Set-StrictMode -Version 'Latest' 15 | 16 | BeforeAll { 17 | Set-StrictMode -Version 'Latest' 18 | 19 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1' -Resolve) 20 | } 21 | 22 | Describe 'Test-Cuser' { 23 | BeforeEach { 24 | $Global:Error.Clear() 25 | } 26 | 27 | It 'should check if local account exists' { 28 | $localUserAccounts = Get-CUser 29 | $localUserAccounts | Should -Not -BeNullOrEmpty 30 | foreach( $localUserAccount in $localUserAccounts ) 31 | { 32 | Test-Cuser -Username $localUserAccount.Name | Should -BeTrue 33 | } 34 | } 35 | 36 | It 'should not find non existent account' { 37 | Test-Cuser -Username ([Guid]::NewGuid().ToString().Substring(0,20)) | Should -BeFalse 38 | $Global:Error | Should -BeNullOrEmpty 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Test/Test-Group.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | Set-StrictMode -Version 'Latest' 14 | 15 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1' -Resolve) 16 | 17 | Describe 'Test-Group' { 18 | It 'should check if local group exists' { 19 | $groups = Get-Group 20 | try 21 | { 22 | $groups | Should -Not -BeNullOrEmpty 23 | $groups | 24 | # Sometimes on the build server, groups come back without a name. 25 | Where-Object { $_.Name } | 26 | ForEach-Object { Test-Group -Name $_.Name } | 27 | Should -BeTrue 28 | } 29 | finally 30 | { 31 | $groups | ForEach-Object { $_.Dispose() } 32 | } 33 | } 34 | 35 | It 'should not find non existent account' { 36 | $error.Clear() 37 | (Test-Group -Name ([Guid]::NewGuid().ToString().Substring(0,20))) | Should -BeFalse 38 | $error | Should -BeNullOrEmpty 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Test/Test-UninstallDirectory.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1' -Resolve) 14 | 15 | function Start-Test 16 | { 17 | $dir = Join-Path -Path $env:TEMP -ChildPath ([IO.Path]::GetRandomFileName()) 18 | Install-Directory -Path $dir 19 | } 20 | 21 | function Stop-Test 22 | { 23 | if( (Test-Path -Path $dir -PathType Container) ) 24 | { 25 | Remove-Item -Path $dir -Recurse 26 | } 27 | } 28 | 29 | function Test-ShouldRemoveDirectory 30 | { 31 | Uninstall-Directory -Path $dir 32 | Assert-NoError 33 | Assert-DirectoryDoesNotExist $dir 34 | } 35 | 36 | function Test-ShouldHandleDirectoryThatDoesNotExist 37 | { 38 | Uninstall-Directory -Path $dir 39 | Uninstall-Directory -Path $dir 40 | Assert-NoError 41 | Assert-DirectoryDoesNotExist $dir 42 | } 43 | 44 | function Test-ShouldDeleteRecursively 45 | { 46 | $filePath = Join-Path -Path $dir -ChildPath 'file' 47 | New-Item -Path $filePath -ItemType 'File' 48 | Uninstall-Directory -Path $dir -Recurse 49 | Assert-NoError 50 | Assert-DirectoryDoesNotExist $dir 51 | } -------------------------------------------------------------------------------- /Test/Test-UsesUseCallerPreference.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | function Test-FunctionsShouldUseUseCallerPreference 14 | { 15 | $files = Get-ChildItem -Path (Join-Path -Path $PSScriptRoot -ChildPath '..\Carbon\Functions\*.ps1') -File | 16 | Where-Object { $_.BaseName -ne 'Use-CallerPreference' } | 17 | Where-Object { -not ($_ | Select-String -Pattern 'Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState' -SimpleMatch) } | 18 | Select-Object -ExpandProperty 'Name' | 19 | Sort-Object 20 | 21 | if( $files ) 22 | { 23 | Fail ('The following scripts don''t don''t use `Use-CallerPreference`:{0} * {1}' -f ([Environment]::NewLine),($files -join ('{0} * ' -f ([Environment]::NewLine)))) 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Test/Uninstall-Group.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | Set-StrictMode -Version 'Latest' 14 | 15 | & (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-CarbonTest.ps1') 16 | 17 | describe Uninstall-Group { 18 | 19 | $groupName = 'TestUninstallGroup' 20 | $description = 'Used by Uninstall-Group.Tests.ps1' 21 | 22 | BeforeEach { 23 | Install-Group -Name $groupName -Description $description 24 | $Global:Error.Clear() 25 | } 26 | 27 | AfterEach { 28 | Uninstall-Group -Name $groupName 29 | } 30 | 31 | BeforeEach { 32 | $Global:Error.Clear() 33 | } 34 | 35 | It 'should remove the group' { 36 | Test-Group -Name $groupName | Should Be $true 37 | Uninstall-Group -Name $groupName 38 | Test-Group -Name $groupName | Should Be $false 39 | } 40 | 41 | It 'should remove nonexistent group without errors' { 42 | Uninstall-Group -Name 'fubarsnafu' 43 | $Global:Error.Count | Should Be 0 44 | } 45 | 46 | It 'should support WhatIf' { 47 | Uninstall-Group -Name $groupName -WhatIf 48 | Test-Group -Name $groupName | Should Be $true 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Test/UsersAndGroups/Test-GetWmiLocalUserAccount.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | function Start-TestFixture 14 | { 15 | & (Join-Path -Path $PSScriptRoot -ChildPath '..\Initialize-CarbonTest.ps1' -Resolve) 16 | } 17 | 18 | function Test-ShouldGetUser 19 | { 20 | Invoke-CPrivateCommand -Name 'Get-CCimInstance' -Parameter @{Class = 'Win32_UserAccount'; Filter = "Domain='$($env:ComputerName)'"} | ForEach-Object { 21 | $user = Get-WmiLocalUserAccount -Username $_.Name 22 | Assert-NotNull $user 23 | Assert-Equal $_.Name $user.Name 24 | Assert-Equal $_.FullName $user.FullName 25 | Assert-Equal $_.SID $user.SID 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Test/UsersAndGroups/Test-UninstallUser.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | $username = 'CarbonRemoveUser' 14 | $password = 'IM33tRequ!rem$' 15 | 16 | function Start-Test 17 | { 18 | & (Join-Path -Path $PSScriptRoot -ChildPath '..\Initialize-CarbonTest.ps1' -Resolve) 19 | } 20 | 21 | function Start-Test 22 | { 23 | net user $username $password /add 24 | } 25 | 26 | function Stop-Test 27 | { 28 | if( Test-User -Username $username ) 29 | { 30 | net user $username /delete 31 | } 32 | } 33 | 34 | function Test-ShouldRemoveUser 35 | { 36 | Uninstall-User -Username $username 37 | Assert-False (Test-User -Username $username) 38 | } 39 | 40 | function Test-ShouldHandleRemovingNonExistentUser 41 | { 42 | $Error.Clear() 43 | Uninstall-User -Username ([Guid]::NewGuid().ToString().Substring(0,20)) 44 | Assert-False $Error 45 | } 46 | 47 | function Test-ShouldSupportWhatIf 48 | { 49 | Uninstall-User -Username $username -WhatIf 50 | Assert-True (Test-User -Username $username) 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Test/X509Certificate2.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | #Requires -Version 5.1 14 | Set-StrictMode -Version 'Latest' 15 | 16 | BeforeAll { 17 | Set-StrictMode -Version 'Latest' 18 | 19 | & (Join-Path -Path $PSScriptRoot 'Initialize-CarbonTest.ps1' -Resolve) 20 | } 21 | 22 | 23 | Describe 'X509Certificate2' { 24 | It 'should create issued properties on x509 certificate2' { 25 | $certPath = Join-Path -Path $PSScriptRoot -ChildPath 'Certificates\CarbonTestCertificate.cer' -Resolve 26 | $cert = Get-CCertificate -Path $certPath -NoWarn 27 | $cert.IssuedTo | Should -Not -BeNullOrEmpty 28 | $cert.IssuedBy | Should -Not -BeNullOrEmpty 29 | 30 | $cert.IssuedBy | Should -Be ($cert.GetNameInfo( 'SimpleName', $true )) 31 | $cert.IssuedTo | Should -Be ($cert.GetNameInfo( 'SimpleName', $false )) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Tools/Blade/Blade.psm1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | Get-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'Functions\*.ps1') | 16 | ForEach-Object { . $_.FullName } 17 | 18 | $privateFunctions = @{ 19 | 'Remove-ItemWithRetry' = $true; 20 | 'Invoke-Test' = $true; 21 | 'Get-FunctionsInFile' = $true; 22 | } 23 | 24 | $publicFunctions = Get-ChildItem -Path 'function:\' | 25 | Where-Object { $_.ModuleName -eq 'Blade' } | 26 | Where-Object { -not $privateFunctions.ContainsKey( $_.Name ) } | 27 | Select-Object -ExpandProperty 'Name' 28 | 29 | Export-ModuleMember -Function $publicFunctions -Alias * 30 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-CEqual.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-CEqual 16 | { 17 | <# 18 | .SYNOPSIS 19 | OBSOLETE. Use `Assert-Equal -CaseSenstive` instead. 20 | 21 | .DESCRIPTION 22 | OBSOLETE. Use `Assert-Equal -CaseSenstive` instead. 23 | 24 | .EXAMPLE 25 | Assert-Equal 'foo' 'FOO' -CaseSensitive 26 | 27 | Demonstrates how to use `Assert-Equal` instead of `Assert-CEqual`. 28 | #> 29 | param( 30 | [Parameter(Mandatory=$true,Position=0)] 31 | [string] 32 | # The expected string. 33 | $Expected, 34 | 35 | [Parameter(Mandatory=$true,Position=1)] 36 | [string] 37 | # The actual string. 38 | $Actual, 39 | 40 | [Parameter(Mandatory=$true,Position=2)] 41 | [string] 42 | # A message to show when the assertion fails. 43 | $Message 44 | ) 45 | 46 | Write-Warning ('Assert-CEqual is obsolete. Use Assert-Equal with the -CaseSensitive switch instead.') 47 | Assert-Equal -Expected $Expected -Actual $Actual -Message $Message -CaseSensitive 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-DirectoryDoesNotExist.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-DirectoryDoesNotExist 16 | { 17 | <# 18 | .SYNOPSIS 19 | Asserts that a directory doesn't exist. 20 | 21 | .DESCRIPTION 22 | Uses PowerShell's `Test-Path` cmdlet to check if a directory doesn't exist. 23 | 24 | .EXAMPLE 25 | Assert-DirectoryExists 'C:\Windows' 26 | 27 | Demonstrates how to assert that a directory doesn't exist. 28 | 29 | .EXAMPLE 30 | Assert-DirectoryExists 'C:\Foobar' 'Foobar wasn''t removed.' 31 | 32 | Demonstrates how to describe why an assertion might fail. 33 | #> 34 | [CmdletBinding()] 35 | param( 36 | [Parameter(Position=0)] 37 | [string] 38 | # The path to the directory to check. 39 | $Path, 40 | 41 | [Parameter(Position=1)] 42 | [string] 43 | # A description of why the assertion might fail. 44 | $Message 45 | ) 46 | 47 | Set-StrictMode -Version 'Latest' 48 | 49 | if( Test-Path -Path $Path -PathType Container ) 50 | { 51 | Fail "Directory '$Path' exists. $Message" 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-DirectoryExists.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-DirectoryExists 16 | { 17 | <# 18 | .SYNOPSIS 19 | Asserts that a directory exists. 20 | 21 | .DESCRIPTION 22 | Uses PowerShell's `Test-Path` cmdlet to check if a directory exists. 23 | 24 | .EXAMPLE 25 | Assert-DirectoryExists 'C:\Windows' 26 | 27 | Demonstrates how to assert that a directory exists. 28 | 29 | .EXAMPLE 30 | Assert-DirectoryExists 'C:\Foobar' 'Foobar wasn''t created.' 31 | 32 | Demonstrates how to describe why an assertion might fail. 33 | #> 34 | [CmdletBinding()] 35 | param( 36 | [Parameter(Position=0)] 37 | [string] 38 | # The path to the directory to check. 39 | $Path, 40 | 41 | [Parameter(Position=1)] 42 | [string] 43 | # A description of why the assertion might fail. 44 | $Message 45 | ) 46 | 47 | Set-StrictMode -Version 'Latest' 48 | 49 | if( -not (Test-Path -Path $Path -PathType Container) ) 50 | { 51 | Fail "Directory $Path does not exist. $Message" 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-FileDoesNotExist.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-FileDoesNotExist 16 | { 17 | <# 18 | .SYNOPSIS 19 | Asserts that a file does not exist. 20 | 21 | .DESCRIPTION 22 | Uses PowerShell's `Test-Path` cmdlet to check if a file doesn't exist. 23 | 24 | .EXAMPLE 25 | Assert-FileDoesNotExist 'C:\foobar.txt' 26 | 27 | Demonstrates how to assert that a does not exist. 28 | 29 | .EXAMPLE 30 | Assert-FileDoesNotExist 'C:\foobar.txt' 'foobar.txt not removed.' 31 | 32 | Demonstrates how to describe why an assertion might fail. 33 | #> 34 | [CmdletBinding()] 35 | param( 36 | [Parameter(Position=0)] 37 | [string] 38 | # The path to the file to check. 39 | $Path, 40 | 41 | [Parameter(Position=1)] 42 | [string] 43 | # A description of why the assertion might fail. 44 | $Message 45 | ) 46 | 47 | Set-StrictMode -Version 'Latest' 48 | 49 | if( Test-Path -Path $Path -PathType Leaf ) 50 | { 51 | Fail "File $Path exists: $Message" 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-LastError.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-LastError 16 | { 17 | <# 18 | .SYNOPSIS 19 | OBSOLETE. Use `Assert-Error` instead. 20 | 21 | .DESCRIPTION 22 | OBSOLETE. Use `Assert-Error` instead. 23 | 24 | .EXAMPLE 25 | Assert-Error -Last 'not found' 26 | 27 | Demonstrates how to use `Assert-Error` instead. 28 | #> 29 | [CmdletBinding()] 30 | param( 31 | [Parameter(Mandatory=$true,Position=0)] 32 | [string] 33 | # The expected error message for the last error. 34 | $ExpectedError, 35 | 36 | [Parameter(Position=1)] 37 | [string] 38 | # A custom message to show when the assertion fails. 39 | $Message 40 | ) 41 | 42 | Set-StrictMode -Version 'Latest' 43 | 44 | Write-Warning 'OBSOLETE. Use `Assert-Error -Last` instead.' 45 | 46 | Assert-Error -Last -Regex $ExpectedError 47 | } 48 | Set-Alias -Name 'Assert-LastPipelineError' -Value 'Assert-LastError' 49 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-LastProcessFailed.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-LastProcessFailed 16 | { 17 | <# 18 | .SYNOPSIS 19 | Asserts that the last process failed by checking PowerShell's `$LastExitCode` automatic variable. 20 | 21 | .DESCRIPTION 22 | A process fails if `$LastExitCode` is non-zero. 23 | 24 | .EXAMPLE 25 | Assert-LastProcessFailed 26 | 27 | Demonstrates how to assert that the last process failed. 28 | 29 | .EXAMPLE 30 | Assert-LastProcessFailed 'cmd.exe' 31 | 32 | Demonstrates how to show a custom message when the assertion fails. 33 | #> 34 | [CmdletBinding()] 35 | param( 36 | [Parameter(Position=0)] 37 | [string] 38 | # The message to show if the assertion fails. 39 | $Message 40 | ) 41 | 42 | Set-StrictMode -Version 'Latest' 43 | 44 | if( $LastExitCode -eq 0 ) 45 | { 46 | Fail "Expected process to fail, but it succeeded (exit code: $LastExitCode). $Message" 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-LastProcessSucceeded.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-LastProcessSucceeded 16 | { 17 | <# 18 | .SYNOPSIS 19 | Asserts that the last process succeeded by checking PowerShell's `$LastExitCode` automatic variable. 20 | 21 | .DESCRIPTIoN 22 | A process succeeds if `$LastExitCode` is zero. 23 | 24 | .EXAMPLE 25 | Assert-LastProcessSucceeded 26 | 27 | Demonstrates how to assert that the last process succeeded. 28 | 29 | .EXAMPLE 30 | Assert-LastProcessSucceeded 'cmd.exe' 31 | 32 | Demonstrates how to show a custom message when the assertion fails. 33 | #> 34 | [CmdletBinding()] 35 | param( 36 | [Parameter(Position=0)] 37 | [string] 38 | # The message to show if the assertion fails. 39 | $Message 40 | ) 41 | 42 | if( $LastExitCode -ne 0 ) 43 | { 44 | Fail "Expected process to succeed, but it failed (exit code: $LastExitCode). $Message" 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-NotNull.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-NotNull 16 | { 17 | <# 18 | .SYNOPSIS 19 | Asserts that an object isn't `$null`. 20 | 21 | .DESCRIPTION 22 | 23 | .EXAMPLE 24 | Assert-NotNull $null 25 | 26 | Demonstrates how to fail a test by asserting that `$null` isn't `$null`. 27 | 28 | .EXAMPLE 29 | Assert-NotNull $object 'The foo didn''t bar!' 30 | 31 | Demonstrates how to give a descriptive error about why the assertion might be failing. 32 | #> 33 | [CmdletBinding()] 34 | param( 35 | [Parameter(Position=0)] 36 | [object] 37 | # The object to check. 38 | $InputObject, 39 | 40 | [Parameter(Position=1)] 41 | [string] 42 | # A reason why the assertion fails. 43 | $Message 44 | ) 45 | 46 | Set-StrictMode -Version 'Latest' 47 | 48 | if( $InputObject -eq $null ) 49 | { 50 | Fail ("Value is null. {0}" -f $message) 51 | } 52 | } 53 | 54 | Set-Alias -Name 'Assert-IsNotNull' -Value 'Assert-NotNull' 55 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Assert-Null.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Assert-Null 16 | { 17 | <# 18 | .SYNOPSIS 19 | Asserts that an object/value is `$null`. 20 | 21 | .DESCRIPTION 22 | `Value` is literally compared with `$null`. 23 | 24 | .EXAMPLE 25 | Assert-Null $null 26 | 27 | Demonstrates how to assert a value is equal to `$null`. 28 | 29 | .EXAMPLE 30 | Assert-Null '' 'Uh-oh. Empty string is null.' 31 | 32 | Demonstrates how to assert a value is equal to `$null` and show a custom error message. 33 | #> 34 | [CmdletBinding()] 35 | param( 36 | [Parameter(Position=0)] 37 | [object] 38 | # The value to check. 39 | $Value, 40 | 41 | [Parameter(Position=1)] 42 | [string] 43 | # The message to show when `Value` if not null. 44 | $Message 45 | ) 46 | 47 | Set-StrictMode -Version 'Latest' 48 | 49 | if( $Value -ne $null ) 50 | { 51 | Fail "Value '$Value' is not null: $Message" 52 | } 53 | } 54 | 55 | Set-Alias -Name 'Assert-IsNull' -Value 'Assert-Null' 56 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/New-AssertionException.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function New-AssertionException 16 | { 17 | <# 18 | .SYNOPSIS 19 | Creates and throws a `Blade.AssertionException`, which fails a test. 20 | 21 | .DESCRIPTION 22 | All failed assertions call this function to report the failure. This is Blade's `Fail` function. 23 | 24 | ALIASES 25 | 26 | * Fail 27 | #> 28 | param( 29 | [Parameter(Position=0)] 30 | [string] 31 | # The failure message. 32 | $Message 33 | ) 34 | 35 | Set-StrictMode -Version 'Latest' 36 | 37 | $scopeNum = 0 38 | $stackTrace = @() 39 | 40 | foreach( $item in (Get-PSCallStack) ) 41 | { 42 | $invocationInfo = $item.InvocationInfo 43 | $stackTrace += "$($item.ScriptName):$($item.ScriptLineNumber) $($invocationInfo.MyCommand)" 44 | } 45 | 46 | $ex = New-Object 'Blade.AssertionException' $message,$stackTrace 47 | throw $ex 48 | } 49 | 50 | Set-Alias -Name 'Fail' -Value 'New-AssertionException' 51 | -------------------------------------------------------------------------------- /Tools/Blade/Functions/Remove-ItemWithRetry.ps1: -------------------------------------------------------------------------------- 1 | # Copyright 2012 - 2015 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function Remove-ItemWithRetry($item, [Switch]$Recurse) 16 | { 17 | if( -not (Test-Path $item) ) 18 | { 19 | return 20 | } 21 | 22 | $RecurseParam = if( $Recurse ) { '-Recurse' } else { '' } 23 | $numTries = 0 24 | do 25 | { 26 | if( -not (Test-Path $item) ) 27 | { 28 | return $true 29 | } 30 | 31 | if( $Recurse ) 32 | { 33 | Remove-Item $item -Recurse -Force -ErrorAction SilentlyContinue 34 | } 35 | else 36 | { 37 | Remove-Item $item -Force -ErrorAction SilentlyContinue 38 | } 39 | 40 | if( Test-Path $item ) 41 | { 42 | Start-Sleep -Milliseconds 100 43 | } 44 | else 45 | { 46 | return $true 47 | } 48 | $numTries += 1 49 | } 50 | while( $numTries -lt 20 ) 51 | return $false 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Tools/Blade/Import-Blade.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Imports the Blade module. 4 | 5 | .DESCRIPTION 6 | Normally, you shouldn't need to import Blade. Usually, you'll just call the `blade.ps1` script directly and it will import Blade for you. 7 | 8 | If Blade is already imported, it will be removed and then re-imported. 9 | 10 | .EXAMPLE 11 | Import-Blade.ps1 12 | 13 | Demonstrates how to import the Blade module. 14 | #> 15 | param( 16 | ) 17 | 18 | #Requires -Version 3 19 | Set-StrictMode -Version 'Latest' 20 | 21 | & { 22 | $originalVerbosePreference = $Global:VerbosePreference 23 | $Global:VerbosePreference = [Management.Automation.ActionPreference]::SilentlyContinue 24 | 25 | if( (Get-Module -Name 'Blade') ) 26 | { 27 | Remove-Module 'Blade' 28 | } 29 | 30 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'Blade.psd1' -Resolve) 31 | } 32 | -------------------------------------------------------------------------------- /Tools/Blade/bin/Blade.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/Blade/bin/Blade.dll -------------------------------------------------------------------------------- /Tools/DotNetZip.1.9.3/DotNetZip.1.9.3.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/DotNetZip.1.9.3/DotNetZip.1.9.3.nupkg -------------------------------------------------------------------------------- /Tools/DotNetZip.1.9.3/lib/net20/Ionic.Zip.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/DotNetZip.1.9.3/lib/net20/Ionic.Zip.dll -------------------------------------------------------------------------------- /Tools/MarkdownSharp/MarkdownSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/MarkdownSharp/MarkdownSharp.dll -------------------------------------------------------------------------------- /Tools/NUnit/2.6.2/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/NUnit/2.6.2/nunit.framework.dll -------------------------------------------------------------------------------- /Tools/NUnit/2.6.2/nunit.mocks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/NUnit/2.6.2/nunit.mocks.dll -------------------------------------------------------------------------------- /Tools/NUnit/2.6.2/pnunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/NUnit/2.6.2/pnunit.framework.dll -------------------------------------------------------------------------------- /Tools/PowerShell/2.0/System.Management.Automation.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/PowerShell/2.0/System.Management.Automation.dll -------------------------------------------------------------------------------- /Tools/PowerShell/3.0/System.Management.Automation.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/PowerShell/3.0/System.Management.Automation.dll -------------------------------------------------------------------------------- /Tools/Silk/Functions/Convert-MarkdownToHtml.ps1: -------------------------------------------------------------------------------- 1 | 2 | filter Convert-MarkdownToHtml 3 | { 4 | if( $_ ) 5 | { 6 | $markdown.Transform( $_ ).Trim() 7 | } 8 | } -------------------------------------------------------------------------------- /Tools/Silk/Functions/Format-ForHtml.ps1: -------------------------------------------------------------------------------- 1 | 2 | filter Format-ForHtml 3 | { 4 | <# 5 | .SYNOPSIS 6 | Encodes text for HTML. 7 | #> 8 | if( $_ ) 9 | { 10 | [Web.HttpUtility]::HtmlEncode($_) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Tools/Silk/Functions/Get-Function.ps1: -------------------------------------------------------------------------------- 1 | 2 | filter Get-Function 3 | { 4 | <# 5 | .SYNOPSIS 6 | Gets all of a module's functions. 7 | #> 8 | param( 9 | [Parameter(Mandatory=$true,ValueFromPipeline=$true)] 10 | # The file to parse for functions 11 | $Path 12 | ) 13 | 14 | Write-Verbose "Loading script '$Path'." 15 | $scriptContent = Get-Content "$Path" 16 | if( -not $scriptContent ) 17 | { 18 | return @() 19 | } 20 | 21 | $errors = [Management.Automation.PSParseError[]] @() 22 | $tokens = [System.Management.Automation.PsParser]::Tokenize( $scriptContent, [ref] $errors ) 23 | if( $errors -ne $null -and $errors.Count -gt 0 ) 24 | { 25 | Write-Error "Found $($errors.count) error(s) parsing '$Path'." 26 | return 27 | } 28 | 29 | Write-Verbose "Found $($tokens.Count) tokens in '$Path'." 30 | 31 | for( $idx = 0; $idx -lt $tokens.Count; ++$idx ) 32 | { 33 | $token = $tokens[$idx] 34 | if( $token.Type -eq 'Keyword'-and ($token.Content -eq 'Function' -or $token.Content -eq 'Filter') ) 35 | { 36 | $atFunction = $true 37 | } 38 | 39 | if( $atFunction -and $token.Type -eq 'CommandArgument' -and $token.Content -ne '' ) 40 | { 41 | Write-Verbose "Found function '$($token.Content).'" 42 | $token.Content 43 | $atFunction = $false 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Tools/Silk/Functions/Get-ModuleVersion.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-ModuleVersion 3 | { 4 | param( 5 | [Parameter(Mandatory=$true)] 6 | [string] 7 | # The path to the module's manifest. 8 | $ManifestPath 9 | ) 10 | 11 | Set-StrictMode -Version 'Latest' 12 | 13 | } -------------------------------------------------------------------------------- /Tools/Silk/Functions/Out-HtmlString.ps1: -------------------------------------------------------------------------------- 1 | 2 | filter Out-HtmlString 3 | { 4 | <# 5 | .SYNOPSIS 6 | Writes a string out to the pipeline, trimming whitespace. 7 | #> 8 | $_ | 9 | Out-String -Width 9999 | 10 | ForEach-Object { $_.Trim() } | 11 | Where-Object { $_ } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Tools/Silk/Functions/Set-ModuleNuspec.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Set-ModuleNuspec 3 | { 4 | param( 5 | [Parameter(Mandatory=$true)] 6 | [string] 7 | # Path to the module's manifest. 8 | $ManifestPath, 9 | 10 | [Parameter(Mandatory=$true)] 11 | [string] 12 | # Path to the module's Nuspec file. 13 | $NuspecPath, 14 | 15 | [Parameter(Mandatory=$true)] 16 | [string] 17 | # Path to the releaes notes file. 18 | $ReleaseNotesPath, 19 | 20 | [string[]] 21 | # Tags to add to the manifest. Tags are space-delimited, so tags shouldn't have spaces. 22 | $Tags 23 | ) 24 | 25 | Set-StrictMode -Version 'Latest' 26 | 27 | $NuspecPath = Resolve-Path -Path $NuspecPath 28 | if( -not $NuspecPath ) 29 | { 30 | return 31 | } 32 | 33 | $nuspec = [xml](Get-Content -Path $NuspecPath -Raw) 34 | if( -not $nuspec ) 35 | { 36 | return 37 | } 38 | 39 | $manifest = Test-ModuleManifest -Path $ManifestPath 40 | if( -not $manifest ) 41 | { 42 | return 43 | } 44 | 45 | $releaseNotes = Get-ModuleReleaseNotes -ManifestPath $ManifestPath -ReleaseNotesPath $ReleaseNotesPath 46 | if( -not $releaseNotes ) 47 | { 48 | return 49 | } 50 | 51 | $nuspecMetadata = $nuspec.package.metadata 52 | 53 | $nuspecMetadata.description = $manifest.Description 54 | $nuspecMetadata.version = $manifest.Version.ToString() 55 | $nuspecMetadata.copyright = $manifest.Copyright 56 | $nuspecMetadata.releaseNotes = $releaseNotes 57 | if( $Tags ) 58 | { 59 | $nuspecMetadata.tags = $Tags -join ' ' 60 | } 61 | 62 | $nuspec.Save( $NuspecPath ) 63 | } -------------------------------------------------------------------------------- /Tools/Silk/Functions/Set-ReleaseNotesReleaseDate.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Set-ReleaseNotesReleaseDate 3 | { 4 | [CmdletBinding()] 5 | param( 6 | [Parameter(Mandatory=$true)] 7 | [string] 8 | # The path to the module manifest whose release notes to update. 9 | $ManifestPath, 10 | 11 | [Parameter(Mandatory=$true)] 12 | [string] 13 | # The path to the release notes file. 14 | $ReleaseNotesPath 15 | ) 16 | 17 | Set-StrictMode -Version 'Latest' 18 | 19 | $manifest = Test-ModuleManifest -Path $ManifestPath 20 | if( -not $manifest ) 21 | { 22 | return 23 | } 24 | 25 | $setHeader = $false 26 | $releaseNotes = Get-Content -Path $ReleaseNotesPath | 27 | ForEach-Object { 28 | if( $_ -match '^# {0}\s*$' -f [regex]::Escape($manifest.Version.ToString()) ) 29 | { 30 | $setHeader = $true 31 | return "# {0} ({1})" -f $manifest.Version,((Get-Date).ToString("d MMMM yyyy")) 32 | } 33 | return $_ 34 | } 35 | if( $setHeader ) 36 | { 37 | $releaseNotes | Set-Content -Path $releaseNotesPath 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tools/Silk/Import-Silk.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Imports the Silk module. 4 | 5 | .DESCRIPTION 6 | Imports the Silk module. If the Silk module is already loaded, it will remove it and then reloaded. 7 | 8 | .EXAMPLE 9 | Import-Silk.ps1 10 | 11 | Imports the Silk module, re-loading it if its already loaded. 12 | 13 | #> 14 | 15 | # Copyright 2012 Aaron Jensen 16 | # 17 | # Licensed under the Apache License, Version 2.0 (the "License"); 18 | # you may not use this file except in compliance with the License. 19 | # You may obtain a copy of the License at 20 | # 21 | # http://www.apache.org/licenses/LICENSE-2.0 22 | # 23 | # Unless required by applicable law or agreed to in writing, software 24 | # distributed under the License is distributed on an "AS IS" BASIS, 25 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | # See the License for the specific language governing permissions and 27 | # limitations under the License. 28 | 29 | [CmdletBinding()] 30 | param( 31 | ) 32 | 33 | Set-StrictMode -Version Latest 34 | $PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition 35 | 36 | if( (Get-Module Silk) ) 37 | { 38 | Remove-Module Silk 39 | } 40 | 41 | Import-Module (Join-Path $PSScriptRoot Silk.psd1 -Resolve) -ErrorAction Stop 42 | -------------------------------------------------------------------------------- /Tools/Silk/Silk.psm1: -------------------------------------------------------------------------------- 1 | # Copyright 2013 Aaron Jensen 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | Add-Type -Path (Join-Path $PSSCriptRoot bin\MarkdownSharp.dll) 16 | $markdown = New-Object MarkdownSharp.Markdown 17 | $markdown.AutoHyperlink = $true 18 | 19 | $loadedTypes = @{ } 20 | [AppDomain]::CurrentDomain.GetAssemblies() | 21 | ForEach-Object { $_.GetTypes() } | 22 | Where-Object { $_.IsPublic } | 23 | Sort-Object -Property 'Name' | 24 | ForEach-Object { 25 | if( $loadedTypes.ContainsKey( $_.Name ) ) 26 | { 27 | Write-Verbose ("Found multiple <{0}> types <{1}> <{2}>." -f $_.Name,$_.FullName,$loadedTypes[$_.Name]) 28 | } 29 | else 30 | { 31 | $loadedTypes[$_.Name] = $_.FullName 32 | } 33 | } 34 | 35 | $filesToSkip = @{ 36 | 'Import-Silk' = $true; 37 | } 38 | 39 | Get-Item (Join-Path -Path $PSScriptRoot -ChildPath 'Functions\*.ps1') | 40 | ForEach-Object { 41 | Write-Debug ("Importing function {0}." -f $_.FullName) 42 | . $_.FullName 43 | } 44 | -------------------------------------------------------------------------------- /Tools/Silk/bin/MarkdownSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/Silk/bin/MarkdownSharp.dll -------------------------------------------------------------------------------- /Tools/Silk/bin/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webmd-health-services/Carbon/ef0c1dd5c534934b54679ab1fd0aa8c8fc9b27e1/Tools/Silk/bin/NuGet.exe -------------------------------------------------------------------------------- /Tools/Silk/en-US/about_Silk.help.txt: -------------------------------------------------------------------------------- 1 | NAME 2 | Silk 3 | 4 | SYNOPSIS 5 | Silk is a PowerShell module for publishing a PowerShell module's help topics as a website. 6 | 7 | DESCRIPTION 8 | 9 | Introduction 10 | 11 | Silk publishes a PowerShell module's help topics as a website. It creates an html page for each function in the module. The module's main about topic (e.g. `about_Silk`) become's the site's index page. Additional about topics become additional navigation elements. 12 | 13 | Details of how Silk publishes the website can be controlled via a JSON manifest file. 14 | 15 | System Requirements 16 | 17 | PowerShell 3 18 | 19 | -------------------------------------------------------------------------------- /Tools/VERIFICATION.md: -------------------------------------------------------------------------------- 1 |  2 | # VERIFICATION 3 | 4 | This package contains several assemblies created and owned by the Carbon 5 | project itself: 6 | 7 | * Carbon.dll 8 | * Carbon.Iis.dll 9 | * Carbon.Xdt.dll 10 | 11 | These assemblies depend on and use these packages, which are downloaded from 12 | NuGet. 13 | 14 | * [DotNetZip/Ionic.Zip](https://www.nuget.org/packages/DotNetZip/) 15 | * [Microsoft.Web.Administration](https://www.nuget.org/packages/Microsoft.Web.Administration/) 16 | * [Microsoft.Web.Xdt](https://www.nuget.org/packages/Microsoft.Web.Xdt/) 17 | * [Microsoft.Win32.Registry](https://www.nuget.org/packages/Microsoft.Win32.Registry/) 18 | * [System.DirectoryServices.AccountManagement](https://www.nuget.org/packages/System.DirectoryServices.AccountManagement/) 19 | * [System.Runtime.InteropServices](https://www.nuget.org/packages/System.Runtime.InteropServices/) 20 | * [System.ServiceProcess.ServiceController](https://www.nuget.org/packages/System.ServiceProcess.ServiceController/) 21 | 22 | All other assemblies are included because they are dependencies required by one 23 | or more of the references above or required to run under different versions of 24 | .NET Core. 25 | -------------------------------------------------------------------------------- /Tools/chocolateyUninstall.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Chocolately install script for Carbon. 4 | #> 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | [CmdletBinding()] 17 | param( 18 | ) 19 | 20 | #Requires -Version 4 21 | Set-StrictMode -Version 'Latest' 22 | $ErrorActionPreference = 'Stop' 23 | 24 | # Use Get-Item so we can mock it 25 | Get-Item -Path 'env:PSModulePath' | 26 | Select-Object -ExpandProperty 'Value'-ErrorAction Ignore | 27 | ForEach-Object { $_ -split ';' } | 28 | Where-Object { $_ } | 29 | Join-Path -ChildPath 'Carbon' | 30 | Where-Object { Test-Path -Path $_ -PathType Container } | 31 | Rename-Item -NewName { 'Carbon{0}' -f [IO.Path]::GetRandomFileName() } -PassThru | 32 | Remove-Item -Recurse -Force 33 | -------------------------------------------------------------------------------- /Tools/xDSCResourceDesigner/xDSCResourceDesigner.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | # Version number of this module. 3 | ModuleVersion = '1.1' 4 | 5 | # ID used to uniquely identify this module 6 | GUID = '74951b31-1aa5-472b-9109-738de1bca38f' 7 | 8 | # Author of this module 9 | Author = 'Microsoft Corporation' 10 | 11 | # Company or vendor of this module 12 | CompanyName = 'Microsoft Corporation' 13 | 14 | # Copyright statement for this module 15 | Copyright = '(c) 2014 Microsoft Corporation. All rights reserved.' 16 | 17 | # Description of the functionality provided by this module 18 | Description = 'This module is meant to assist with the development and testing of DSC Resources.' 19 | 20 | # Minimum version of the Windows PowerShell engine required by this module 21 | PowerShellVersion = '4.0' 22 | 23 | # Minimum version of the common language runtime (CLR) required by this module 24 | CLRVersion = '4.0' 25 | 26 | # Script module or binary module file associated with this manifest. 27 | RootModule = 'xDSCResourceDesigner.psm1' 28 | 29 | # Functions to export from this module 30 | FunctionsToExport = @('New-xDscResourceProperty', 31 | 'New-xDscResource', 32 | 'Update-xDscResource', 33 | 'Test-xDscResource', 34 | 'Test-xDscSchema', 35 | 'Import-xDscSchema') 36 | 37 | # Cmdlets to export from this module 38 | CmdletsToExport = '*' 39 | } -------------------------------------------------------------------------------- /examples/Initialize-BuildServer.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Example build server setup script. 4 | 5 | .DESCRIPTION 6 | This sample script shows how to setup a simple build server running CruiseControl.NET as a Windows Service. 7 | #> 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | [CmdletBinding()] 20 | param( 21 | ) 22 | 23 | #Requires -Version 4 24 | Set-StrictMode -Version Latest 25 | 26 | & (Join-Path $PSScriptRoot ..\Import-Carbon.ps1 -Resolve) 27 | 28 | $ccservicePath = 'Path\to\ccservice.exe' 29 | $ccserviceUser = 'example.com\CCServiceUser' 30 | $ccservicePassword = 'CCServiceUserPassword' 31 | Install-Service -Name CCService -Path $ccservicePath -Username $ccserviceUser -Password $ccservicePassword 32 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "6.0.100", 4 | "rollForward": "latestFeature" 5 | } 6 | } 7 | --------------------------------------------------------------------------------