PowerShell functions for Windows

This page contains an overview and detailed description of all Windows functions included in the Dennis Span PowerShell function library. You can download the PowerShell module file on the main page PowerShell function library.

Table of Contents

Certificates

DS_BindCertificateToIISPort

Use this function to bind an SSL certification so an IIS port.

  • Description:
    Bind a certificate to an IIS port.
  • Parameters:
    • URL
      [Mandatory] This parameter contains the URL (e.g. apps.myurl.com) of the certificate.
      If this parameter contains the prefix http:// or https:// or any suffixes, these are automatically deleted.
    • Port
      [Optional] This parameter contains the port of the IIS site to which the certificate should be bound (e.g. 443).
      If this parameter is omitted, the value 443 is used.
  • Example 1:
    DS_BindCertificateToIISSite -URL “myurl.com” -Port 443
    Binds the certificate containing the URL ‘myurl.com’ to port 443. The function automatically determines the hash value of the certificate.
  • Example 2:
    DS_BindCertificateToIISSite -URL “anotherurl.com” -Port 12345
    Binds the certificate containing the URL anotherurl.com to port 12345. The function automatically determines the hash value of the certificate.

DS_InstallCertificate

Use this function to install a certificate in one of the local stores. This function supports all stores (in both local machine and current user context) as well as all main certificate types, for example:

  • Certificates with private key (e.g. *.PFX)
  • Certificates with private key and password protection
  • Root and intermediate certificates (e.g. *.CER)
  • Wildcard certificates
  • Subject Alternative Name (SAN) certificates

Please be aware that the abbreviation of some certificate stores are different from their display name, for example:

  • CA = Intermediate Certificates Authorities
  • My = Personal
  • Root = Trusted Root Certificates Authorities
  • TrustedPublisher = Trusted Publishers
Note: use the following PowerShell command to find the names of all existing local machine certificate stores: Get-Childitem cert:\localmachine.
Note: a certificate password has to be parsed as a secure string! There are various ways how to accomplish this. See my article Encrypting passwords in a PowerShell script for more information.

Description:
Install a certificate. This can be any type of certificate, such as root certificates, intermediate certificates and personal certificates. Also, most formats are supported, such as CER and PFX as well as certificates that include a password.

  • Parameters:
    • StoreScope
      This parameter determines whether the local machine or the current user store is to be used (possible values are: CurrentUser | LocalMachine).
    • StoreName
      This parameter contains the name of the store (possible values are: CA | My, Root | TrustedPublisher and more).
    • CertFile
      This parameter contains the name, including path and file extension, of the certificate file (e.g. C:\MyCert.cer).
    • CertPassword
      This parameter is optional and is required in case the exported certificate is password protected. The password has to be parsed as a secure-string
      For more information see the article Encrypting passwords in a PowerShell script.
  • Example 1:
    DS_InstallCertificate -StoreScope “LocalMachine” -StoreName “Root” -CertFile “C:\Temp\MyRootCert.cer”
    Installs the root certificate MyRootCert.cer in the Trusted Root Certificates Authorities store of the local machine.
  • Example 2:
    DS_InstallCertificate -StoreScope “LocalMachine” -StoreName “CA” -CertFile “C:\Temp\MyIntermediateCert.cer”
    Installs the intermediate certificate MyIntermediateCert.cer in the Intermediate Certificates Authorities store of the local machine.
  • Example 3:
    $Password = “mypassword” | ConvertTo-SecureString -AsPlainText -Force
    DS_InstallCertificate -StoreScope “LocalMachine” -StoreName “My” -CertFile “C:\Temp\MyServerCert.pfx” -CertPassword $Password

    Installs the password protected certificate MyServerCert.pfx in the Personal store of the local machine. The password has to be parsed as a secure-string. See my article Encrypting passwords in a PowerShell script for more information.
  • Example 4:
    $Password = “mypassword” | ConvertTo-SecureString -AsPlainText -Force
    DS_InstallCertificate -StoreScope “CurrentUser” -StoreName “My” -CertFile “C:\Temp\MyUserCert.pfx” -CertPassword $Password
    Installs the password protected certificate MyUserCert.pfx in the Personal store of the current user. The password has to be parsed as a secure-string. See my article Encrypting passwords in a PowerShell script for more information.

