full_path
stringlengths 31
232
| filename
stringlengths 4
167
| content
stringlengths 0
48.3M
|
|---|---|---|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPSearchIndexPartition/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example adds an extra search partition to the local farms topology
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPSearchIndexPartition AdditionalPartition
{
Servers = @("Server2", "Server3")
Index = 1
RootDirectory = "I:\SearchIndexes\1"
ServiceAppName = "Search Service Application"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPUserProfileServiceAppPermissions/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example applies permissions for the user profile service application to limit
access to specific features.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPUserProfileServiceAppPermissions UPAPermissions
{
ProxyName = "User Profile Service Application Proxy"
CreatePersonalSite = @("DEMO\Group", "DEMO\User1")
FollowAndEditProfile = @("Everyone")
UseTagsAndNotes = @("None")
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPAppManagementServiceApp/1-CreateServiceApp.ps1
|
1-CreateServiceApp.ps1
|
<#
.EXAMPLE
This example shows how to create a new app management service application in the
local SharePoint farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPAppManagementServiceApp AppManagementServiceApp
{
Name = "App Management Service Application"
ApplicationPool = "SharePoint Service Applications"
DatabaseServer = "SQL01.contoso.com"
DatabaseName = "SP_AppManagement"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPAppManagementServiceApp/2-RemoveServiceApp.ps1
|
2-RemoveServiceApp.ps1
|
<#
.EXAMPLE
This example shows how to remove a specific app management service application in the
local SharePoint farm. The application pool property is still mandatory but it is not
used so therefore the value is not important.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPAppManagementServiceApp AppManagementServiceApp
{
Name = "App Management Service Application"
ApplicationPool = "n/a"
Ensure = "Absent"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPHealthAnalyzerRuleState/1-DisableHealthRule.ps1
|
1-DisableHealthRule.ps1
|
<#
.EXAMPLE
This example shows how to disable a health analyzer rule
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPHealthAnalyzerRuleState DisableDiskSpaceRule
{
Name = "Drives are at risk of running out of free space."
Enabled = $false
RuleScope = "All Servers"
Schedule = "Daily"
FixAutomatically = $false
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPJoinFarm/1-JoinFarm.ps1
|
1-JoinFarm.ps1
|
<#
.EXAMPLE
This example shows how to join an existing SharePoint farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount,
[Parameter(Mandatory = $true)]
[PSCredential]
$Passphrase
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPJoinFarm JoinFarm
{
DatabaseServer = "SQL.contoso.local\SQLINSTANCE"
FarmConfigDatabaseName = "SP_Config"
Passphrase = $Passphrase
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPJoinFarm/1-JoinFarmWithRole.ps1
|
1-JoinFarmWithRole.ps1
|
<#
.EXAMPLE
This example shows how to join an existing SharePoint farm using a specific
server role (applies to SharePoint 2016 only).
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount,
[Parameter(Mandatory = $true)]
[PSCredential]
$Passphrase
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPJoinFarm JoinFarm
{
DatabaseServer = "SQL.contoso.local\SQLINSTANCE"
FarmConfigDatabaseName = "SP_Config"
ServerRole = "WebFrontEnd"
Passphrase = $Passphrase
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPSearchCrawlMapping/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example shows how to apply a Search Crawl Mapping rule to a search application.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPSearchCrawlMapping IntranetCrawlMapping
{
ServiceAppName = "Search Service Application"
Url = "http://crawl.sharepoint.com"
Target = "http://site.sharepoint.com"
Ensure = "Present"
PsDScRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPSubscriptionSettingsServiceApp/1-NewServiceApp.ps1
|
1-NewServiceApp.ps1
|
<#
.EXAMPLE
This example creates a new subscription settings service app in the local farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPSubscriptionSettingsServiceApp SubscriptionSettingsServiceApp
{
Name = "Subscription Settings Service Application"
ApplicationPool = "SharePoint web services"
DatabaseServer = "SQL01.contoso.com"
DatabaseName = "SP_SubscriptionSettings"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPSubscriptionSettingsServiceApp/2-RemoveServiceApp.ps1
|
2-RemoveServiceApp.ps1
|
<#
.EXAMPLE
This example removes a subscription settings service app in the local farm.
The ApplicationPool property is required, but is ignored when removing a
service app.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPSubscriptionSettingsServiceApp SubscriptionSettingsServiceApp
{
Name = "Subscription Settings Service Application"
ApplicationPool = "n/a"
PsDscRunAsCredential = $SetupAccount
Ensure = "Absent"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWebAppThrottlingSettings/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example shows how to apply throttling settings to a specific web app
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPWebAppThrottlingSettings PrimaryWebAppThrottlingSettings
{
Url = "http://exmaple.contoso.local"
ListViewThreshold = 5000
AllowObjectModelOverride = $false
HappyHourEnabled = $true
HappyHour = MSFT_SPWebApplicationHappyHour {
Hour = 3
Minute = 0
Duration = 1
}
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPDatabaseAAG/1-AddDBtoAAG.ps1
|
1-AddDBtoAAG.ps1
|
<#
.EXAMPLE
This example takes an existing SharePoint database and puts it in to the specified
AlwaysOn Availability Group (AAG).
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPDatabaseAAG ConfigDBAAG
{
DatabaseName = "SP_Config"
AGName = "MyAvailabilityGroup"
FileShare = "\\SQL\Backups"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPDatabaseAAG/3-RemoveDBfromAAG.ps1
|
3-RemoveDBfromAAG.ps1
|
<#
.EXAMPLE
This example removes a database from the specified AlwaysOn Availability Group (AAG)
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPDatabaseAAG ConfigDBAAG
{
DatabaseName = "SP_Config"
AGName = "MyAvailabilityGroup"
Ensure = "Absent"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPDatabaseAAG/2-AddMultipleDBstoAAG.ps1
|
2-AddMultipleDBstoAAG.ps1
|
<#
.EXAMPLE
This example takes existing SharePoint databases, based on the database name pattern, and puts
them in to the specified AlwaysOn Availability Group (AAG).
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPDatabaseAAG ConfigDBAAG
{
DatabaseName = "*Content*"
AGName = "MyAvailabilityGroup"
FileShare = "\\SQL\Backups"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPTrustedIdentityTokenIssuer/1-SigningCertInFileCertificateStore.ps1
|
1-SigningCertInFileCertificateStore.ps1
|
<#
.EXAMPLE
This example deploys a trusted token issuer to the local farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPTrustedIdentityTokenIssuer SampleSPTrust
{
Name = "Contoso"
Description = "Contoso"
Realm = "https://sharepoint.contoso.com"
SignInUrl = "https://adfs.contoso.com/adfs/ls/"
IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
ClaimsMappings = @(
MSFT_SPClaimTypeMapping{
Name = "Email"
IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
}
MSFT_SPClaimTypeMapping{
Name = "Role"
IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType"
LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
}
)
SigningCertificateThumbPrint = "F0D3D9D8E38C1D55A3CEF3AAD1C18AD6A90D5628"
ClaimProviderName = "LDAPCP"
ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/"
Ensure = "Present"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPTrustedIdentityTokenIssuer/2-SigningCertInFilePath.ps1
|
2-SigningCertInFilePath.ps1
|
<#
.EXAMPLE
This example deploys a trusted token issuer to the local farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPTrustedIdentityTokenIssuer SampleSPTrust
{
Name = "Contoso"
Description = "Contoso"
Realm = "https://sharepoint.contoso.com"
SignInUrl = "https://adfs.contoso.com/adfs/ls/"
IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
ClaimsMappings = @(
MSFT_SPClaimTypeMapping{
Name = "Email"
IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
}
MSFT_SPClaimTypeMapping{
Name = "Role"
IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType"
LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
}
)
SigningCertificateFilePath = "F:\Data\DSC\FakeSigning.cer"
ClaimProviderName = "LDAPCP"
ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/"
Ensure = "Present"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPInstallLanguagePack/2-InstallLanguagePackInWindow.ps1
|
2-InstallLanguagePackInWindow.ps1
|
<#
.EXAMPLE
This module will install the SharePoint Language Pack in the specified timeframe.
The binaries for SharePoint in this scenario are stored at C:\SPInstall (so it
will look to run C:\SPInstall\Setup.exe)
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPInstallLanguagePack InstallLPBinaries
{
BinaryDir = "C:\SPInstall"
BinaryInstallDays = "sat", "sun"
BinaryInstallTime = "12:00am to 2:00am"
Ensure = "Present"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPInstallLanguagePack/1-InstallLanguagePack.ps1
|
1-InstallLanguagePack.ps1
|
<#
.EXAMPLE
This module will install the SharePoint Language Pack. The binaries for
SharePoint in this scenario are stored at C:\SPInstall (so it will look to run
C:\SPInstall\Setup.exe)
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPInstallLanguagePack InstallLPBinaries
{
BinaryDir = "C:\SPInstall"
Ensure = "Present"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWebAppSiteUseAndDeletion/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example shows how to apply site use and deletion settings to the specified web applicaiton
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPWebAppSiteUseAndDeletion ConfigureSiteUseAndDeletion
{
Url = "http://example.contoso.local"
SendUnusedSiteCollectionNotifications = $true
UnusedSiteNotificationPeriod = 90
AutomaticallyDeleteUnusedSiteCollections = $true
UnusedSiteNotificationsBeforeDeletion = 24
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPAppCatalog/1-SetSiteAsAppCatalog.ps1
|
1-SetSiteAsAppCatalog.ps1
|
<#
.EXAMPLE
This example shows how to configure the AppCatalog in the farm
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPAppCatalog MainAppCatalog
{
SiteUrl = "https://content.sharepoint.contoso.com/sites/AppCatalog"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPProductUpdate/2-InstallSP.ps1
|
2-InstallSP.ps1
|
<#
.EXAMPLE
This example installs the SharePoint 2013 Service Pack only in the specified window.
It also shuts down services to speed up the installation process.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPProductUpdate InstallCUMay2016
{
SetupFile = "C:\Install\SP2013SP1\officeserversp2013-kb2880552-fullfile-x64-en-us.exe"
ShutdownServices = $true
BinaryInstallDays = "sat", "sun"
BinaryInstallTime = "12:00am to 2:00am"
Ensure = "Present"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPProductUpdate/3-InstallLPSP.ps1
|
3-InstallLPSP.ps1
|
<#
.EXAMPLE
This example installs the SharePoint 2013 Dutch Language Pack Service Pack only in the specified window.
It also shuts down services to speed up the installation process.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPProductUpdate InstallCUMay2016
{
SetupFile = "C:\Install\SP2013-LP_NL-SP1\serverlpksp2013-kb2880554-fullfile-x64-nl-nl.exe"
ShutdownServices = $true
BinaryInstallDays = "sat", "sun"
BinaryInstallTime = "12:00am to 2:00am"
Ensure = "Present"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPProductUpdate/1-InstallCU.ps1
|
1-InstallCU.ps1
|
<#
.EXAMPLE
This example installs the Cumulative Update only in the specified window.
It also shuts down services to speed up the installation process.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPProductUpdate InstallCUMay2016
{
SetupFile = "C:\Install\CUMay2016\ubersrv2013-kb3115029-fullfile-x64-glb.exe"
ShutdownServices = $true
BinaryInstallDays = "sat", "sun"
BinaryInstallTime = "12:00am to 2:00am"
Ensure = "Present"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWebAppPermissions/1-LimitPermissions.ps1
|
1-LimitPermissions.ps1
|
<#
.EXAMPLE
This example shows how to limit the available permisions within a web app
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPWebAppPermissions WebApplicationPermissions
{
WebAppUrl = "https://intranet.sharepoint.contoso.com"
ListPermissions = "Manage Lists","Override List Behaviors","Add Items","Edit Items","Delete Items","View Items","Approve Items","Open Items","View Versions","Delete Versions","Create Alerts","View Application Pages"
SitePermissions = "Manage Permissions","View Web Analytics Data","Create Subsites","Manage Web Site","Add and Customize Pages","Apply Themes and Borders","Apply Style Sheets","Create Groups","Browse Directories","Use Self-Service Site Creation","View Pages","Enumerate Permissions","Browse User Information","Manage Alerts","Use Remote Interfaces","Use Client Integration Features","Open","Edit Personal User Information"
PersonalPermissions = "Manage Personal Views","Add/Remove Personal Web Parts","Update Personal Web Parts"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWebAppPermissions/2-AllPermissions.ps1
|
2-AllPermissions.ps1
|
<#
.EXAMPLE
This example shows how to ensure all permissions are available for a web app
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPWebAppPermissions WebApplicationPermissions
{
WebAppUrl = "https://portal.sharepoint.contoso.com"
AllPermissions = $true
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPVisioServiceApp/1-NewServiceApp.ps1
|
1-NewServiceApp.ps1
|
<#
.EXAMPLE
This example shows how to create a new visio services service app in the local farm
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPVisioServiceApp VisioServices
{
Name = "Visio Graphics Service Application"
ApplicationPool = "SharePoint Web Services"
InstallAccount = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPVisioServiceApp/2-RemoveServiceApp.ps1
|
2-RemoveServiceApp.ps1
|
<#
.EXAMPLE
This example shows how to remove a visio services service app in the local farm.
The ApplicationPool property is still requried but is not used when removing, so
the value used here doesn't matter.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPVisioServiceApp VisioServices
{
Name = "Visio Graphics Service Application"
ApplicationPool = "n/a"
Ensure = "Absent"
InstallAccount = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWebApplication/2-ClaimsExample.ps1
|
2-ClaimsExample.ps1
|
<#
.EXAMPLE
This example shows how to create a new web application in the local farm using a custom claim provider.
A SPTrustedIdentityTokenIssuer is created named Contoso, then this SPTrustedIdentityTokenIssuer is referenced
by the SPWebApplication as the AuthenticationProvider and the AuthenticationMethod is set to "Claims" value.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPTrustedIdentityTokenIssuer SampleSPTrust
{
Name = "Contoso"
Description = "Contoso"
Realm = "https://sharepoint.contoso.com"
SignInUrl = "https://adfs.contoso.com/adfs/ls/"
IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
ClaimsMappings = @(
MSFT_SPClaimTypeMapping{
Name = "Email"
IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
}
MSFT_SPClaimTypeMapping{
Name = "Role"
IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType"
LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
}
)
SigningCertificateThumbPrint = "F3229E7CCA1DA812E29284B0ED75A9A019A83B08"
ClaimProviderName = "LDAPCP"
ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/"
Ensure = "Present"
PsDscRunAsCredential = $SetupAccount
}
SPWebApplication HostNameSiteCollectionWebApp
{
Name = "SharePoint Sites"
ApplicationPool = "SharePoint Sites"
ApplicationPoolAccount = "CONTOSO\svcSPWebApp"
AllowAnonymous = $false
AuthenticationMethod = "Claims"
AuthenticationProvider = "Contoso"
DatabaseName = "SP_Content_01"
DatabaseServer = "SQL.contoso.local\SQLINSTANCE"
Url = "http://example.contoso.local"
Port = 80
Ensure = "Present"
PsDscRunAsCredential = $SetupAccount
DependsOn = "[SPTrustedIdentityTokenIssuer]SampleSPTrust"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWebApplication/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example shows how to create a new web application in the local farm
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPWebApplication HostNameSiteCollectionWebApp
{
Name = "SharePoint Sites"
ApplicationPool = "SharePoint Sites"
ApplicationPoolAccount = "CONTOSO\svcSPWebApp"
AllowAnonymous = $false
AuthenticationMethod = "NTLM"
DatabaseName = "SP_Content_01"
DatabaseServer = "SQL.contoso.local\SQLINSTANCE"
Url = "http://example.contoso.local"
Port = 80
Ensure = "Present"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPUserProfileSyncConnection/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example adds a new user profile sync connection to the specified user
profile service app
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount,
[Parameter(Mandatory = $true)]
[PSCredential]
$ConnectionAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPUserProfileSyncConnection MainDomain
{
UserProfileService = "User Profile Service Application"
Forest = "contoso.com"
Name = "Contoso"
ConnectionCredentials = $ConnectionAccount
Server = "server.contoso.com"
UseSSL = $false
IncludedOUs = @("OU=SharePoint Users,DC=Contoso,DC=com")
ExcludedOUs = @("OU=Notes Usersa,DC=Contoso,DC=com")
Force = $false
ConnectionType = "ActiveDirectory"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPShellAdmins/2-SpecificDBs.ps1
|
2-SpecificDBs.ps1
|
<#
.EXAMPLE
This example gives admin access to the specified users for the local farm as well as
all content databases in the local farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPShellAdmins ShellAdmins
{
Name = "Shell Admins"
Members = "CONTOSO\user1", "CONTOSO\user2"
ContentDatabases = @(
@(MSFT_SPContentDatabasePermissions {
Name = "SharePoint_Content_1"
Members = "CONTOSO\user2", "CONTOSO\user3"
})
@(MSFT_SPContentDatabasePermissions {
Name = "SharePoint_Content_2"
Members = "CONTOSO\user3", "CONTOSO\user4"
})
)
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPShellAdmins/1-FarmAdmins.ps1
|
1-FarmAdmins.ps1
|
<#
.EXAMPLE
This example gives admin access to the specified users for the local farm as well as
all content databases in the local farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPShellAdmins ShellAdmins
{
Name = "Shell Admins"
Members = "CONTOSO\user1", "CONTOSO\user2"
AllContentDatabases = $true
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPBlobCacheSettings/1-ApplyBlobCacheConfig.ps1
|
1-ApplyBlobCacheConfig.ps1
|
<#
.EXAMPLE
This example shows how to configure the blob cache settings on the local server for the
specified web application and zone
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPBlobCacheSettings BlobCacheSettings
{
WebAppUrl = "http://intranet.contoso.com"
Zone = "Default"
EnableCache = $true
Location = "F:\BlobCache"
MaxSizeInGB = 10
FileTypes = "\.(gif|jpg|png|css|js)$"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPFarmAdministrators/2-SetIncludeExcludeAdmins.ps1
|
2-SetIncludeExcludeAdmins.ps1
|
<#
.EXAMPLE
This example shows how certain changes are made to the farm admins groups. Here any
members in the MembersToInclude property are added, and members in the MembersToExclude
property are removed. Any members that exist in the farm admins group that aren't listed
in either of these properties are left alone.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPFarmAdministrators LocalFarmAdmins
{
Name = "Farm Administrators"
MembersToInclude = @("CONTOSO\user1")
MembersToExclude = @("CONTOSO\user2")
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPFarmAdministrators/1-SetSpecificAdmins.ps1
|
1-SetSpecificAdmins.ps1
|
<#
.EXAMPLE
This example shows how to set a specific list of members for the farm admins group.
Any members not in this list will be removed.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPFarmAdministrators LocalFarmAdmins
{
Name = "Farm Administrators"
Members = @("CONTOSO\user1", "CONTOSO\user2")
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPManagedMetaDataServiceApp/3-SetTermStoreAdmins.ps1
|
3-SetTermStoreAdmins.ps1
|
<#
.EXAMPLE
This example shows how to deploy the Managed Metadata service app to the local SharePoint farm
and also include a specific list of users to be the term store administrators.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPManagedMetaDataServiceApp ManagedMetadataServiceApp
{
Name = "Managed Metadata Service Application"
InstallAccount = $SetupAccount
ApplicationPool = "SharePoint Service Applications"
DatabaseServer = "SQL.contoso.local"
DatabaseName = "SP_ManagedMetadata"
TermStoreAdministrators = @(
"CONTOSO\user1",
"CONTOSO\user2"
)
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPManagedMetaDataServiceApp/1-CreateServiceApp.ps1
|
1-CreateServiceApp.ps1
|
<#
.EXAMPLE
This example shows how to deploy the Managed Metadata service app to the local SharePoint farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPManagedMetaDataServiceApp ManagedMetadataServiceApp
{
Name = "Managed Metadata Service Application"
InstallAccount = $SetupAccount
ApplicationPool = "SharePoint Service Applications"
DatabaseServer = "SQL.contoso.local"
DatabaseName = "SP_ManagedMetadata"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPManagedMetaDataServiceApp/2-RemoveServiceApp.ps1
|
2-RemoveServiceApp.ps1
|
<#
.EXAMPLE
This example shows how to remove a specific managed metadata service app from the
local SharePoint farm. Because Application pool parameter is required
but is not acutally needed to remove the app, any text value can
be supplied for these as it will be ignored.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPManagedMetaDataServiceApp ManagedMetadataServiceApp
{
Name = "Managed Metadata Service Application"
InstallAccount = $SetupAccount
ApplicationPool = "none"
Ensure = "Absent"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPOutgoingEmailSettings/2-WebApp.ps1
|
2-WebApp.ps1
|
<#
.EXAMPLE
This example shows to set outgoing email settings for a specific web app
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPOutgoingEmailSettings FarmWideEmailSettings
{
WebAppUrl = "http://site.contoso.com"
SMTPServer = "smtp.contoso.com"
FromAddress = "sharepoint`@contoso.com"
ReplyToAddress = "noreply`@contoso.com"
CharacterSet = "65001"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPOutgoingEmailSettings/1-WholeFarm.ps1
|
1-WholeFarm.ps1
|
<#
.EXAMPLE
This example shows to set outgoing email settings for the entire farm. Use the URL
of the central admin site for the web app URL to apply for the entire farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPOutgoingEmailSettings FarmWideEmailSettings
{
WebAppUrl = "http://sharepoint1:2013"
SMTPServer = "smtp.contoso.com"
FromAddress = "sharepoint`@contoso.com"
ReplyToAddress = "noreply`@contoso.com"
CharacterSet = "65001"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWebAppWorkflowSettings/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example shows how to apply workflow settings to the specific web application
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPWebAppWorkflowSettings PrimaryWebAppWorkflowSettings
{
Url = "Shttp://exmaple.contoso.local"
ExternalWorkflowParticipantsEnabled = $false
EmailToNoPermissionWorkflowParticipantsEnable = $false
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPUserProfileServiceApp/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example adds a new user profile service application to the local farm
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount,
[Parameter(Mandatory = $true)]
[PSCredential]
$FarmAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPUserProfileServiceApp UserProfileServiceApp
{
Name = "User Profile Service Application"
ApplicationPool = "SharePoint Service Applications"
MySiteHostLocation = "http://my.sharepoint.contoso.local"
ProfileDBName = "SP_UserProfiles"
ProfileDBServer = "SQL.contoso.local\SQLINSTANCE"
SocialDBName = "SP_Social"
SocialDBServer = "SQL.contoso.local\SQLINSTANCE"
SyncDBName = "SP_ProfileSync"
SyncDBServer = "SQL.contoso.local\SQLINSTANCE"
EnableNetBIOS = $false
FarmAccount = $FarmAccount
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWordAutomationServiceApp/1-NewServiceApp.ps1
|
1-NewServiceApp.ps1
|
<#
.EXAMPLE
This example makes sure the service application exists and has a specific configuration
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPWordAutomationServiceApp WordAutomation
{
Name = "Word Automation Service Application"
Ensure = "Present"
ApplicationPool = "SharePoint Web Services"
DatabaseName = "WordAutomation_DB"
DatabaseServer = "SQLServer"
SupportedFileFormats = "docx", "doc", "mht", "rtf", "xml"
DisableEmbeddedFonts = $false
MaximumMemoryUsage = 100
RecycleThreshold = 100
DisableBinaryFileScan = $false
ConversionProcesses = 8
JobConversionFrequency = 15
NumberOfConversionsPerProcess = 12
TimeBeforeConversionIsMonitored = 5
MaximumConversionAttempts = 2
MaximumSyncConversionRequests = 25
KeepAliveTimeout = 30
MaximumConversionTime = 300
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPWordAutomationServiceApp/2-RemoveServiceApp.ps1
|
2-RemoveServiceApp.ps1
|
<#
.EXAMPLE
This example removes a word automation service app
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPWordAutomationServiceApp WordAutomation
{
Name = "Word Automation Service Application"
Ensure = "Absent"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPAppDomain/1-SetAppDomainDetails.ps1
|
1-SetAppDomainDetails.ps1
|
<#
.EXAMPLE
This example shows how to apply app URLs to the current farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPAppDomain LocalFarmAppUrls
{
AppDomain = "contosointranetapps.com"
Prefix = "app"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPInstall/1-InstallToDefaultPath.ps1
|
1-InstallToDefaultPath.ps1
|
<#
.EXAMPLE
This module will install SharePoint to the default locations. The binaries for
SharePoint in this scenario are stored at C:\SPInstall (so it will look to run
C:\SPInstall\Setup.exe)
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPInstall InstallBinaries
{
BinaryDir = "C:\SPInstall"
ProductKey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPInstall/3-InstallSPFoundation.ps1
|
3-InstallSPFoundation.ps1
|
<#
.EXAMPLE
This module will install SharePoint Foundation 2013 to the local server
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName PSDesiredStateConfiguration
node localhost {
Package InstallSharePointFoundation
{
Ensure = "Present"
Name = "Microsoft SharePoint Foundation 2013 Core"
Path = "E:\SharePoint2013\Setup.exe"
Arguments = "/config E:\SharePoint2013\files\setupfarmsilent\config.xml"
ProductID = "90150000-1014-0000-1000-0000000FF1CE"
ReturnCode = 0
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPInstall/2-InstallToCustomPath.ps1
|
2-InstallToCustomPath.ps1
|
<#
.EXAMPLE
This module will install SharePoint to the specific locations set for the
InstallPath and DataPath directories.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPInstall InstallBinaries
{
BinaryDir = "D:\SharePoint\Binaries"
InstallPath = "D:\SharePoint\Install"
DataPath = "D:\SharePoint\Data"
ProductKey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPInstallPrereqs/2-OfflineInstall.ps1
|
2-OfflineInstall.ps1
|
<#
.EXAMPLE
This module will install the prerequisites for SharePoint 2013. This resource will run in
offline mode, running all prerequisite installations from the specified paths.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPInstallPrereqs InstallPrerequisites
{
InstallerPath = "C:\SPInstall\Prerequisiteinstaller.exe"
OnlineMode = $false
SXSpath = "c:\SPInstall\Windows2012r2-SXS"
SQLNCli = "C:\SPInstall\prerequisiteinstallerfiles\sqlncli.msi"
PowerShell = "C:\SPInstall\prerequisiteinstallerfiles\Windows6.1-KB2506143-x64.msu"
NETFX = "C:\SPInstall\prerequisiteinstallerfiles\dotNetFx45_Full_setup.exe"
IDFX = "C:\SPInstall\prerequisiteinstallerfiles\Windows6.1-KB974405-x64.msu"
Sync = "C:\SPInstall\prerequisiteinstallerfiles\Synchronization.msi"
AppFabric = "C:\SPInstall\prerequisiteinstallerfiles\WindowsServerAppFabricSetup_x64.exe"
IDFX11 = "C:\SPInstall\prerequisiteinstallerfiles\MicrosoftIdentityExtensions-64.msi"
MSIPCClient = "C:\SPInstall\prerequisiteinstallerfiles\setup_msipc_x64.msi"
WCFDataServices = "C:\SPInstall\prerequisiteinstallerfiles\WcfDataServices.exe"
KB2671763 = "C:\SPInstall\prerequisiteinstallerfiles\AppFabric1.1-RTM-KB2671763-x64-ENU.exe"
WCFDataServices56 = "C:\SPInstall\prerequisiteinstallerfiles\WcfDataServices56.exe"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPInstallPrereqs/1-OnlineInstall.ps1
|
1-OnlineInstall.ps1
|
<#
.EXAMPLE
This module will install the prerequisites for SharePoint. This resource will run in
online mode, looking to download all prerequisites from the internet.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPInstallPrereqs InstallPrerequisites
{
InstallerPath = "C:\SPInstall\Prerequisiteinstaller.exe"
OnlineMode = $true
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPSearchServiceApp/1-NewServiceApp.ps1
|
1-NewServiceApp.ps1
|
<#
.EXAMPLE
This example creates a new search service app in the local farm
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPSearchServiceApp SearchServiceApp
{
Name = "Search Service Application"
DatabaseName = "SP_Search"
ApplicationPool = "SharePoint Service Applications"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPSearchServiceApp/2-RemoveServiceApp.ps1
|
2-RemoveServiceApp.ps1
|
<#
.EXAMPLE
This example removes a search service app in the local farm. The ApplicationPool
parameter is still required but is not actually used, so its value does not matter.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPSearchServiceApp SearchServiceApp
{
Name = "Search Service Application"
Ensure = "Absent"
ApplicationPool = "n/a"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPServiceAppProxyGroup/1-ProxyGroups.ps1
|
1-ProxyGroups.ps1
|
<#
.EXAMPLE
This example creates two seperate proxy groups of service apps that can be
assigned to web apps in the farm
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPServiceAppProxyGroup ProxyGroup1
{
Name = "Proxy Group 1"
Ensure = "Present"
ServiceAppProxies = "Web 1 User Profile Service Application","Web 1 MMS Service Application","State Service Application"
}
SPServiceAppProxyGroup ProxyGroup2
{
Name = "Proxy Group 2"
Ensure = "Present"
ServiceAppProxiesToInclude = "Web 2 User Profile Service Application"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPSecureStoreServiceApp/1-NewServiceApp.ps1
|
1-NewServiceApp.ps1
|
<#
.EXAMPLE
This example creates a new secure store service app.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPSecureStoreServiceApp SecureStoreServiceApp
{
Name = "Secure Store Service Application"
ApplicationPool = "SharePoint Service Applications"
AuditingEnabled = $true
AuditlogMaxSize = 30
DatabaseName = "SP_SecureStore"
InstallAccount = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPSecureStoreServiceApp/2-RemoveServiceApp.ps1
|
2-RemoveServiceApp.ps1
|
<#
.EXAMPLE
This example removes a secure store service app. The ApplicationPool and
AuditingEnabled parameters are required, but are not used so their values
are able to be set to anything.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPSecureStoreServiceApp SecureStoreServiceApp
{
Name = "Secure Store Service Application"
ApplicationPool = "n/a"
AuditingEnabled = $false
InstallAccount = $SetupAccount
Ensure = "Absent"
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPTimerJobState/1-Example.ps1
|
1-Example.ps1
|
<#
.EXAMPLE
This example show how to disable the dead site delete job in the local farm.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPTimerJobState DisableTimerJob_DeadSiteDelete
{
Name = "job-dead-site-delete"
WebApplication = "http://sites.sharepoint.contoso.com"
Enabled = $false
Schedule ="weekly at sat 5:00"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPAntivirusSettings/1-SetAntivirusConfig.ps1
|
1-SetAntivirusConfig.ps1
|
<#
.EXAMPLE
This example shows how to apply specific anti-virus configuration to the farm
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPAntivirusSettings AVSettings
{
ScanOnDownload = $true
ScanOnUpload = $true
AllowDownloadInfected = $false
AttemptToClean = $false
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPDiagnosticLoggingSettings/1-ApplyLoggingSettings.ps1
|
1-ApplyLoggingSettings.ps1
|
<#
.EXAMPLE
This example applies the specified diagnostic logging settings to the local
SharPoint farm. Any setting not defined will be left as it default, or to
whatever value has been manually configured outside of DSC.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPDiagnosticLoggingSettings ApplyDiagnosticLogSettings
{
PsDscRunAsCredential = $SetupAccount
LogPath = "L:\ULSLogs"
LogSpaceInGB = 10
AppAnalyticsAutomaticUploadEnabled = $false
CustomerExperienceImprovementProgramEnabled = $true
DaysToKeepLogs = 7
DownloadErrorReportingUpdatesEnabled = $false
ErrorReportingAutomaticUploadEnabled = $false
ErrorReportingEnabled = $false
EventLogFloodProtectionEnabled = $true
EventLogFloodProtectionNotifyInterval = 5
EventLogFloodProtectionQuietPeriod = 2
EventLogFloodProtectionThreshold = 5
EventLogFloodProtectionTriggerPeriod = 2
LogCutInterval = 15
LogMaxDiskSpaceUsageEnabled = $true
ScriptErrorReportingDelay = 30
ScriptErrorReportingEnabled = $true
ScriptErrorReportingRequireAuth = $true
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPCacheAccounts/1-SetCacheAccounts.ps1
|
1-SetCacheAccounts.ps1
|
<#
.EXAMPLE
This example sets the super use and reader accounts for the specified web app. It will
also set the appropriate web app policies by default for these accounts.
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPCacheAccounts SetCacheAccounts
{
WebAppUrl = "http://sharepoint.contoso.com"
SuperUserAlias = "DEMO\svcSPSuperUser"
SuperReaderAlias = "DEMO\svcSPReader"
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/SharePointDSC/1.7.0.0/Examples/Resources/SPCacheAccounts/2-SetCacheAccountsNoPolicy.ps1
|
2-SetCacheAccountsNoPolicy.ps1
|
<#
.EXAMPLE
This example sets the super use and reader accounts for the specified web app. It will
not set the web app policies for these accounts though, allowing them to be controlled
elsewhere (either manually or with SPWebAppPolicy)
#>
Configuration Example
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]
$SetupAccount
)
Import-DscResource -ModuleName SharePointDsc
node localhost {
SPCacheAccounts SetCacheAccounts
{
WebAppUrl = "http://sharepoint.contoso.com"
SuperUserAlias = "DEMO\svcSPSuperUser"
SuperReaderAlias = "DEMO\svcSPReader"
SetWebAppPolicy = $false
PsDscRunAsCredential = $SetupAccount
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/0-CommonInit.ps1
|
0-CommonInit.ps1
|
$MyPath = Split-Path $MyInvocation.MyCommand.Path
$DemoRoot = 'D:\Nana\Test'
$OutputPath = "$DemoRoot\CompiledConfigurations"
$TraceFolder = "$DemoRoot\Traces"
$AzureDemoNode = 'Nana-AADemo-10'
Import-Module -Force "$MyPath\HelperMethods.psm1"
$DomainController = 'Nana-XM-DC'
$DNSServer = '92.168.1.100'
$TestNode = 'Nana-XM-Node'
$PCTestNode = 'Nana-PC-Node'
if ($null -eq $Credential)
{
$Credential = Get-Credential administrator
}
#endregion Initialization
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/ConfigData.AddToDomain.ps1
|
ConfigData.AddToDomain.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
if ($Credential -eq $null)
{
$Credential = Get-Credential Administrator -Message 'Enter domain admin credential'
}
@{
AllNodes = @(
@{
NodeName = 'Nana-XM-Node'
Role = 'Node'
DomainName = 'NanaTestDomain'
DomainAdminCredential = (new-object System.Management.Automation.PSCredential 'NanaTestDomain\Administrator', $Credential.Password)
DomainUser = 'NanaTestDomain\Nana'
DomainController = $DomainController
DNSServer = $DNSServer
# allow plain text passwords in a mof file is a security hole
# it is being used here purely for the demo
# Do not use this in any script in your environment
PSDscAllowPlainTextPassword = $true
}
)
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/Configuration.DomainSetup.ps1
|
Configuration.DomainSetup.ps1
|
configuration DomainSetup
{
Import-DscResource -ModuleName PSDesiredStateConfiguration, xActiveDirectory
node $AllNodes.Where{$_.Role -eq 'DomainController'}.Nodename
{
WindowsFeature ADDSInstall
{
Ensure = 'Present'
Name = 'AD-Domain-Services'
}
xADDomain DC
{
DomainName = $Node.DomainName
DomainAdministratorCredential = $Node.DomainAdminCredential
SafemodeAdministratorPassword = $Node.SafeModeAdminCredential
DependsOn = '[WindowsFeature]ADDSInstall'
}
xWaitForADDomain WaitForDC
{
DomainName = $Node.DomainName
DomainUserCredential = $Node.DomainAdminCredential
RetryCount = 10
RetryIntervalSec = 100
DependsOn = '[xADDomain]DC'
}
xADUser FirstUser
{
DomainName = $Node.DomainName
DomainAdministratorCredential = $Node.DomainAdminCredential
UserName = $Node.AnotherAdminCredential.UserName
Password = $Node.AnotherAdminCredential
Ensure = 'Present'
DependsOn = '[xWaitForADDomain]WaitForDC'
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/HalfConfig.ps1
|
HalfConfig.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\Assert-DomainSetup.ps1"
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/MetaConfig.DomainSetup.ps1
|
MetaConfig.DomainSetup.ps1
|
[DscLocalConfigurationManager()]
configuration DCMetaConfig
{
node $AllNodes.Where{$_.Role -eq 'DomainController'}.Nodename
{
Settings
{
ActionAfterReboot = 'StopConfiguration'
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/Invoke-AddToDomain.ps1
|
Invoke-AddToDomain.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
$ConfigData = (& "$ScriptPath\ConfigData.AddToDomain.ps1")
. "$ScriptPath\Configuration.AddToDomain.ps1"
Remove-Item -Recurse -Force "$OutputPath\AddToDomain" 2> $null
AddToDomain -OutputPath "$OutputPath\AddToDomain" -ConfigurationData $ConfigData
Start-DscConfiguration -Wait -Force -Path "$OutputPath\AddToDomain" -Verbose -Credential $Credential
#Restart-Computer -Force -Wait -Protocol WSMan -ComputerName $DomainController -Verbose
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/Configuration.AddToDomain.ps1
|
Configuration.AddToDomain.ps1
|
configuration AddToDomain
{
Import-DscResource -ModuleName xActiveDirectory, xComputerManagement, xNetworking, PSDesiredStateConfiguration
node $AllNodes.Where{$_.Role -eq 'Node'}.Nodename
{
xDNSServerAddress DNS
{
InterfaceAlias = 'Ethernet'
Address = $Node.DNSServer
AddressFamily = 'IPv4'
}
xComputer Computer
{
Name = $Node.NodeName
DomainName = $Node.DomainName
Credential = $Node.DomainAdminCredential
DependsOn = '[xDNSServerAddress]DNS'
}
WaitForAll WaitForDomainUser
{
NodeName = $Node.DomainController
ResourceName = '[xADUser]FirstUser'
RetryIntervalSec = 10
RetryCount = 10
}
Group Administrators
{
GroupName = 'Administrators'
Ensure = 'Present'
Members = $Node.DomainUser
DependsOn = @('[xComputer]Computer', '[WaitForAll]WaitForDomainUser')
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/ConfigData.DomainSetup.ps1
|
ConfigData.DomainSetup.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
if ($Credential -eq $null)
{
$Credential = Get-Credential Administrator -Message 'Enter domain admin credential (will also be used as Safemode Admin Credentials)'
}
@{
AllNodes = @(
@{
NodeName = 'Nana-XM-DC'
Role = 'DomainController'
DomainName = 'NanaTestDomain.com'
DomainAdminCredential = $Credential
SafemodeAdminCredential = $Credential
AnotherAdminCredential = (New-Object System.Management.Automation.PSCredential "Nana", $Credential.Password)
# allow plain text passwords in a mof file is a security hole
# it is being used here purely for the demo
# Do not use this in any script in your environment
PSDscAllowPlainTextPassword = $true
}
)
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/Assert-MetaConfig.ps1
|
Assert-MetaConfig.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
$ConfigData = (& "$ScriptPath\ConfigData.DomainSetup.ps1")
. "$ScriptPath\MetaConfig.DomainSetup.ps1"
Remove-Item -Recurse -Force "$OutputPath\DCMetaConfig" 2> $null
DCMetaConfig -OutputPath "$OutputPath\DCMetaConfig" -ConfigurationData $ConfigData
Set-DscLocalConfigurationManager -Path "$OutputPath\DCMetaConfig" -Verbose -Credential $Credential
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/xMachine/Assert-DomainSetup.ps1
|
Assert-DomainSetup.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
$ConfigData = (& "$ScriptPath\ConfigData.DomainSetup.ps1")
. "$ScriptPath\Configuration.DomainSetup.ps1"
Remove-Item -Recurse -Force "$OutputPath\DomainSetup" 2> $null
DomainSetup -OutputPath "$OutputPath\DomainSetup" -ConfigurationData $ConfigData
. "$ScriptPath\Assert-MetaConfig.ps1"
Start-DscConfiguration -Wait -Force -Path "$OutputPath\DomainSetup" -Verbose -Credential $Credential
# restart VM
#Restart-Computer -Force -Wait -Protocol WSMan -ComputerName $DomainController -Verbose
Start-DscConfiguration -Wait -ComputerName $DomainController -Credential $Credential -UseExisting -Verbose
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/ConfigurationStatus/Demo.ps1
|
Demo.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
# get configuration status from a node
$s = New-CimSession -ComputerName $DomainController -Credential $Credential
Get-DscConfigurationStatus -CimSession $s
# get all configuration status
Get-DscConfigurationStatus -CimSession $s -All -OutVariable Status
# Properties of interest - Status, Type, Mode, RebootRequested
# information available in status
$Status[0] | Format-List * -Force
# job id filtering
$Status | Group-Object -Property JobId
# post reboot will have same job id
# resources in desired state
$Status[-2].ResourcesInDesiredState | Format-Table ResourceId, ModuleName, ModuleVersion, REbootRequested -AutoSize
# mess around with something
Invoke-Command -ComputerName $DomainController -Credential $Credential {net user nana /delete }
# invoke consistency check
Invoke-ConsistencyCheck -ComputerName $DomainController -Credential $Credential
# show resources not in desired state
Get-DscConfigurationStatus -CimSession $s -All -OutVariable Status
$Status[0].ResourcesNotInDesiredState
# check when there was a deviation
$status | ?{$_.ResourcesNotInDesiredSTate -ne $Null}
# fix the mess up
Start-DscConfiguration -ComputerName $DomainController -Credential $Credential -Force -Verbose -Path "$OutputPath\DOmainSetup" -wait
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/TestConfiguration/Configuration.Simple.ps1
|
Configuration.Simple.ps1
|
configuration Simple
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
node $AllNodes.Where{$_.Role -eq 'Node'}.Nodename
{
File Helo
{
DestinationPath = 'C:\Temp\HeloWorld.txt'
Contents = 'Helo world'
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/TestConfiguration/Configuration.Features.ps1
|
Configuration.Features.ps1
|
Configuration Features
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
node $AllNodes.Where{$_.Role -eq 'Node'}.Nodename
{
WindowsFeature IIS
{
Name = 'Web-Server'
Ensure = 'Present'
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/TestConfiguration/ConfigData.Simple.ps1
|
ConfigData.Simple.ps1
|
@{
AllNodes = @(
@{
NodeName = 'Nana-XM-Node'
Role = 'Node'
}
)
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/TestConfiguration/Demo.ps1
|
Demo.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
$s = New-CimSession -ComputerName $TestNode -Credential $Credential
# get VM to initial state
# Restore-VMSnapshot -Name 'Initial' -VMName $TestNode -Verbose
# test the status of a configuration
Test-DscConfiguration -CimSession $s
# when there are no configurations it returns an error
# apply a simple configuration
psedit "$ScriptPath\Configuration.Simple.ps1"
. "$ScriptPath\Configuration.Simple.ps1"
$ConfigData = (& "$ScriptPath\ConfigData.Simple.ps1")
Simple -OutputPath "$OutputPath\Simple" -ConfigurationData $ConfigData
Start-DscConfiguration -Path "$OutputPath\Simple" -Wait -Force -Verbose
# run test configuration again
Test-DscConfiguration -CimSession $s
# returns a boolean so can be used in a script
if (Test-DscConfiguration -CimSession $s){Write-Output 'System is in desired state'}
# to get detailed information, use -Detailed
Test-DscConfiguration -CimSession $s -Detailed -Verbose
Invoke-Command -ComputerName $TestNode -Credential $Credential {del c:\temp\heloworld.txt}
# notice how detailed tells the resource that are in desired state and
# those that aren't
Test-DscConfiguration -CimSession $s -Detailed -Verbose
# Test if system pertains to a configuration without applying it
psedit "$ScriptPath\Configuration.Features.ps1"
. "$ScriptPath\Configuration.Features.ps1"
Features -OutputPath "$OutputPath\Features" -ConfigurationData $ConfigData
Test-DscConfiguration -Path "$OutputPath\Features" -CimSession $s -Verbose
# it used the mof in the path - but didn't mess with the existing one
Test-DscConfiguration -CimSession $s -Detailed -Verbose
# can compare multiple machines with a reference mof
$s2 = New-CimSession -ComputerName $DomainController -Credential $Credential
Test-DscConfiguration -CimSession ($s, $s2) -ReferenceConfiguration "$OutputPath\Features\$TestNode.mof" -Verbose
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/RunAs/ProcessOwnerCredential.ConfigData.ps1
|
ProcessOwnerCredential.ConfigData.ps1
|
@{
AllNodes = @(
@{
NodeName = 'localhost'
Role = 'DemoNode'
PSDscAllowPlainTextPassword = $true
}
)
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/RunAs/ProcessOwnerCredential.ps1
|
ProcessOwnerCredential.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
configuration ProcessOwnerCredential
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
node $AllNodes.Where{$_.Role -eq 'DemoNode'}.NodeName
{
Script owner
{
GetScript = {@{}}
SetScript = {$p = (Get-Process -id $pid);
$info = (D:\Nana\Official\git\DemosSept2015\RunAs\Get-ProcessOwner.ps1 -process $p);
write-verbose -verbose -message "This process runs as $($info.Name.ToString())"}
TestScript = {$false}
PsDscRunAsCredential = (Get-Credential Administrator)
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/RunAs/ProcessOwner.ps1
|
ProcessOwner.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
configuration ProcessOwner
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
Script owner
{
GetScript = {@{}}
SetScript = {$p = (Get-Process -id $pid);
$info = (D:\Nana\Official\git\DemosSept2015\RunAs\Get-ProcessOwner.ps1 -process $p);
write-verbose -verbose -message "This process runs as $($info.Name.ToString())"}
TestScript = {$false}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/RunAs/Get-ProcessOwner.ps1
|
Get-ProcessOwner.ps1
|
##############################################################################
##
## Get-ProcessOwner.ps1
## Get the owner of a process.
##
## Script taken from http://www.leeholmes.com/blog/2006/07/21/get-the-owner-of-a-process-in-powershell-%E2%80%93-pinvoke-and-refout-parameters/
##
##############################################################################
param([System.Diagnostics.Process] $process)
$TOKEN_QUERY = 0x0008
function Main
{
$token = [IntPtr]::Zero
$processHandle = $process.Handle
if($processHandle -ne $null)
{
if((OpenProcessToken $process.Handle $TOKEN_QUERY ([Ref] $token)) -eq 0)
{
throw “Could not retrieve token for $($process.ProcessName)”
}
}
if($token -ne 0)
{
new-object System.Security.Principal.WindowsIdentity $token
CloseHandle $token > $null
}
}
## Invoke a Win32 P/Invoke call.
function Invoke-Win32([string] $dllName, [Type] $returnType,
[string] $methodName, [Type[]] $parameterTypes, [Object[]] $parameters)
{
## Begin to build the dynamic assembly
$domain = [AppDomain]::CurrentDomain
$name = New-Object Reflection.AssemblyName ‘PInvokeAssembly’
$assembly = $domain.DefineDynamicAssembly($name, ‘Run’)
$module = $assembly.DefineDynamicModule(‘PInvokeModule’)
$type = $module.DefineType(‘PInvokeType’, “Public,BeforeFieldInit”)
## Go through all of the parameters passed to us. As we do this,
## we clone the user’s inputs into another array that we will use for
## the P/Invoke call.
$inputParameters = @()
$refParameters = @()
for($counter = 1; $counter -le $parameterTypes.Length; $counter++)
{
## If an item is a PSReference, then the user
## wants an [out] parameter.
if($parameterTypes[$counter – 1] -eq [Ref])
{
## Remember which parameters are used for [Out] parameters
$refParameters += $counter
## On the cloned array, we replace the PSReference type with the
## .Net reference type that represents the value of the PSReference,
## and the value with the value held by the PSReference.
$parameterTypes[$counter – 1] =
$parameters[$counter – 1].Value.GetType().MakeByRefType()
$inputParameters += $parameters[$counter – 1].Value
}
else
{
## Otherwise, just add their actual parameter to the
## input array.
$inputParameters += $parameters[$counter – 1]
}
}
## Define the actual P/Invoke method, adding the [Out]
## attribute for any parameters that were originally [Ref]
## parameters.
$method = $type.DefineMethod($methodName, ‘Public,HideBySig,Static,PinvokeImpl’,
$returnType, $parameterTypes)
foreach($refParameter in $refParameters)
{
$method.DefineParameter($refParameter, “Out”, $null)
}
## Apply the P/Invoke constructor
$ctor = [Runtime.InteropServices.DllImportAttribute].GetConstructor([string])
$attr = New-Object Reflection.Emit.CustomAttributeBuilder $ctor, $dllName
$method.SetCustomAttribute($attr)
## Create the temporary type, and invoke the method.
$realType = $type.CreateType()
$realType.InvokeMember($methodName, ‘Public,Static,InvokeMethod’, $null, $null,
$inputParameters)
## Finally, go through all of the reference parameters, and update the
## values of the PSReference objects that the user passed in.
foreach($refParameter in $refParameters)
{
$parameters[$refParameter – 1].Value = $inputParameters[$refParameter – 1]
}
}
function OpenProcessToken([IntPtr] $handle, [UInt32] $tokenAccess, [Ref] $token)
{
$parameterTypes = [IntPtr], [UInt32], [Ref]
$parameters = $handle, $tokenAccess, $token
Invoke-Win32 “advapi32.dll” ([Int]) “OpenProcessToken” $parameterTypes $parameters
}
function CloseHandle([IntPtr] $handle)
{
$parameterTypes = [IntPtr]
$parameters = [IntPtr] $handle
Invoke-Win32 “kernel32.dll” ([Bool]) “CloseHandle” $parameterTypes $parameters
}
. Main
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/RunAs/Demo.ps1
|
Demo.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
# Try to figure out the context in which DSC runs
# Thanks Lee Holmes for the script
psedit "$ScriptPath\Get-ProcessOwner.ps1"
psedit "$ScriptPath\ProcessOwner.ps1"
# compile and invoke the configuration
. "$ScriptPath\ProcessOwner.ps1"
ProcessOwner -OutputPath "$Outputpath\ProcessOwner"
Start-DscConfiguration -Path "$Outputpath\ProcessOwner" -Wait -Force -Verbose
# every resource now comes with an additional property
Get-DscResource -Name File -Syntax
# the PSDscRunAsCredential will take a credential and will run the resource
# in a process with that token
psedit "$ScriptPath\ProcessOwnerCredential.ps1"
. "$ScriptPath\ProcessOwnerCredential.ps1"
$ConfigData = (& "$ScriptPath\ProcessOwnerCredential.ConfigData.ps1")
ProcessOwnerCredential -OutputPath "$Outputpath\ProcessOwnerCredential" -ConfigurationData $ConfigData
Start-DscConfiguration -Path "$Outputpath\ProcessOwnerCredential" -Wait -Force -Verbose
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/PartialConfigurations/HeloWorld.ps1
|
HeloWorld.ps1
|
configuration HeloWorld
{
param(
[string]
$ComputerName
)
Import-DscResource -ModuleName PSDesiredStateConfiguration
node $ComputerName
{
File f
{
Contents = 'Helo World'
DestinationPath = 'c:\temp\heloworld.txt'
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/PartialConfigurations/MetaConfiguration.ps1
|
MetaConfiguration.ps1
|
[DscLocalConfigurationManager()]
configuration MetaConfiguration
{
param(
[string]
$ComputerName = 'localhost'
)
node $ComputerName
{
Settings
{
RefreshFrequencyMins = 60
ActionAfterReboot = 'StopConfiguration'
DebugMode = 'ForceModuleImport'
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/PartialConfigurations/AppLayer.ps1
|
AppLayer.ps1
|
Configuration AppLayer
{
param(
[string]
$ComputerName
)
# Import the module that defines custom resources
Import-DscResource -Module xWebAdministration, PSDesiredStateConfiguration
node $ComputerName
{
# Stop the default website
xWebsite DefaultSite
{
Ensure = "Present"
Name = "Default Web Site"
State = "Stopped"
PhysicalPath = "C:\inetpub\wwwroot"
}
# Copy the website content
File WebContent
{
Ensure = "Present"
SourcePath = 'C:\Content\Nana\Content\BakeryWebsite'
DestinationPath = 'C:\inetpub\FourthCoffee'
Recurse = $true
Type = "Directory"
}
# Create the new Website
xWebsite BakeryWebSite
{
Ensure = "Present"
Name = 'FourthCoffee'
State = "Started"
PhysicalPath = 'C:\inetpub\FourthCoffee'
DependsOn = "[File]WebContent"
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/PartialConfigurations/MetaConfigurationForPartialConfigs.ps1
|
MetaConfigurationForPartialConfigs.ps1
|
[DscLocalConfigurationManager()]
configuration MetaConfigForPartialConfigs
{
param(
[string]
$ComputerName
)
node $ComputerName
{
Settings
{
RefreshFrequencyMins = 60
}
PartialConfiguration OSLayer
{
Description = "Everything at the OS level"
ExclusiveResources = @("xComputerManagement\xComputer")
}
PartialConfiguration AppLayer
{
Description = 'Web application deployment'
ExclusiveResources = @('xWebAdministration\xWebsite')
DependsOn = "[PartialConfiguration]OSLayer"
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/PartialConfigurations/OSLayer.ps1
|
OSLayer.ps1
|
Configuration OSLayer
{
param(
[string]
$ComputerName
)
Import-DscResource -ModuleName PSDesiredStateConfiguration, xwebadministration
node $ComputerName
{
# Install the IIS role
WindowsFeature IIS
{
Ensure = "Present"
Name = "Web-Server"
}
# Install the ASP .NET 4.5 role
WindowsFeature AspNet45
{
Ensure = "Present"
Name = "Web-Asp-Net45"
}
xWebsite DefaultSite
{
Ensure = "Present"
Name = "Default Web Site"
State = "Stopped"
PhysicalPath = "C:\inetpub\wwwroot"
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/PartialConfigurations/PartialConfiguration.ps1
|
PartialConfiguration.ps1
|
#region Declarations
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
#endregion Declarations
# In PowerShell 5.0, there is a new syntax for partial configurations
psedit "$ScriptPath\MetaConfiguration.ps1"
# for partial configurations, meta configuration must first declare the individual
# pieces and dependencies
psedit "$ScriptPath\MetaConfigurationForPartialConfigs.ps1"
. "$ScriptPath\MetaConfigurationForPartialConfigs.ps1"
MetaConfigForPartialConfigs -ComputerName $PCTestNode -OutputPath "$OutputPath\MetaConfigurationForPartialConfigs"
Set-DscLocalConfigurationManager -Path "$OutputPath\MetaConfigurationForPartialConfigs" -ComputerName $PCTestNode `
-Verbose -Credential $Credential
# Once set start will not work
psedit "$ScriptPath\HeloWorld.ps1"
. "$ScriptPath\HeloWorld.ps1"
HeloWorld -ComputerName $PCTestNode -OutputPath "$OutputPath\HeloWorld"
Start-DscConfiguration -Path "$OutputPath\HeloWorld" -Wait -Force -ComputerName $PCTestNode -Credential $Credential -Verbose
psedit "$ScriptPath\OSLayer.ps1"
psedit "$ScriptPath\AppLayer.ps1"
. "$ScriptPath\OSLayer.ps1"
. "$ScriptPath\AppLayer.ps1"
OSLayer -ComputerName $PCTestNode -OutputPath "$OutputPath\OSLayer"
AppLayer -ComputerName $PCTestNode -OutputPath "$OutputPath\AppLayer"
Publish-DscConfiguration -Path "$OutputPath\OSLayer" -ComputerName $PCTestNode -verbose -Credential $Credential
Publish-DscConfiguration -Path "$OutputPath\AppLayer" -ComputerName $PCTestNode -verbose -Credential $Credential
# the file is only published and during invocation is merged
Invoke-Command $PCTestNode -Credential $Credential { dir "$env:windir\system32\configuration\PartialConfigurations"}
# convergence happens automatically on the next consistency check
Invoke-ConsistencyCheck -ComputerName $PCTestNode -Credential $Credential
# you can also force one using Start-DscConfiguration
Start-DscConfiguration -UseExisting -ComputerName $PCTestNode -Wait -Verbose -Credential $Credential
# correct the exclusiv error and republish
psedit "$ScriptPath\OSLayer.ps1"
. "$ScriptPath\OSLayer.ps1"
OSLayer -ComputerName $PCTestNode -OutputPath "$OutputPath\OSLayer"
Publish-DscConfiguration -Path "$OutputPath\OSLayer" -ComputerName $PCTestNode -verbose -Credential $Credential
Invoke-ConsistencyCheck -ComputerName $PCTestNode -Credential $Credential
# reset the metaconfiguration
. "$ScriptPath\MetaConfiguration.ps1"
MetaConfiguration -ComputerName $PCTestNode -OutputPath "$OutputPath\MetaConfiguration"
Set-DscLocalConfigurationManager -Path "$OutputPath\MetaConfiguration" -ComputerName $PCTestNode -Credential $Credential -Verbose
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/Debugging/ServiceConfiguration.ps1
|
ServiceConfiguration.ps1
|
configuration ServiceConfiguration
{
Import-DscResource -ModuleName nPSDesiredStateConfiguration
nService Wecsvc
{
Name = 'Wecsvc'
StartupType = 'Automatic'
State = 'Running'
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/Debugging/ProcessOwnerCredential.ps1
|
ProcessOwnerCredential.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
configuration ProcessOwnerCredential
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
Script owner
{
GetScript = {@{}}
SetScript = {$p = (Get-Process -id $pid);
$info = (D:\Nana\Official\git\DemosSept2015\RunAs\Get-ProcessOwner.ps1 -process $p);
write-verbose -verbose -message "This process runs as $($info.Name.ToString())"}
TestScript = {$false}
PsDscRunAsCredential = Get-Credential .\Administrator
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/Debugging/ServiceConfigurationClasses.ps1
|
ServiceConfigurationClasses.ps1
|
configuration ServiceConfigurationClasses
{
Import-DscResource -ModuleName nServiceManager
nService Wecsvc
{
Name = 'Wecsvc'
StartupType = 'Automatic'
State = 'Running'
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/Debugging/Demo.ps1
|
Demo.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\..\0-CommonInit.ps1"
# here is a sample resource - nService
psedit "$env:ProgramFiles\windowspowershell\modules\nPSDesiredStateConfiguration\DSCResources\Nana_nService\Nana_nService.psm1"
# copy a buggy resource to demo debugging
copy "$env:ProgramFiles\windowspowershell\modules\nPSDesiredStateConfiguration\DSCResources\Nana_nService\Nana_nService.psm1" "$env:ProgramFiles\windowspowershell\modules\nPSDesiredStateConfiguration\DSCResources\Nana_nService\Nana_nService.Original.psm1"
copy "$ScriptPath\Nana_nService_Buggy.psm1" "$env:ProgramFiles\windowspowershell\modules\nPSDesiredStateConfiguration\DSCResources\Nana_nService\Nana_nService.psm1"
# here is a sample configuration
psedit "$ScriptPath\ServiceConfiguration.ps1"
# invoke the configuration
. "$ScriptPath\ServiceConfiguration.ps1"
ServiceConfiguration -OutputPath "$Outputpath\ServiceConfiguration"
Start-DscConfiguration -Path "$Outputpath\ServiceConfiguration" -ComputerName localhost -Verbose -force -Wait
# enable debugging for DSC Resources
Enable-DscDebug -BreakAll
# apply the configuration again
Start-DscConfiguration -Path "$Outputpath\ServiceConfiguration" -ComputerName localhost -Verbose -force -Wait
# disable debugging
Disable-DscDebug
# restore the correct file
copy "$env:ProgramFiles\windowspowershell\modules\nPSDesiredStateConfiguration\DSCResources\Nana_nService\Nana_nService.original.psm1" `
"$env:ProgramFiles\windowspowershell\modules\nPSDesiredStateConfiguration\DSCResources\Nana_nService\Nana_nService.psm1"
# DSC debugging uses the PowerShell debugging enhancements introduced in v5
# Get a list of Processes hosting PowerShell that can be debugged
Get-PSHostProcessInfo
# can attach to any process using
#Enter-PSHostProcess -Id -AppDomainName
# can get list of runspaces to debug
Get-Runspace
# debug using Debug-Runspace
# Debug-Runspace -id
# debugging class based resources is similar
copy "$env:ProgramFiles\windowspowershell\modules\nServiceManager\nService.psm1" "$env:ProgramFiles\windowspowershell\modules\nServiceManager\nService.Original.psm1"
copy "$ScriptPath\nService_Buggy.psm1" "$env:ProgramFiles\windowspowershell\modules\nServiceManager\nService.psm1"
psedit "$ScriptPath\ServiceConfigurationClasses.ps1"
. "$ScriptPath\ServiceConfigurationClasses.ps1"
ServiceConfigurationClasses -OutputPath "$Outputpath\ServiceConfigurationClasses"
Start-DscConfiguration -Path "$Outputpath\ServiceConfigurationClasses" -ComputerName localhost -Verbose -force -Wait
# enable debugging for DSC resources
Enable-DscDebug -BreakAll
# apply the configuration again
# note the 2 step over and 1 Step into for the class based resource
Start-DscConfiguration -Path "$Outputpath\ServiceConfigurationClasses" -ComputerName localhost -Verbose -force -Wait
# disable debugging
Disable-DscDebug
# restore contents back
copy "$env:ProgramFiles\windowspowershell\modules\nServiceManager\nService.original.psm1" "$env:ProgramFiles\windowspowershell\modules\nServiceManager\nService.psm1"
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/DSCaaS/Azure.Subscription.Settings.ps1
|
Azure.Subscription.Settings.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
@{
SubscriptionName = 'Azure Extension Test' # Name of the subscription to use for azure cmdlets
StorageAccountName = 'nanapsconfdemoap' # Azure storage account name
#StorageAccountKey = 'FI5Irwba8oHUWswyJj4ZD5CE2t2M51/hQxA6NYBMqCrdzcnY9xaeTa6R5di75DbBf0oaBHIg/knNmgfEMbJwPw=='
StorageAccountKey = '54BLGcpyj9wwpaQ1/NQOMQSjnx1/KtNLnOje4zdf9t2PiwaeP+XFNcth3tMe2stEGMfiJMz7yUmwOcxkA4oSJg=='
#StorageLocation = 'West US'
StorageLocation = 'SouthEast Asia'
StorageType = 'Standard_GRS'
AutomationAccount = 'NanaDemoAP'
ResourceGroup = 'NanaDemoRGAP'
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/DSCaaS/Features.ps1
|
Features.ps1
|
configuration Features
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
node localhost
{
WindowsFeature IIS
{
Name = 'Web-Server'
Ensure = 'Present'
}
}
}
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/DSCaaS/Demo.ps1
|
Demo.ps1
|
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
. "$ScriptPath\1-CommonInit.ps1"
# Load configuration Settings
Write-Verbose "Loading subscription settings '$ScriptPath\Azure.Subscription.Settings.ps1'"
$Settings = (& "$ScriptPath\Azure.Subscription.Settings.ps1")
# get the registration information for the account
Get-AzureAutomationRegistrationInfo -ResourceGroupName $Settings.ResourceGroup `
-AutomationAccountName $Settings.AutomationAccount `
-Verbose `
-OutVariable RegInfo
# let us use a simple configuration
psedit "$ScriptPath\Features.ps1"
# import the configuration script
Import-AzureAutomationDscConfiguration -SourcePath "$ScriptPath\Features.ps1" `
-Description 'Simple demo' `
-Published `
-Force `
-ResourceGroupName $Settings.ResourceGroup `
-AutomationAccountName $Settings.AutomationAccount `
-Verbose
# view the status of the configuration script
Get-AzureAutomationDscConfiguration -Name 'Features' -ResourceGroupName $Settings.ResourceGroup -AutomationAccountName $Settings.AutomationAccount -Verbose
# compile the configuration script
Start-AzureAutomationDscCompilationJob -ConfigurationName 'Features' `
-ResourceGroupName $Settings.ResourceGroup `
-AutomationAccountName $Settings.AutomationAccount `
-Verbose `
-OutVariable job
# view status of compilation
Get-AzureAutomationDscCompilationJob -Id $job.Id -ResourceGroupName $Settings.ResourceGroup -AutomationAccountName $Settings.AutomationAccount
# use this in an Azure node
Register-AzureAutomationDscNode -AzureVMName $AzureDemoNode `
-ResourceGroupName $Settings.ResourceGroup `
-AutomationAccountName $Settings.AutomationAccount `
-AzureVMLocation $Settings.StorageLocation `
-Verbose
# get list of nodes registered
Get-AzureAutomationDscNode -ResourceGroupName $Settings.ResourceGroup -AutomationAccountName $Settings.AutomationAccount
# get the required metaconfiguration
Get-AzureAutomationDscOnboardingMetaconfig -OutputFolder "$DemoRoot" `
-ResourceGroupName $Settings.ResourceGroup `
-AutomationAccountName $Settings.AutomationAccount `
-Force
# invoke the meta config from a node in AWS
# registration happens from meta config is set
# get list of nodes registered
Get-AzureAutomationDscNode -ResourceGroupName $Settings.ResourceGroup -AutomationAccountName $Settings.AutomationAccount
# Assign a configuration to node
Set-AzureAutomationDscNode -NodeConfigurationName 'Features.localhost' -ResourceGroupName $Settings.ResourceGroup -AutomationAccountName $Settings.AutomationAccount
|
PowerShellCorpus/PowerShellGallery/DemosSept2015/0.1/DSCaaS/1-CommonInit.ps1
|
1-CommonInit.ps1
|
[CmdletBinding()]
param()
$CommonInit1Path = Split-Path $MyInvocation.MyCommand.Path
. "$CommonInit1Path\..\0-CommonInit.ps1"
$VerbosePref = $false
if ($PSBoundParameters.ContainsKey('Verbose'))
{
$VerbosePref = $true
}
Import-Module -Name Azure -Verbose:$false -ErrorVariable ev -ErrorAction SilentlyContinue
if ($ev -ne $null)
{
Import-Module -Name AzureResourceManager -Verbose:$false -ErrorVariable ev -ErrorAction Stop
}
Switch-AzureMode -Name AzureResourceManager
#
if (-not(Get-AzureAccount -ErrorAction SilentlyContinue))
{
Add-AzureAccount -ErrorVariable ev
if ($ev -ne $Null)
{
throw 'Something went wrong in Azure authentication, try again'
}
}
|
PowerShellCorpus/PowerShellGallery/Statistics/1.1.63/Measure-Object.ps1
|
Measure-Object.ps1
|
function Measure-Object {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[array]
$Data
,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]
$Property
)
Process {
#region Percentiles require sorted data
$Data = $Data | Sort-Object -Property $Property
#endregion
#region Grab basic measurements from upstream Measure-Object
$Stats = $Data | Microsoft.PowerShell.Utility\Measure-Object -Property $Property -Minimum -Maximum -Sum -Average
#endregion
#region Calculate median
Write-Debug ('[{0}] Number of data items is <{1}>' -f $MyInvocation.MyCommand.Name, $Data.Count)
if ($Data.Count % 2 -eq 0) {
Write-Debug ('[{0}] Even number of data items' -f $MyInvocation.MyCommand.Name)
$MedianIndex = ($Data.Count / 2) - 1
Write-Debug ('[{0}] Index of Median is <{1}>' -f $MyInvocation.MyCommand.Name, $MedianIndex)
$LowerMedian = $Data[$MedianIndex] | Select-Object -ExpandProperty $Property
$UpperMedian = $Data[$MedianIndex + 1] | Select-Object -ExpandProperty $Property
Write-Debug ('[{0}] Lower Median is <{1}> and upper Median is <{2}>' -f $MyInvocation.MyCommand.Name, $LowerMedian, $UpperMedian)
$Median = ([double]$LowerMedian + [double]$UpperMedian) / 2
Write-Debug ('[{0}] Average of lower and upper Median is <{1}>' -f $MyInvocation.MyCommand.Name, $Median)
} else {
Write-Debug ('[{0}] Odd number of data items' -f $MyInvocation.MyCommand.Name)
$MedianIndex = [math]::Ceiling(($Data.Count - 1) / 2)
Write-Debug ('[{0}] Index of Median is <{1}>' -f $MyInvocation.MyCommand.Name, $MedianIndex)
$Median = $Data[$MedianIndex] | Select-Object -ExpandProperty $Property
Write-Debug ('[{0}] Median is <{1}>' -f $MyInvocation.MyCommand.Name, $Median)
}
Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Median' -Value $Median
#endregion
#region Calculate variance
$Variance = 0
foreach ($_ in $Data) {
$Variance += [math]::Pow($_.$Property - $Stats.Average, 2) / $Stats.Count
}
$Variance /= $Stats.Count
Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Variance' -Value $Variance
#endregion
#region Calculate standard deviation
$StandardDeviation = [math]::Sqrt($Stats.Variance)
Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'StandardDeviation' -Value $StandardDeviation
#endregion
#region Calculate percentiles
$Percentile10Index = [math]::Ceiling(10 / 100 * $Data.Count)
$Percentile25Index = [math]::Ceiling(25 / 100 * $Data.Count)
$Percentile75Index = [math]::Ceiling(75 / 100 * $Data.Count)
$Percentile90Index = [math]::Ceiling(90 / 100 * $Data.Count)
Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile10' -Value $Data[$Percentile10Index].$Property
Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile25' -Value $Data[$Percentile25Index].$Property
Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile75' -Value $Data[$Percentile75Index].$Property
Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile90' -Value $Data[$Percentile90Index].$Property
#endregion
#region Calculate Tukey's range for outliers
$TukeysOutlier = 1.5
$TukeysRange = $TukeysOutlier * ($Stats.Percentile75 - $Stats.Percentile25)
Add-Member -InputObject $Stats -MemberType NoteProperty -Name TukeysRange -Value $TukeysRange
#endregion
#region Calculate confidence intervals
$z = @{
'90' = 1.645
'95' = 1.96
'98' = 2.326
'99' = 2.576
}
$Confidence95 = 1.96 * $Stats.StandardDeviation / [math]::Sqrt($Stats.Count)
Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Confidence95' -Value $Confidence95
#endregion
#region Return measurements
$Stats
#endregion
}
}
New-Alias -Name mo -Value Measure-Object -Force
|
PowerShellCorpus/PowerShellGallery/Statistics/1.1.63/Get-ExampleTimeSeries.ps1
|
Get-ExampleTimeSeries.ps1
|
function Get-ExampleTimeSeries {
[CmdletBinding()]
param(
[int]
$Count = 100
,
[datetime]
$Start
,
[datetime]
$End = (Get-Date)
,
[int]
$IntervalDays = 7
)
if (-Not $Start) {
$Start = $End.AddDays(-1 * $IntervalDays)
}
$StartTicks = $Start.Ticks
$EndTicks = $End.Ticks
1..$Count | ForEach-Object {
Get-Random -Minimum $StartTicks -Maximum $EndTicks
} | Sort-Object | ForEach-Object {
[pscustomobject]@{
Timestamp = Get-Date -Date $_
Value = Get-Random -Minimum 0 -Maximum 100
}
}
}
|
PowerShellCorpus/PowerShellGallery/Statistics/1.1.63/Show-Measurement.ps1
|
Show-Measurement.ps1
|
function Show-Measurement {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[object]
$InputObject
,
[Parameter()]
[ValidateNotNullOrEmpty()]
[int]
$Width = $( if ($Host.UI.RawUI.MaxWindowSize.Width) { $Host.UI.RawUI.MaxWindowSize.Width - 10 } else { 90 } )
,
[switch]
$PassThru
)
Process {
#region Generate visualization of measurements
$AvgSubDevIndex = [math]::Round(($InputObject.Average - $InputObject.StandardDeviation) / $InputObject.Maximum * $Width, 0)
$AvgIndex = [math]::Round( $InputObject.Average / $InputObject.Maximum * $Width, 0)
$AvgAddDevIndex = [math]::Round(($InputObject.Average + $InputObject.StandardDeviation) / $InputObject.Maximum * $Width, 0)
$AvgSubConfIndex = [math]::Round(($InputObject.Average - $InputObject.Confidence95) / $InputObject.Maximum * $Width, 0)
$AvgAddConfIndex = [math]::Round(($InputObject.Average + $InputObject.Confidence95) / $InputObject.Maximum * $Width, 0)
$MedIndex = [math]::Round( $InputObject.Median / $InputObject.Maximum * $Width, 0)
$P10Index = [math]::Round( $InputObject.Percentile10 / $InputObject.Maximum * $Width, 0)
$P25Index = [math]::Round( $InputObject.Percentile25 / $InputObject.Maximum * $Width, 0)
$P75Index = [math]::Round( $InputObject.Percentile75 / $InputObject.Maximum * $Width, 0)
$P90Index = [math]::Round( $InputObject.Percentile90 / $InputObject.Maximum * $Width, 0)
$P25SubTukIndex = [math]::Round(($InputObject.Percentile25 - $InputObject.TukeysRange) / $InputObject.Maximum * $Width, 0)
$P75AddTukIndex = [math]::Round(($InputObject.Percentile75 + $InputObject.TukeysRange) / $InputObject.Maximum * $Width, 0)
Write-Debug "P10=$P10Index P25=$P25Index A=$AvgIndex M=$MedIndex sA=$AvgSubDevIndex As=$AvgAddDevIndex cA=$AvgSubConfIndex aC=$AvgAddConfIndex o=$P25SubTukIndex O=$P75AddTukIndex P75=$P75Index P90=$P90Index"
$graph = @()
$graph += 'Range : ' + '---------|' * ($Width / 10)
$graph += '10% Percentile : ' + ' ' * $P10Index + 'P10'
$graph += '25% Percentile : ' + ' ' * $P25Index + 'P25'
$graph += 'Average : ' + ' ' * $AvgIndex + 'A'
$graph += 'Standard Deviation: ' + (New-RangeString -Width $Width -LeftIndex $AvgSubDevIndex -RightIndex $AvgAddDevIndex -LeftIndicator 's' -RightIndicator 'S')
$graph += '95% Confidence : ' + (New-RangeString -Width $Width -LeftIndex $AvgSubConfIndex -RightIndex $AvgAddConfIndex -LeftIndicator 'c' -RightIndicator 'C')
$graph += 'Tukeys Range : ' + (New-RangeString -Width $Width -LeftIndex $P25SubTukIndex -RightIndex $P75AddTukIndex -LeftIndicator 'o' -RightIndicator 'O')
$graph += 'Median : ' + ' ' * $MedIndex + 'M'
$graph += '75% Percentile : ' + ' ' * $P75Index + 'P75'
$graph += '90% Percentile : ' + ' ' * $P90Index + 'P90'
$graph += 'Range : ' + '---------|' * ($Width / 10)
#endregion
#region Return graph
if ($PassThru) {
$InputObject
}
Write-Host ($graph -join "`n")
#endregion
}
}
New-Alias -Name sm -Value Show-Measurement -Force
|
PowerShellCorpus/PowerShellGallery/Statistics/1.1.63/Get-Histogram.ps1
|
Get-Histogram.ps1
|
function Get-Histogram {
[CmdletBinding(DefaultParameterSetName='BucketCount')]
Param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[array]
$Data
,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]
$Property
,
[Parameter()]
[ValidateNotNullOrEmpty()]
[float]
$Minimum
,
[Parameter()]
[ValidateNotNullOrEmpty()]
[float]
$Maximum
,
[Parameter()]
[ValidateNotNullOrEmpty()]
[Alias('Width')]
[float]
$BucketWidth = 1
,
[Parameter()]
[ValidateNotNullOrEmpty()]
[Alias('Count')]
[float]
$BucketCount
)
Process {
Write-Verbose ('[{0}] Building histogram' -f $MyInvocation.MyCommand)
Write-Debug ('[{0}] Retrieving measurements from upstream cmdlet for {1} values' -f $MyInvocation.MyCommand, $Data.Count)
Write-Progress -Activity 'Measuring data'
$Stats = $Data | Microsoft.PowerShell.Utility\Measure-Object -Minimum -Maximum -Property $Property
if (-Not $PSBoundParameters.ContainsKey('Minimum')) {
$Minimum = $Stats.Minimum
Write-Debug ('[{0}] Minimum value not specified. Using smallest value ({1}) from input data.' -f $MyInvocation.MyCommand, $Minimum)
}
if (-Not $PSBoundParameters.ContainsKey('Maximum')) {
$Maximum = $Stats.Maximum
Write-Debug ('[{0}] Maximum value not specified. Using largest value ({1}) from input data.' -f $MyInvocation.MyCommand, $Maximum)
}
if (-Not $PSBoundParameters.ContainsKey('BucketCount')) {
$BucketCount = [math]::Ceiling(($Maximum - $Minimum) / $BucketWidth)
Write-Debug ('[{0}] Bucket count not specified. Calculated {1} buckets from width of {2}.' -f $MyInvocation.MyCommand, $BucketCount, $BucketWidth)
}
if ($BucketCount -gt 100) {
Write-Warning ('[{0}] Generating {1} buckets' -f $MyInvocation.MyCommand, $BucketCount)
}
Write-Debug ('[{0}] Building buckets using: Minimum=<{1}> Maximum=<{2}> BucketWidth=<{3}> BucketCount=<{4}>' -f $MyInvocation.MyCommand, $Minimum, $Maximum, $BucketWidth, $BucketCount)
Write-Progress -Activity 'Creating buckets'
$OverallCount = 0
$Buckets = 1..$BucketCount | ForEach-Object {
[pscustomobject]@{
Index = $_
lowerBound = $Minimum + ($_ - 1) * $BucketWidth
upperBound = $Minimum + $_ * $BucketWidth
Count = 0
RelativeCount = 0
Group = New-Object -TypeName System.Collections.ArrayList
PSTypeName = 'HistogramBucket'
}
}
Write-Debug ('[{0}] Building histogram' -f $MyInvocation.MyCommand)
$DataIndex = 1
foreach ($_ in $Data) {
$Value = $_.$Property
Write-Progress -Activity 'Filling buckets' -PercentComplete ($DataIndex / $Data.Count * 100)
if ($Value -ge $Minimum -and $Value -le $Maximum) {
$BucketIndex = [math]::Floor(($Value - $Minimum) / $BucketWidth)
if ($BucketIndex -lt $Buckets.Length) {
$Buckets[$BucketIndex].Count += 1
[void]$Buckets[$BucketIndex].Group.Add($_)
$OverallCount += 1
}
}
++$DataIndex
}
Write-Debug ('[{0}] Adding relative count' -f $MyInvocation.MyCommand)
foreach ($_ in $Buckets) {
$_.RelativeCount = if ($OverallCount -gt 0) { $_.Count / $OverallCount } else { 0 }
}
Write-Debug ('[{0}] Returning histogram' -f $MyInvocation.MyCommand)
$Buckets
}
}
New-Alias -Name gh -Value Get-Histogram -Force
|
PowerShellCorpus/PowerShellGallery/Statistics/1.1.63/Get-InterarrivalTime.ps1
|
Get-InterarrivalTime.ps1
|
function Get-InterarrivalTime {
[CmdletBinding()]
Param(
[Parameter(Mandatory,ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[array]
$InputObject
,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]
$Property
,
[Parameter()]
[ValidateSet('Ticks', 'TotalSecond', 'Minutes', 'Hours', 'Days')]
[string]
$Unit = 'Ticks'
)
Begin {
Write-Debug ('[{0}] Entering begin block' -f $MyInvocation.MyCommand)
$PreviousArrival = $null
}
Process {
Write-Debug ('[{0}] Entering process block' -f $MyInvocation.MyCommand)
$InputObject | ForEach-Object {
Write-Debug ('[{0}] Processing value' -f $MyInvocation.MyCommand)
if ($PreviousArrival) {
Write-Debug ('[{0}] Calculating interarrival time' -f $MyInvocation.MyCommand)
Add-Member -InputObject $_ -MemberType NoteProperty -Name "Interarrival$Unit" -Value (New-TimeSpan -Start $PreviousArrival.$Property -End $_.$Property | Select-Object -ExpandProperty $Unit) -PassThru
}
$PreviousArrival = $_
}
}
}
New-Alias -Name giat -Value Get-InterarrivalTime -Force
|
PowerShellCorpus/PowerShellGallery/Statistics/1.1.63/ConvertFrom-PrimitiveType.ps1
|
ConvertFrom-PrimitiveType.ps1
|
function ConvertFrom-PrimitiveType {
[CmdletBinding()]
param(
[Parameter(Mandatory,ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
$InputObject
)
Process {
Write-Debug ('[{0}] Entered process block' -f $MyInvocation.MyCommand)
$InputObject | ForEach-Object {
if (-Not $_.GetType().IsPrimitive) {
throw ('[{0}] Value is not a primitive type' -f $MyInvocation.MyCommand)
}
[pscustomobject]@{
Value = $_
}
}
}
}
New-Alias -Name cfpt -Value ConvertFrom-PrimitiveType -Force
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.