How can I use PowerShell to set the default document in IIS? - powershell

I'm configuring a web site using PowerShell and I want to set the default document. How do I do this?

This is one way:
$metabasePath = "IIS://Localhost/W3SVC"
$iisNumber = "12345"
$site = new-object
System.DirectoryServices.DirectoryEntry("$metabasePath/$iisNumber/root")
$site.psbase.Properties["DefaultDoc"].Value =
"newdefdoc.htm," + $site.psbase.Properties["DefaultDoc"].Value
$site.psbase.CommitChanges()
The value returned in $site.psbase.Properties["DefaultDoc"].Value is a comma separated list of documents so you may need to re-jig the order to suit your case. The example above just adds a new default document (newdefdoc.htm) to the top of the list.

Related

Powershell - changing value of returned SQL data variable fails

In Powershell, I am doing a SQL query for a single row of data. Lets say $data for example.
The response from the query a System.Data.DataSet type. Within it, there is a tables property that has the data I need.
$data.Tables
ServerName : Server15
SamAccount : Admin-Server15
LastPWDReset : 1/15/2019 12:00:00 AM
LastPWDResetAttempt :
I don't intend to write this data back out of anything. Instead, I want to display it, and convert the empty "LastPWDResetAttemp" to "NONE" where it is blank.
I thought it would be done like this:
$data.Tables.lastPWDResetAttempt = "None"
but that gives me an error The property 'lastPWDResetAttempt' cannot be found on this object. Verify that the property exists and can be set.
I can't help but think I am missing some conversion from "Dataset" to "String".
I've tried to-string but in doing so, I ended up with just a string of data and not the headings. Nothing I could update, or easily use to build my eventual table.
My work around:
$webdata = "" | select ServerName,SamAccount,LastPWDReset,LastPWDResetAttempt
$webdata.ServerName = $data.tables.servername
$webdata.SamAccount = $data.tables.samaccount
$webdata.LastPWDReset = $data.tables.LastPWDReset
$webdata.LastPWDResetAttempt = $data.tables.LastPWDResetAttempt
$webdata.LastPWDResetAttempt = "Never"
works. I just can't believe there isn't an easier way, nor do I understand why I can view a list of the data, just to not then be able to set it.
I think it is because Tables is an array and does not have the property LastPWDResetAttempt.
You can try the following instead:
$data.Tables[0].Rows[0].LastPWDResetAttempt = "None"
Also I think your workaround, though it may contain more lines of code, is actually a better solution though.

EWS Category search

i've a script on powershell to manage mailbox using EWS, however i'm not able to user the current filters and filter certain categories.
I would like filter categories that start by _ or * and apply to my current filters
$sfRead = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead, $True)
$WIPSubject = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject, "Assigned")
$sfNot = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+Not($WIPSubject)
$sfCollection = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And)
$sfCollection.add($sfRead)
$sfCollection.add($sfNot)
If you want to do a wildcard search on the Subject then I would suggest that you use AQS for queries instead https://msdn.microsoft.com/en-us/library/office/dn579420(v=exchg.150).aspx . SearchFilters don't support wildcards you have the ContainsSubString filter which will find partial string matches https://msdn.microsoft.com/en-us/library/office/dd633645(v=exchg.80).aspx which is the closest.

Powershell EWS Nested search filter

I'm trying to perform a search filter using EWS on a function based on Powershell.
I would like to mix AND & OR due i mix different properties, i've tried the method below but it didn't work as expected:
$sfCollectionAND = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And)
$sfCollectionAND .add($SenderAddress1)
$sfCollectionAND .add($SenderAddress2)
$sfCollectionOR = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::Or)
$sfCollectionOR .add($sfCollectionAND)
$sfCollectionOR .add($ReceiveDate1)
$sfCollectionOR .add($ReceiveDate2)
Basically the filter purpose is 1st gather message between period of time and then exclude 2 senders.

Remove an entry from VM Advanced Config via PowerCLI and ReconfigVM

http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.VirtualMachine.html#reconfigure
I'm writing a script to update the VMX state for virtual machines to comply with some standards, but also want to backup their state in case they need to re restored. The ReconfigVM task works fine, and I can pull the state via ($VM | Get-View).config.extraconfig
What I can't figure out is how to remove items using VirtualMachineConfigSpec.
Let's say I update a value as such.
$ExtraOptions = #{
"isolation.device.connectable.disable"="true";
"log.rotateSize"="100000";
}
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
Foreach ($Option in $ExtraOptions.GetEnumerator()) {
$OptionValue = New-Object VMware.Vim.optionvalue
$OptionValue.Key = $Option.Key
$OptionValue.Value = $Option.Value
$vmConfigSpec.extraconfig += $OptionValue
}
# ...
foreach($vm in $vms){
$vm.ReconfigVM($vmConfigSpec)
}
Now let's say I create a backup hashtable of the config spec for the values prior to changing them. Since these values did not exist prior to the update there's no value prior.
A $null throws an error.
"isolation.device.connectable.disable"=$null;
An empty "" does no update
"isolation.device.connectable.disable"="";
I could simply revert the Boolean values and set integer values to 0, but I'd rather just remove the value from the configuration.
The documentation states the following about extraconfig
Additional configuration information for the virtual machine. This describes a set of modifications to the additional options. An option is removed if the key is present but the value is not set or the value is an empty string. Otherwise, the key is set to the new value.
Configuration keys that would conflict with parameters that are explicitly configurable through other fields in the ConfigSpec object are silently ignored.
EDIT
Passing a whitespace character (i.e. " ") will set the value to false or 0.
Apparently you'd have to download the vmx file (where these options are stored), and then re-upload the modified file while the VM is powered off, and maybe also un-registered.
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.extraconfig = New-Object VMware.Vim.optionvalue
$vmConfigSpec.extraconfig[0].Key="cloud.uuid"
$vmConfigSpec.extraconfig[0].Value=""
$vm.ReconfigVM($vmConfigSpec)
Taking the plus sign out along with value of nothing "" should remove the line from the vmx file.

How to modify internalname in Sharepoint 2010 list field

I need to change the internalname for a sharepoint 2010 list item field. For some reason, our migration software renamed it during 2007->2010 migration and this field is referenced by other processes so we need the internalname back to the original. This field exists in over 200 lists in the migrated site so we need a means to do this programatically - powershell preferred.
$newInternalName = "yourInternalFieldName"
$displayName = "oldDisplayName"
$SPWebApp = Get-SPWebApplication "http://yourwebapp"
foreach (SPList $currList in $SPWebApp.Lists)
{
foreach (SPField $fld in $currList.Fields) #you could potentially use a different command here to get the field more efficiently
{
if ($fld.Name == $displayName)
{
#The boolean in the parameter list is for required/non-required field $currList.Fields.Add($newInternalName,Microsoft.SharePoint.SPFieldType.Text,$False)
foreach (SPListItem $item in $currList.Items)
{
$item[$newInternalName] = $item[$displayName]
$item[$newInternalName].Title = $displayName #I'm assuming you want to keep the display name the same
$item.Update()
}
Break #since you've already fixed the column for this list no need to keep going through the fields
# optional delete unwanted column
# $currList.Fields.Delete($displayName)
# $currList.Update()
}
}
}
As far as I know, you cannot change the internal name of a field once it has been created. Here I create a new field with the correct internal name and copy over the values. I don't have access to a server with Powershell today so I wasn't able to test this, but this should be very close to what you need. You may need to tweak it a bit based on what type of field you're dealing with, if you want to use a different Add function, and/or you want to delete the old field.
The enumeration to select the type of the field in the Add function is defined here:
http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.spfieldtype(v=office.14).aspx
There are a couple of overloads for the Add function so if the one I used doesn't work for you, you might wanna use one of these others
http://msdn.microsoft.com/en-us/library/office/aa540133(v=office.14).aspx