Documentation is available at https://docs.microsoft.com/en-us/IIS-Administration
"users": {
"administrators": [
"mydomain\\myusername",
"myusername@mycompany.com",
"IIS Administration API Owners"
],
"owners": [
"mydomain\\myusername",
"myusername@mycompany.com",
"IIS Administration API Owners"
]
},
In the following code, replace the path to match your clone location. It first starts the developer command prompt for Visual Studio 2022, publishes the solution and finally, builds the installer at installer\IISAdministrationBundle\bin\x64\Release.
%comspec% /k "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat"
cd /d C:\src\repos\IIS.Administration
msbuild -restore Microsoft.IIS.Administration.sln /t:publish
build\nuget.exe restore installer\IISAdministrationSetup\packages.config -SolutionDirectory installer
msbuild installer /p:configuration=release
There is a blog post to get up and running on Nano Server located at https://blogs.iis.net/adminapi/microsoft-iis-administration-on-nano-server.
JSON request
{
"name": "Contoso1234",
"physical_path": "C:\\inetpub\\wwwroot",
"bindings": [
{
"port": 8080,
"protocol": "http",
"ip_address": "*"
}
]
}
"cors": {
"rules": []
},
"files": {
"locations": [
{
"alias": "inetpub",
"path": "C:\\inetpub",
"claims": [
"read",
"write"
]
}
}
C:\src\repos\IIS.Administration\scripts\Configure-DevEnvironment.ps1 -ConfigureTestEnvironment
var apiClient = new HttpClient(new HttpClientHandler() {
UseDefaultCredentials = true
}, true);
// Set access token for every request
apiClient.DefaultRequestHeaders.Add("Access-Token", "Bearer {token}");
// Request HAL (_links)
apiClient.DefaultRequestHeaders.Add("Accept", "application/hal+json");
var res = await apiClient.GetAsync("https://localhost:55539/api/webserver/websites");
if (res.StatusCode != HttpStatusCode.OK) {
HandleError(res);
return;
}
JArray sites = JObject.Parse(res.Content.ReadAsStringAsync().Result).Value<JArray>("websites");
var newSite = new {
name = "Contoso",
physical_path = @"C:\inetpub\wwwroot",
bindings = new object[] {
new {
port = 8080,
protocol = "http",
ip_address = "*"
}
}
};
res = await apiClient.PostAsync("https://localhost:55539/api/webserver/websites",
new StringContent(JsonConvert.SerializeObject(newSite), Encoding.UTF8, "application/json"));
if (res.StatusCode != HttpStatusCode.Created) {
HandleError(res);
return;
}
JObject site = JObject.Parse(res.Content.ReadAsStringAsync().Result);
var updateObject = new {
bindings = new object[] {
new {
port = 8081,
protocol = "http",
ip_address = "*"
}
}
};
var updateRequest = new HttpRequestMessage(new HttpMethod("PATCH"),
"https://localhost:55539" + site["_links"]["self"].Value<string>("href"));
updateRequest.Content = new StringContent(JsonConvert.SerializeObject(updateObject), Encoding.UTF8, "application/json");
res = await apiClient.SendAsync(updateRequest);
if (res.StatusCode != HttpStatusCode.OK) {
HandleError(res);
return;
}
site = JObject.Parse(res.Content.ReadAsStringAsync().Result);
res = await apiClient.DeleteAsync("https://localhost:55539" + site["_links"]["self"].Value<string>("href"));
There is a utils.ps1 script that demonstrates how to generate an access token from PowerShell.
# Replace the path to match your clone location
$accessToken = C:\src\repos\IIS.Administration\scripts\utils\utils.ps1 Generate-AccessToken -url "https://localhost:55539"
# Supply an access token to run the example
$accessToken = "{Some Access token}"
$headers = @{ "Access-Token" = "Bearer $accessToken"; "Accept" = "application/hal+json" }
$response = Invoke-RestMethod "https://localhost:55539/api/webserver/websites" -UseDefaultCredentials -Headers $headers
$response.websites