To combine, format, join or concat strings in PowerShell
You can concat strings in PowerShell by using the + operator, but like in C#, I think it is better to use a formatting approach by using the –f string operator: [-f operator] PS
You can concat strings in PowerShell by using the + operator, but like in C#, I think it is better to use a formatting approach by using the –f string operator: [-f operator] PS
If you want to combine the physical path C:\ with a relative path “Temp” in PowerShell, Use Join-Path PS C:\Users\rLisdonk> Join-Path "C:\" "\Temp" C:\Temp PS C:\Users\rLisdonk> Join-Path "C:\" "Temp" C:\Temp PS C:\Users\rLisdonk> Join-Path "C:"
If you want to grant “Log on as a service” rights to a user account, using PowerShell you can use the secedit.exe tool, using a *.inf security template file. [Script] secedit /import /db secedit.sdb
To show the password from the Get-Credentials cmdlet in plaintext, use the following PowerShell script: $credential = Get-Credential [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($credential .Password))
If you want to create service accounts with PowerShell and the result must be like: Use this PowerShell script: # To run this script use: & "C:\Users\rLisdonk\Desktop\ToServer\Test.ps1" $computerName = "MyComputerName” $serviceAccountWebName = "saAsaWeb"
If you want to use the systems “%PROGRAMFILES%” folder in PowerShell, use: $rootInstallationFolder = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFiles) $rootInstallationFolder Result C:\Program Files (x86) Note Because SpecialFolders is a nested type in System.Environment, you must use the “+”
If you want to script a SQL Server database and want to include content for the lookup tables, you can use Microsoft.SqlServer.Management.Smo in C#: Add reference to Microsoft.SqlServer.Smo Add reference to Microsoft.SqlServer.ConnectionInfo Add reference to
You can use VSCmdShell to run a PowerShell script from within Visual Studio 2008. After installing VSCmdShell you can change the startup folder (working folder) of the powershell window: Tools > Options > Power Toys
If you want to install a *.msi package by first un-installing the product and then installing, you can use the following PowerShell script: Use System.Diagnostics.Process.Start function and the WaitForExit function to make sure the product
If you want to copy all *.txt files in folder C:\Source to C:\Destination preserving the directory structure: Source files C:\Source\Test1.cmd C:\Source\Test1.txt C:\Source\Dir1\Test2.txt PowerShell statement Copy-Item "C:\Source" "C:\Destination" -filter "*.txt" -recurse –force Result