Files and folders

DS_CleanupDirectory

Use this function to delete all files and subfolders within a give directory without deleting the main directory itself.

  • Description:
    Delete all files and subfolders in one specific directory, but do not delete the main folder itself.
  • Parameter:
    • Directory
      This parameter contains the full path to the directory that needs to cleaned (for example C:\Temp).
  • Example:
    DS_CleanupDirectory -Directory “C:\Temp”
    Deletes all files and subfolders in the directory C:\Temp. The directory C:\Temp itself is NOT deleted.

Related functions:

DS_CompactDirectory

Use this function to compact a directory in order to save space. This function uses the compact.exe in the directory %WinDir%\System32.

  • Description:
    Execute a process
  • Parameter:
    • Directory
      This parameter contains the full path to the directory that needs to be compacted (for example C:\Windows\WinSxS).
  • Example:
    DS_CompactDirectory -Directory “C:\Windows\WinSxS”
    Compacts the directory C:\Windows\WinSxS.

DS_CopyFile

Use this function to copy one or more files.

  • Description:
    Copy one or more files
  • Parameters:
    • SourceFiles
      This parameter can contain multiple file and folder combinations including wildcards. UNC paths can be used as well. Please see the examples for more information.
      To see the examples, please enter the following PowerShell command: Get-Help DS_CopyFile -examples
    • Destination
      This parameter contains the destination path (for example C:\Temp2 or C:\MyPath\MyApp). This path may also include a file name.
      This situation occurs when a single file is copied to another directory and renamed in the process (for example $Destination = C:\Temp2\MyNewFile.txt).
      UNC paths can be used as well. The destination directory is automatically created if it does not exist (in this case the function DS_CreateDirectory is called).
      This works both with local and network (UNC) directories. In case the variable $Destination contains a path and a file name, the parent folder is
      automatically extracted, checked and created if needed.
      Please see the examples for more information.To see the examples, please enter the following PowerShell command: Get-Help DS_CopyFile -examples
  • Example 1:
    DS_CopyFile -SourceFiles “C:\Temp\MyFile.txt” -Destination “C:\Temp2”
    Copies the file C:\Temp\MyFile.txt to the directory C:\Temp2.
  • Example 2:
    DS_CopyFile -SourceFiles “C:\Temp\MyFile.txt” -Destination “C:\Temp2\MyNewFileName.txt”
    Copies the file C:\Temp\MyFile.txt to the directory C:\Temp2 and renames the file to MyNewFileName.txt.
  • Example 3:
    DS_CopyFile -SourceFiles “C:\Temp\*.txt” -Destination “C:\Temp2”
    Copies all files with the file extension *.txt in the directory C:\Temp to the destination directory C:\Temp2.
  • Example 4:
    DS_CopyFile -SourceFiles “C:\Temp\*.*” -Destination “C:\Temp2”
    Copies all files within the root directory C:\Temp to the destination directory C:\Temp2. Subfolders (including files within these subfolders) are NOT copied.
  • Example 5:
    DS_CopyFile -SourceFiles “C:\Temp\*” -Destination “C:\Temp2”
    Copies all files in the directory C:\Temp to the destination directory C:\Temp2. Subfolders as well as files within these subfolders are also copied.
  • Example 6:
    DS_CopyFile -SourceFiles “C:\Temp\*.txt” -Destination “\\localhost\Temp2”
    Copies all files with the file extension *.txt in the directory C:\Temp to the destination directory \\localhost\Temp2. The directory in this example is a network directory (UNC path).

DS_CreateDirectory

Use this function to create a new directory.

  • Description:
    Create a new directory.
  • Parameter:
    • Directory
      This parameter contains the name of the new directory including the full path (for example C:\Temp\MyNewFolder).
  • Example:
    DS_CreateDirectory -Directory “C:\Temp\MyNewFolder”
    Creates the new directory C:\Temp\MyNewFolder.

DS_DeleteDirectory

Use this function to delete a directory including all files, subfolders and files within subfolders.

  • Description:
    Delete a directory.
  • Parameter:
    • Directory
      This parameter contains the full path to the directory which needs to be deleted (for example C:\Temp\MyFolder).
  • Example:
    DS_DeleteDirectory -Directory “C:\Temp\MyFolder”
    Deletes the directory C:\Temp\MyFolder including all subfolders and files contained within those subfolders.

Related functions:

DS_DeleteFile

Use this function to delete a single file or multiple files within one directory.

  • Description:
    Delete a file.
  • Parameter:
    • File
      This parameter contains the full path to the file (including the file name and file extension) that needs to be deleted (for example C:\Temp\MyFile.txt).
  • Example 1:
    DS_DeleteFile -File “C:\Temp\MyFile.txt”
    Deletes the file “C:\Temp\MyFile.txt”.
  • Example 2:
    DS_DeleteFile -File “C:\Temp\*.txt”
    Deletes all files in the directory C:\Temp that have the file extension *.txt. *.txt files stored within subfolders of C:\Temp are NOT deleted.
  • Example 3:
    DS_DeleteFile -File “C:\Temp\*.*”
    Deletes all files in the directory C:\Temp. This function does NOT remove any subfolders nor files within a subfolder (use the function DS_CleanupDirectory instead).

Related functions:

DS_RenameItem

Use this function to rename files and folders. Regarding files, not only the name, but also the file extension can be renamed.

  • Description:
    Rename files and folders.
  • Parameter:
    • ItemPath
      This parameter contains the full path to the file or folder that needs to be renamed (for example C:\Temp\MyOldFileName.txt or C:\Temp\MyOldFolderName).
    • NewName
      This parameter contains the new name of the file or folder (for example MyNewFileName.txt or MyNewFolderName).
  • Example 1:
    DS_RenameItem -ItemPath “C:\Temp\MyOldFileName.txt” -NewName “MyNewFileName.txt”
    Renames the file C:\Temp\MyOldFileName.txt to MyNewFileName.txt. The parameter NewName only requires the new file name without specifying the path to the file.
  • Example 2:
    DS_RenameItem -ItemPath “C:\Temp\MyOldFileName.txt” -NewName “MyNewFileName.rtf”
    Renames the file C:\Temp\MyOldFileName.txt to MyNewFileName.rtf. Besides changing the name of the file, the file extension is modified as well. Please make sure that the new file format is compatible with the original file format and can actually be opened after being renamed! The parameter NewName only requires the new file name without specifying the path to the file.
  • Example 3:
    DS_RenameItem -ItemPath “C:\Temp\MyOldFolderName” -NewName “MyNewFolderName”
    Renames the folder C:\Temp\MyOldFolderName to C:\Temp\MyNewFolderName. The parameter NewName only requires the new folder name without specifying the path to the folder.

Firewall

DS_CreateFirewallRule

