How to use PowerShell to modify a host file
The following command adds a record to the host file and lets/sps2010/hostheader1/this URL point to the server itself.
Copy Code code as follows:
$url = "http://sps2010/hostheader1/"
if (get-content $env: windir\system32\drivers\etc\hosts |? {$_-imatch "\s$url"}) -eq $null) {"' n127.0.0.1 $url" | Out-file-filepath "$env: Windir\system32\drivers\etc\hosts"-append-encoding ASCII}
A PowerShell method call
No time system of learning PowerShell, can only now learn to use. This function call took me more than half an hour to finish. Oh.
You don't laugh at me, hehe.
In this example, the following points are included in the PowerShell:
method of calling static functions
The specified method of the enumeration type
Null value
Boolean value
PS C:\Users\administrator. vsat> $SPUtility = [Microsoft.Sharepoint.Utilities.SPUtility]
PS C:\Users\administrator. vsat> $SPPrincipalType = [Microsoft.Sharepoint.Utilities.SPPrincipalType]
PS C:\Users\administrator. Vsat> $obj = $SPUtility:: Resolvewindowsprincipal ($null, $owebapp, "Vsat\administrator", $SPPrincipalType:: user,$ False)
PS C:\Users\administrator. vsat> $obj
principaltype : User
LoginName : Vsat\administrator
issharepointgroup:false
principalid :-1
Email : Administrator@vsat.bizapp
sipaddress :
Mobile :
DisplayName: Administrator
Department :
jobtitle :
How do I determine the current version of PowerShell?
Run the following command:
Get-host | Select-object Version
If the installation is PowerShell 3.0, then the output should be: