Home>

How to modify host file using powershell

The following command, Added a record for the host file, Let/sps2010/hostheader1/this url point to the server itself.

$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

There is no time to learn powershell systematically. This function call took me over half an hour to get it done. Ha ha.

Don't laugh at me, Ha ha.

In this example, Includes the following points in powershell:

How to call a static function

How to specify enumerated types

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:[email protected]
sipaddress:
mobile:
displayname:administrator
department:
jobtitle:

How to determine the current version of powershell

Run the following command:

get-host | select-object version

If powershell 3.0 is installed, the output should be:

version
-------
3.0
  • Previous Analysis of the usage of date and time selection dialog in Android
  • Next windowonload usage guide