Use this function to create a firewall rule on the local machine. This function uses the NetSh command when the operating system Windows Server 2008 (R2) or Windows 7 is detected. For operating systems from Windows Server 2012 and later, the PowerShell cmdlet New-NetFirewallRule is used. The firewall profile is automatically set to any.

  • Description:
    Create a firewall rule on the local machine.
  • Parameters:
    • Name
      This parameter contains the name of the firewall rule (the name must be unique and cannot be All). The parameter name is used for both the name as well as the display name.
    • Description
      This parameter contains the description of the firewall rule. The description can be an empty string.
    • Ports
      This parameter contains the port or ports which should be allowed or denied. Possible notations are:

      • Example 1: 80,81,82,90,93
      • Example 2: 80-82,90,93
    • Protocol
      This parameter contains the name of the protocol. The most used options are TCP or UDP, but more options are available.
    • Direction
      This parameter contains the direction. Possible options are Inbound or Outbound.
    • Action
      This parameter contains the action. Possible options are Allow or Block.
  • Example:
    DS_CreateFirewallRule -Name “Citrix example firewall rules” -Description “Examples firewall rules for Citrix” -Ports “80-82,99” -Protocol “UDP” -Direction “Inbound” -Action “Allow”
    Creates an inbound firewall rule for the UDP protocol.

Installations and executables

DS_ExecuteProcess

Use this function to execute a process. To install or uninstall an executable or MSI package use the function DS_InstallOrUninstallSoftware.

  • Description:
    Execute a process.
  • Parameters:
    • FileName
      This parameter contains the full path including the file name and file extension of the executable (for example C:\Temp\MyApp.exe).
    • Arguments
      This parameter contains the list of arguments to be executed together with the executable.
  • Example:
    DS_ExecuteProcess -FileName “C:\Temp\MyApp.exe” -Arguments “-silent”
    Executes the file MyApp.exe with arguments -silent.

DS_InstallOrUninstallSoftware

Install or uninstall an executable file (setup.exe) or MSI package.

  • Description:
    Install or uninstall software (MSI or SETUP.exe)
  • Parameters:
    • File
      This parameter contains the file name including the path and file extension, for example C:\Temp\MyApp\Files\MyApp.msi or C:\Temp\MyApp\Files\MyApp.exe.
    • Installationtype
      This parameter contains the installation type, which is either Install or Uninstall.
    • Arguments
      This parameter contains the command line arguments. The arguments list can remain empty. In case of an MSI, the following parameters are automatically included in the function and do not have
      to be specified in the Arguments parameter:

      • For installations: /i /qn /norestart /l*v “c:\Logs\MyLogFile.log”
      • For uninstallations: /x /qn /norestart /l*v “c:\Logs\MyLogFile.log”
  • Example 1:
    DS_InstallOrUninstallSoftware -File “C:\Temp\MyApp\Files\MyApp.msi” -InstallationType “Install” -Arguments “”
    Installs the MSI package MyApp.msi with no arguments (the function already includes the following default arguments: /i /qn /norestart /l*v $LogFile).
  • Example 2:
    DS_InstallOrUninstallSoftware -File “C:\Temp\MyApp\Files\MyApp.msi” -InstallationType “Uninstall” -Arguments “”
    Uninstalls the MSI package MyApp.msi (the function already includes the following default arguments: /x /qn /norestart /l*v $LogFile).
  • Example 3:
    DS_InstallOrUninstallSoftware -File “C:\Temp\MyApp\Files\MyApp.exe” -InstallationType “Install” -Arguments “/silent /logfile:C:\Logs\MyApp\log.log”
    Installs the SETUP file MyApp.exe.

Logging

DS_ClearAllMainEventLogs

Use this function to clear all events logs found on the local operating system. One instance where you may use this function is when you are preparing a new master image. Execute this function as one of the last tasks.

  • Description:
    Clear all main event logs.
  • Example:
    DS_ClearAllMainEventLogs
    Loops through all event logs on the local system and clears (deletes) all entries in each of the logs founds.

DS_WriteLog

Use this function to write lines to the main log file. This function is also used by all other functions. If no log file is specified, a default log file C.\Logs\DefaultLogFile_%Date%_%Time%.log is created. Also the directory C:\Logs is created if it does not exist.

  • Description:
    Write text to this script’s log file.
  • Parameters:
    • InformationType
      This parameter contains the information type prefix. Possible prefixes and information types are:
      I = Information
      S = Success
      W = Warning
      E = Error
      – = No status
    • Text
      This parameter contains the text (the line) you want to write to the log file. If text in the parameter is omitted, an empty line is written.
    • LogFile
      This parameter contains the full path, the file name and file extension to the log file (e.g. C:\Logs\MyApps\MylogFile.log)
  • Example 1:
    DS_WriteLog -InformationType “I” -Text “Copy files to C:\Temp” -LogFile “C:\Logs\MylogFile.log”
    Writes a line containing information to the log file.
  • Example 2:
    DS_WriteLog -InformationType “E” -Text “An error occurred trying to copy files to C:\Temp (error: $($Error[0]))” -LogFile “C:\Logs\MylogFile.log”
    Writes a line containing error information to the log file.
  • Example 3:
    DS_WriteLog -InformationType “-” -Text “” -LogFile “C:\Logs\MylogFile.log”
    Writes an empty line to the log file.

DS_WriteToEventLog

Use this function to write an entry to a specific event log. An entry can be of the type Information, Warning or Error. This function also automatically creates new event logs in case a non-existing event log has been defined. The same goes for unknown event sources; these are also automatically created in case they do not exist.

  • Description:
    Write an entry into the Windows event log. New event logs as well as new event sources are automatically created.
  • Parameters:
    • EventLog
      This parameter contains the name of the event log the entry should be written to (e.g. Application, Security, System or a custom one).
    • Source
      This parameter contains the source (e.g. MyScript).
    • EventID
      This parameter contains the event ID number (e.g. 3000).
    • Type
      This parameter contains the type of message. Possible values are: Information | Warning | Error
    • Message
      This parameter contains the event log description explaining the issue.
  • Example 1:
    DS_WriteToEventLog -EventLog “System” -Source “MyScript” -EventID “3000” -Type “Error” -Message “An error occurred”
    Write an error message to the System event log with the source MyScript and event ID 3000. The unknown source MyScript is automatically created.
  • Example 2:
    DS_WriteToEventLog -EventLog “Application” -Source “Something” -EventID “250” -Type “Information” -Message “Information: action completed successfully”
    Write an information message to the Application event log with the source Something and event ID 250. The unknown source Something is automatically created.
  • Example 3:
    DS_WriteToEventLog -EventLog “MyNewEventLog” -Source “MyScript” -EventID “1000” -Type “Warning” -Message “Warning. There seems to be an issue”
    Write an warning message to the event log called MyNewEventLog with the source MyScript and event ID 1000. The unknown event log MyNewEventLog and source MyScript are automatically created.

Miscellaneous

DS_SendMail

Use this function to send an e-mail to one or more recipients. This function does not include the option to attach a file.

  • Description:
    Send an e-mail
  • Parameters:
    • Sender
      This parameter contains the e-mail address of the sender (e.g. mymail@mydomain.com).
    • Recipients
      This parameter contains the e-mail address or addresses of the recipients, for example:

      • One recipient: <name>@mycompany.com”
      • Multiple recipients: “<name>@mycompany.com”, “<name>@mycompany.com”)
    • Subject
      This parameter contains the subject of the e-mail.
    • Text
      This parameter contains the body (= content / text) of the e-mail.
    • SMTPServer
      This parameter contains the name or the IP-address of the SMTP server (e.g. smtp.mycompany.com or 192.168.0.110).
  • Example 1:
    DS_SendMail -Sender “me@mycompany.com” -Recipients “someone@mycompany.com” -Subject “Something important” -Text “This is the text for the e-mail” -SMTPServer “smtp.mycompany.com”
    Sends an e-mail to one recipient.
  • Example 2:
    DS_SendMail -Sender “me@mycompany.com” -Recipients “someone@mycompany.com”,”someoneelse@mycompany.com” -Subject “Something important” -Text “This is the text for the e-mail” -SMTPServer “smtp.mycompany.com”
    Sends an e-mail to two recipients.
  • Example 3:
    DS_SendMail -Sender “Dennis Span <me@mycompany.com>” -Recipients “someone@mycompany.com”,”someoneelse@mycompany.com” -Subject “Something important” -Text “This is the text for the e-mail” -SMTPServer “smtp.mycompany.com”
    Sends an e-mail to two recipients with the sender’s name included in the sender’s e-mail address.
  • Example 4:
    DS_SendMail -Sender “Error report <me@mycompany.com>” -Recipients “someone@mycompany.com”,”someoneelse@mycompany.com” -Subject “Something important” -Text “This is the text for the e-mail” -SMTPServer “smtp.mycompany.com”
    Sends an e-mail to two recipients with a description included in the sender’s e-mail address.

Printing

DS_InstallPrinterDriver

Use this function to install a printer driver. For a better understanding of printer drivers, please see my article Printer Drivers Installation and Troubleshooting Guide.

  • Description:
    Install a Windows printer driver.
  • Parameters:
    • Name
      This parameter contains the name of the printer driver as found in the accompanying INF file, for example HP Universal Printing PCL 6 (v5.5.0).
    • Path
      This parameter contains the path to the printer driver, for example C:\Temp\PrinterDrivers\HP\UP_PCL6.
    • INF_Name
      This parameter contains the name of the INF file located within the directory defined in the variable Path, for example hpcu130u.INF.
  • Example:
    DS_InstallPrinterDriver -Name “HP Universal Printing PCL 6 (v5.5.0)” -Path “C:\Temp\PrinterDrivers\HP\UP_PCL6” -INF_Name “hpcu130u.INF”
    Installs the printer driver HP Universal Printing PCL 6 (v5.5.0) using the file in the directory C:\Temp\PrinterDrivers\HP\UP_PCL6.

Registry

DS_CreateRegistryKey

Use this function to create a new registry key. This function is also used by the function DS_SetRegistryValue in case the specified registry key does not exist.

  • Description:
    Create a registry key.
  • Parameter:
    • RegKeyPath
      This parameter contains the registry path, for example hklm:\Software\MyApp.
  • Example:
    DS_CreateRegistryKey -RegKeyPath “hklm:\Software\MyApp”
    Creates the new registry key hklm:\Software\MyApp.

DS_DeleteRegistryKey

Use this function to delete a registry key.

  • Description:
    Delete a registry key.
  • Parameter:
    • RegKeyPath
      This parameter contains the registry path, for example hklm:\Software\MyApp.
  • Example:
    DS_DeleteRegistryKey -RegKeyPath “hklm:\Software\MyApp”
    Deletes the registry key hklm:\Software\MyApp.

DS_DeleteRegistryValue

Use this function to delete a registry value. This can be a value of any type such as REG_SZ (= string), DWORD, binary, etc.

  • Description:
    Delete a registry value. This can be a value of any type (e.g. REG_SZ, DWORD, etc.).
  • Parameters:
    • RegKeyPath
      This parameter contains the registry path (for example hklm:\SOFTWARE\MyApp)
    • RegValueName
      This parameter contains the name of the registry value that is to be deleted (for example MyValue).
  • Example:
    DS_DeleteRegistryValue -RegKeyPath “hklm:\SOFTWARE\MyApp” -RegValueName “MyValue”
    Deletes the registry value MyValue from the registry key hklm:\SOFTWARE\MyApp.

DS_ImportRegistryFile

Use this function to import a registry file (*.reg).

  • Description:
    Import a registry (*.reg) file into the registry.
  • Parameter:
    • FileName
      This parameter contains the full path, file name and file extension of the registry file, for example C:\Temp\MyRegFile.reg.
  • Example:
    DS_ImportRegistryFile -FileName “C:\Temp\MyRegFile.reg”
    Imports registry settings from the file C:\Temp\MyRegFile.reg.

DS_RenameRegistryKey

Use this function to rename a registry key.

  • Description:
    Rename a registry key.
  • Parameters:
    • RegKeyPath
      This parameter contains the registry path that needs to be renamed (for example hklm:\Software\MyRegKey).
    • NewName
      This parameter contains the new name of the last part of the registry path that is to be renamed (for example MyRegKeyNew).
  • Example:
    DS_RenameRegistryKey -RegKeyPath “hklm:\Software\MyRegKey” -NewName “MyRegKeyNew”
    Renames the registry path hklm:\Software\MyRegKey to hklm:\Software\MyRegKeyNew. The parameter NewName only requires the last part of the registry path without specifying the entire registry path.

DS_RenameRegistryValue

Use this function to rename a registry value (any data type).

  • Description:
    Rename a registry value (all data types).
  • Parameters:
    • RegKeyPath
      This parameter contains the full registry path (for example hklm:\SOFTWARE\MyApp).
    • RegValueName
      This parameter contains the name of the registry value that needs to be renamed (for example MyRegistryValue).
    • NewName
      This parameter contains the new name of the registry value that is to be renamed (for example MyRegistryValueNewName)
  • Example:
    DS_RenameRegistryValue -RegKeyPath “hklm:\Software\MyRegKey” -RegValueName “MyRegistryValue” -NewName “MyRegistryValueNewName”
    Renames the registry value MyRegistryValue in the registry key hklm:\Software\MyRegKey to MyRegistryValueNewName.

DS_SetRegistryValue

Use this function to create a registry value. All, or at least almost all, data types are supported, such as String, Binary, DWORD, QWORD, MultiString and ExpandString.

  • Description:
    Set a registry value.
  • Parameters:
    • RegKeyPath
      This parameter contains the registry path, for example hklm:\Software\MyApp.
    • RegValueName
      This parameter contains the name of the new registry value, for example MyValue.
    • RegValue
      This parameter contains the value of the new registry entry, for example 1.
    • Type
      This parameter contains the type. Possible options are:
      String | Binary | DWORD | QWORD | MultiString | ExpandString.
  • Example 1:
    DS_SetRegistryValue -RegKeyPath “hklm:\Software\MyApp” -RegValueName “MyStringValue” -RegValue “Enabled” -Type “String”
    Creates a new string value called MyStringValue with the value of Enabled
  • Example 2:
    DS_SetRegistryValue -RegKeyPath “hklm:\Software\MyApp” -RegValueName “MyBinaryValue” -RegValue “01” -Type “Binary”
    Creates a new binary value called MyBinaryValue with the value of 01
  • Example 3:
    DS_SetRegistryValue -RegKeyPath “hklm:\Software\MyApp” -RegValueName “MyDWORDValue” -RegValue “1” -Type “DWORD”
    Creates a new DWORD value called MyDWORDValue with the value of 00000001 (or simply 1).
  • Example 4:
    DS_SetRegistryValue -RegKeyPath “hklm:\Software\MyApp” -RegValueName “MyQWORDValue” -RegValue “1” -Type “QWORD”
    Creates a new QWORD value called MyQWORDValue with the value of 1.
  • Example 5:
    DS_SetRegistryValue -RegKeyPath “hklm:\Software\MyApp” -RegValueName “MyMultiStringValue” -RegValue “Value1″,”Value2″,”Value3” -Type “MultiString”
    Creates a new multistring value called MyMultiStringValue with the value of Value1 Value2 Value3.
  • Example 6:
    DS_SetRegistryValue -RegKeyPath “hklm:\Software\MyApp” -RegValueName “MyExpandStringValue” -RegValue “MyValue” -Type “ExpandString”
    Creates a new expandstring value called MyExpandStringValue with the value of MyValue.

Services

DS_ChangeServiceStartupType

Use this function to change the startup type of a service.

  • Description:
    Change the startup type of a service.
  • Parameters:
    • ServiceName
      This parameter contains the name of the service (not the display name!) to stop, for example Spooler or TermService. Depend services are stopped automatically as well.
    • StartupType
      This parameter contains the required startup type of the service (possible values are: Boot | System | Automatic | Manual | Disabled.
  • Example 1:
    DS_ChangeServiceStartupType -ServiceName “Spooler” -StartupType “Disabled”
    Disables the service Spooler (display name: Print Spooler).
  • Example 2:
    DS_ChangeServiceStartupType -ServiceName “Spooler” -StartupType “Manual”
    Sets the startup type of the service Spooler to manual (display name: Print Spooler).

DS_StopService

Use this function to stop a service. This function also automatically stops all depend services.

  • Description:
    Stop a service (including depend services).
  • Parameter:
    • ServiceName
      This parameter contains the name of the service (not the display name!) to stop, for example Spooler or TermService. Depend services are stopped automatically as well. Depend services do not need to be specified separately. The function will retrieve them automatically.
  • Example:
    DS_StopService -ServiceName “Spooler”
    Stops the service Spooler (display name: Print Spooler).

DS_StartService

Use this function to start a service. This function also automatically starts all depend services.

  • Description:
    Starts a service (including depend services).
  • Parameter:
    • ServiceName:
      This parameter contains the name of the service (not the display name!) to start, for example Spooler or TermService. Depend services are started automatically as well. Depend services do not need to be specified separately. The function will retrieve them automatically.
  • Example:
    DS_StartService -ServiceName “Spooler”
    Starts the service Spooler (display name: Print Spooler).

System

DS_DeleteScheduledTask

Use this function to delete a scheduled tasks on the local machine. Only the name of the tasks needs to be specified. The function, or rather, a second function called DS_GetAllScheduledTaskSubFolders, scans all scheduled tasks on the local system (including those residing in subfolders). So there is no need for you to indicate a subfolder.
This function is based on a PowerShell script I found in the Microsoft Script Center repository (Get scheduled tasks from remote computer) by Microsoft MVP Jaap Brasser.

  • Description:
    Delete a scheduled task.
  • Parameter:
    • Name
      This parameter contains the name of the scheduled task that is to be deleted.
  • Example:
    DS_DeleteScheduledTask -Name “GoogleUpdateTaskMachineCore”
    Deletes the scheduled task GoogleUpdateTaskMachineCore.

DS_GetAllScheduledTaskSubFolders

This function enumerates all schedules tasks on the local system (including tasks residing in subfolders). It is not to be used as a stand-alone function. This function is called by the function DS_DeleteScheduledTask.
This function is based on a PowerShell script I found in the Microsoft Script Center repository (Get scheduled tasks from remote computer) by Microsoft MVP Jaap Brasser.

DS_ReassignDriveLetter

Use this function to re-assign an existing drive letter to a new drive letter.

  • Description:
    Re-assign an existing drive letter to a new drive letter.
  • Parameters:
    • CurrentDriveLetter
      This parameter contains the drive letter that needs to be re-assigned.
    • NewDriveLetter
      This parameter contains the new drive letter that needs to be assigned to the current drive letter.
  • Example:
    DS_ReassignDriveLetter -CurrentDriveLetter “D:” -NewDriveLetter “Z:”
    Re-assigns drive letter D: to drive letter Z:.

DS_RenameVolumeLabel

Use this function to rename the label of an existing volume.

  • Description:
    Rename the volume label of an existing volume.
  • Parameters:
    • DriveLetter
      This parameter contains the drive letter of the volume that needs to be renamed.
    • NewVolumeLabel
      This parameter contains the new name for the volume.
  • Example:
    DS_RenameVolumeLabel -DriveLetter “C:” -NewVolumeLabel “SYSTEM”
    Renames the volume connected to drive C: to SYSTEM.