The package signature reports Root element is missing error - signature

Signing a package with a powershell reports an error
Error details
Exception calling "Sign" with "2": "Root element is missing."
At C:\Users...\sign.ps1
+ [Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.PackageManager]::Sign...
+
+CategoryInfo : NotSpecified:(:)[].MethodInvocationException
+FullyQualifiedErrorId : XmlException
The script code is as follows
$ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "Microsoft.Windows.Kits.Hardware.objectmodel.dll")
$ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "Microsoft.Windows.Kits.Hardware.objectmodel.submission.dll")
# The package to sign.
$packageFile = 'arg[0]'
$store = new-object -typename System.Security.Cryptography.X509Certificates.X509Store -ArgumentList "My", 1
$store.open(4);
foreach($mCert in $store.Certificates)
{
[Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.PackageManager]::Sign($packageFile, $mCert)
}
operating system
windows server 2008 R2 sp1
Can you please tell where i am going wrong.

Related

Trouble Accessing Newly attached disk in DSC on an azure VM

I have an issue with a DSC config i'm trying to use to install and run a mongo service on an Azure VM.
When the DSC runs on the initial deployment of the VM, the secondary disk 'F' is attached and formatted successfully, however... i receive an error when trying to create directories on the new disk:
Error message: \"DSC Configuration 'Main' completed with error(s).
Cannot find drive. A drive with the name 'F' does not exist.
The PowerShell DSC resource '[Script]SetUpDataDisk' with SourceInfo 'C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\MongoDSC.0\\MongoDSC.ps1::51::2::Script' threw one or more non-terminating errors while running the Set-TargetResource functionality.
Here is my DSC script :
Configuration Main
{
Param ( [string] $nodeName )
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xStorage
Node $nodeName
{
xWaitforDisk Disk2
{
DiskId = 2
RetryIntervalSec = 60
RetryCount = 60
}
xDisk FVolume
{
DiskId = 2
DriveLetter = 'F'
FSLabel = 'MongoData'
DependsOn = "[xWaitforDisk]Disk2"
}
Script SetUpDataDisk{
TestScript ={
return Test-Path "f:\mongoData\"
}
SetScript ={
#set up the directories for mongo
$retries = 0
Do{
$mountedDrive = Get-Volume | Where DriveLetter -eq 'F'
if($mountedDrive -eq $null)
{
Start-Sleep -Seconds 60
$retries = $retries + 1
}
}While(($mountedDrive -eq $null) -and ($retries -lt 60))
$dirName = "mongoData"
$dbDirName = "db"
$logDirName = "logs"
##! ERROR THROWN FROM THESE LINES
New-Item -Path "F:\$dirName" -ItemType Directory
New-Item -Path "F:\$dirName\$dbDirName" -ItemType Directory
New-Item -Path "F:\$dirName\$logDirName" -ItemType Directory
}
GetScript = {#{Result = "SetUpDataDisk"}}
DependsOn = "[xDisk]FVolume"
}
}
}
The annoying thing is that if i run the deployment again everything works with no errors, i have put a loop in to try and wait for the disk to be ready but this still throws the error. I'm very new to DSC so any pointers would be helpful.
It seems xDiskAccessPath can be used for that:
<#
.EXAMPLE
This configuration will wait for disk 2 to become available, and then make the disk available as
two new formatted volumes mounted to folders c:\SQLData and c:\SQLLog, with c:\SQLLog using all
available space after c:\SQLData has been created.
#>
Configuration Example
{
Import-DSCResource -ModuleName xStorage
Node localhost
{
xWaitforDisk Disk2
{
DiskId = 2
RetryIntervalSec = 60
RetryCount = 60
}
xDiskAccessPath DataVolume
{
DiskId = 2
AccessPath = 'c:\SQLData'
Size = 10GB
FSLabel = 'SQLData1'
DependsOn = '[xWaitForDisk]Disk2'
}
xDiskAccessPath LogVolume
{
DiskId = 2
AccessPath = 'c:\SQLLog'
FSLabel = 'SQLLog1'
DependsOn = '[xDiskAccessPath]DataVolume'
}
}
}
https://github.com/PowerShell/xStorage/blob/dev/Modules/xStorage/Examples/Resources/xDiskAccessPath/1-xDiskAccessPath_InitializeDataDiskWithAccessPath.ps1

PowerShell Scheduled Task RegisterTask Method

I am attempting to use powershell v2.0 to create a scheduled task using the Schedule.Service Com Object.
I have created ps1 file but we get an error when we execute it that is eluding me.
Here is the code:
param(
[string]$xmlFilePath = $(throw "-xmlFilePath is required"),
[string]$server = "localhost",
[string]$taskFolderName = "\"
)
try {
$xmlContent = [xml] (Get-Content $xmlFilePath);
$taskScheduler = New-Object -ComObject Schedule.Service
$taskScheduler.Connect($server)
$taskFolder = $taskScheduler.GetFolder($taskFolderName);
$taskFolder.RegisterTask($xmlFilePathl, $xmlContent, 6, "<user name>", "<password>", 1);
}
catch {
$Exception = $_.Exception;
while ($Exception.Message -ne $null)
{
Write-Error $Exception.Message;
$Exception = $Exception.InnerException;
}
return;
}
Runnig this locally or remotely gives the same result.
The error is as follows:
C:\temp\CreateScheduledTaskFromXML.ps1 : Exception calling "RegisterTask" with "6" argument(s): "(1,2)::"
At line:1 char:33
+ .\CreateScheduledTaskFromXML.ps1 <<<< -server DEVBDAPP12 -xmlFilePath "C:\Temp\collectors\adcomputer\Discovery.Ser
vices.ActiveDirectory.Computer.Collector.xml"
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CreateScheduledTaskFromXML.ps1
What does this mean "Exception calling "RegisterTask" with "6" argument(s): "(1,2)::""
The failure is occuring on the registertask method but the error does not make sense.
This use is based on the following MSDN article
http://msdn.microsoft.com/en-us/library/windows/desktop/aa382575(v=vs.85).aspx
As a side not, We cannot update this machine to powershell 3.0 or use the powerpack at this time and would like to avoid schtask.exe so these are not options
If anyone has any insight it would be greatly appreciated.
If you just type :
$taskScheduler = New-Object -ComObject Schedule.Service
$taskScheduler.Connect("localhost")
$taskFolder = $taskScheduler.GetFolder("\")
$taskFolder.RegisterTask
You receive :
IRegisteredTask RegisterTask (string, string, int, Variant, Variant, _TASK_LOGON_TYPE, Variant)
There are 7 arguments, this meas that you miss one argument. If you have a look at Microsoft documentation the call looks like this :
HRESULT RegisterTask(
[in] BSTR path,
[in] BSTR xmlText,
[in] LONG flags,
[in] VARIANT userId,
[in] VARIANT password,
[in] TASK_LOGON_TYPE logonType,
[in, optional] VARIANT sddl,
[out] IRegisteredTask **ppTask
);
So I would try to add $null as the last argument (security descriptor) :
$taskFolder.RegisterTask($xmlFilePathl, $xmlContent, 6, "<user name>", "<password>", 1, $null)
I was able to figure out this problem. First was the first argument in the RegisterTask. I was interpreting this as the folder in the Task scheduler. However, this is not the folder but the task name. Second, with the help from some of the comments and the validation flag, I found that the second argument needs to be a string type and not xml type. Finally, I had to add a 7th argument of null to fullfill the method signature: Thanks for all your help
Here is the updated code that works:
param(
[string]$taskName = $(throw "-taskName is required"), #complete path for the scheduled task
[string]$xmlFilePath = $(throw "-xmlFilePath is required"),
[string]$server = "localhost", # Only works with Servers it can access. Use WinRM for cross domain request
[string]$taskFolderName = "\"
)
$value = $null;
try {
$xmlContent = [string](Get-Content $xmlFilePath);
$taskScheduler = New-Object -ComObject Schedule.Service
$taskScheduler.Connect($server)
$taskFolder = $taskScheduler.GetFolder($taskFolderName);
$value = $taskFolder.RegisterTask($taskName, $xmlContent, 6, "<username>", "<password>", 1, $null);
}
catch {
$Exception = $_.Exception;
while ($Exception.Message -ne $null)
{
Write-Error $Exception.Message;
$Exception = $Exception.InnerException;
}
return;
}

(Part2) SharePoint 2010, Powershell - Loop through all Document Libraries, create view and set it as default.

This is a query leading on from another that was very kindly worked on by #marek-grzenkowicz.
Issue 1) The script is generating an error when it runs. It was mentioned that you can't modify an element of the collection that is being enumerated. Can you show me how to work around this? Despite changes being made to avoid the problem it's still happening
An error occurred while enumerating through a collection: Collection was modified; enumera tion operation may not execute.. At C:\Users\quickdev1\Documents\LoopThroughAl lLibrariesCreateView.ps1:7 char:10
+ foreach <<<< ($list in $web.Lists) {
+ CategoryInfo : InvalidOperati on: (Microsoft.Share...on+SPEnumerator:S PEnumerator) [], RuntimeException
+ FullyQualifiedErrorId : BadEnumeration
Issue 2) I would like to put in some logic to check if an existing view is already there with the name "Detailed" and if so to skip that Library but I'm not sure how to achieve it.
If anyone could help it would be awesome.
Thanks,
Ashley
Full Script
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$siteURL = "http://sp14fdev01/"
$site = Get-SPSite($siteURL)
foreach($web in $site.AllWebs) {
foreach($list in $web.Lists) {
if($list.BaseType -eq "DocumentLibrary") {
// the variables `$web` and `$list` already reference the objects you need
//$site = New-Object Microsoft.SharePoint.SPSite($SiteURL) ;
//$web = $site.OpenWeb($SiteURL);
// new instance of the list is necessary to avoid the error "Collection was modified"
$newList = $web.Lists.item($list.ID);
$viewfields = New-Object System.Collections.Specialized.StringCollection
$viewfields.Add("DocIcon")
$viewfields.Add("LinkFilename")
$viewfields.Add("_UIVersionString")
$viewfields.Add("FileSizeDisplay")
$viewfields.Add("Created")
$viewfields.Add("Modified")
$viewfields.Add("Editor")
[void]$newList.Views.Add("Detailed", $viewfields, "", 100, $true, $true)
$newList.Update();
// setting the default view
$view=$newList.Views["Detailed"]
$view.DefaultView = $true
$view.Update()
}
}
$web.Dispose();
}
$site.Dispose();
You will have to use a for-loop instad of a foreach since you are modifying the collection you are looping over.
Like this:
foreach($web in $site.AllWebs)
{
$listCounter = $web.Lists.Count
for($i=0;$i -le $listCounter;$i++)
{
$list = $web.Lists[$i]
//etc....
}
}

How do I download all SharePoint 2010 Language Packs using Powershell?

I would really like to be able to download all SharePoint 2010 Language Packs easily using a powershell script.
Downloading the SharePoint Language Packs will enable automated and scripted SharePoint installation.
Here's a script I put together based on this script by Ryan Dennis:
Import-Module BitsTransfer
## Prompt for the destination path
$DestPath = Read-Host -Prompt "- Enter the destination path for downloaded files"
## Check that the path entered is valid
If (Test-Path "$DestPath" -Verbose)
{
## If destination path is valid, create folder if it doesn't already exist
$DestFolder = "$DestPath\LanguagePacks"
New-Item -ItemType Directory $DestFolder -ErrorAction SilentlyContinue
}
Else
{
Write-Warning " - Destination path appears to be invalid."
## Pause
Write-Host " - Please check the path, and try running the script again."
Write-Host "- Press any key to exit..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
break
}
## We use the hard-coded URL below, so that we can extract the filename (and use it to get destination filename $DestFileName)
## Note: These URLs are subject to change at Microsoft's discretion.
$UrlList = #{
"http://download.microsoft.com/download/A/6/C/A6C2FAE9-58A4-410D-81E0-682E8CBF3D18/ServerLanguagePack.exe" = "ar"; #Arabic
"http://download.microsoft.com/download/0/D/B/0DB91457-43D2-4BCC-A7AF-8559C3E3E1CF/ServerLanguagePack.exe" = "eu"; #Basque
"http://download.microsoft.com/download/9/1/C/91CFFA84-3A8C-4B2B-BD1F-AF77073C832D/ServerLanguagePack.exe" = "bg"; #Bulgarian
"http://download.microsoft.com/download/0/7/B/07B06744-859A-40CF-84BB-4C8113F9FB75/ServerLanguagePack.exe" = "ca"; #Catalan
"http://download.microsoft.com/download/D/F/C/DFCC90EE-FC55-4EC3-8618-7A2ED0B6F20F/ServerLanguagePack.exe" = "zh"; #Chinese Simplified
"http://download.microsoft.com/download/5/D/E/5DE5B04D-DA7E-41DD-8BB5-FE7BF02630B8/ServerLanguagePack.exe" = "zh-ch"; #Chinese Traditional
"http://download.microsoft.com/download/B/6/B/B6B2439C-EB60-4361-AB83-71CB6B890ADE/ServerLanguagePack.exe" = "hr"; #Croatian
"http://download.microsoft.com/download/7/B/6/7B67B8FC-81C6-446A-9681-897C0888D592/ServerLanguagePack.exe" = "cs"; #Czech
"http://download.microsoft.com/download/C/D/7/CD76DD3E-95E4-4504-93CF-F7CD6D8B7CF5/ServerLanguagePack.exe" = "cs"; #Danish
"http://download.microsoft.com/download/D/8/C/D8C7212B-6DFE-439D-B7D6-EFB35D66041E/ServerLanguagePack.exe" = "nl-nl"; #Dutch
"http://download.microsoft.com/download/1/7/F/17F6BB3B-662F-4555-9760-DB44D3B3F6A4/ServerLanguagePack.exe" = "en-us"; #English
"http://download.microsoft.com/download/4/4/6/446DDD4D-DC67-4663-B7C5-CCFA79316703/ServerLanguagePack.exe" = "et"; #Estonian
"http://download.microsoft.com/download/1/1/6/116C7960-6DFB-468E-BBCB-15E8706783F3/ServerLanguagePack.exe" = "fi"; #Finnish
"http://download.microsoft.com/download/8/0/B/80B8DB8F-D863-4DD9-98E0-A3698510EF13/ServerLanguagePack.exe" = "fr-fr"; #French
"http://download.microsoft.com/download/D/0/F/D0FE84CB-B591-4D5E-9406-CBA2476D4A94/ServerLanguagePack.exe" = "gl"; #Galician
"http://download.microsoft.com/download/7/3/8/738597D9-2817-46D7-8F70-7FBBEE73ABCF/ServerLanguagePack.exe" = "de-de"; #German
"http://download.microsoft.com/download/5/F/0/5F03CC80-D10A-43D5-AA1D-E84C6C077E2C/ServerLanguagePack.exe" = "el"; #Greek
"http://download.microsoft.com/download/D/1/0/D10A5EC6-6C6B-4C4B-9FF1-A662B397E850/ServerLanguagePack.exe" = "he"; #Hebrew
"http://download.microsoft.com/download/7/9/5/795A36AA-D414-4D67-A84D-6815D2FB5A88/ServerLanguagePack.exe" = "hi"; #Hindi
"http://download.microsoft.com/download/F/D/B/FDB09771-D7FF-4123-A66D-2F0A58687E90/ServerLanguagePack.exe" = "hu"; #Hungarian
"http://download.microsoft.com/download/A/8/4/A843E91B-7AEE-47B4-A144-49F525DEBD9D/ServerLanguagePack.exe" = "it-it"; #Italian
"http://download.microsoft.com/download/9/4/D/94DDA001-2059-4F02-8810-8662C1098F8D/ServerLanguagePack.exe" = "ja"; #Japanese
"http://download.microsoft.com/download/F/C/D/FCD57DCD-2BFB-4638-94A3-583AD688CB4D/ServerLanguagePack.exe" = "kk"; #Kazakh
"http://download.microsoft.com/download/B/9/D/B9DB186A-8126-49A9-AFA8-C6D63F12AA40/ServerLanguagePack.exe" = "ko"; #Korean
"http://download.microsoft.com/download/3/E/D/3EDD2930-7BEC-4490-B917-7A49CBA7C5E5/ServerLanguagePack.exe" = "lv"; #Latvian
"http://download.microsoft.com/download/E/E/E/EEE0F34F-94D1-4202-B0D0-213C93E20536/ServerLanguagePack.exe" = "lt"; #Lithuanian
"http://download.microsoft.com/download/D/5/9/D596FB84-8ED3-44A4-88D1-FDD4798E226A/ServerLanguagePack.exe" = "no-no"; #Norwegian
"http://download.microsoft.com/download/B/F/1/BF1F45F4-44A8-453D-882D-03BAC1F6A0B5/ServerLanguagePack.exe" = "pl"; #Polish
"http://download.microsoft.com/download/6/9/F/69F59A23-C22F-4B22-9D72-790E84F6070E/ServerLanguagePack.exe" = "pt-br"; #Portugese (Brazil)
"http://download.microsoft.com/download/0/E/F/0EF8F011-89A6-43AE-BD52-090918750432/ServerLanguagePack.exe" = "pt-pt"; #Portugese (Portugal)
"http://download.microsoft.com/download/8/8/0/880A4C0E-25CA-43B5-84EF-A788FA462AB2/ServerLanguagePack.exe" = "ro"; #Romanian
"http://download.microsoft.com/download/2/6/D/26D339A3-0304-4B66-8062-98BDC0E0D413/ServerLanguagePack.exe" = "ru"; #Russian
"http://download.microsoft.com/download/F/D/2/FD2B1BA8-9841-46F9-A4A7-B97294554249/ServerLanguagePack.exe" = "sr-sp"; #Serbian (Latin)
"http://download.microsoft.com/download/0/E/7/0E7A8426-7797-48F9-B396-AA96ADD1D899/ServerLanguagePack.exe" = "sk"; #Slovak
"http://download.microsoft.com/download/0/3/5/035FD96F-04B1-4461-B8E9-6492654C8549/ServerLanguagePack.exe" = "sl"; #Slovenian
"http://download.microsoft.com/download/0/D/5/0D547EA0-C094-4D06-BE15-F5111A1D4642/ServerLanguagePack.exe" = "es-mx" #Spanish
"http://download.microsoft.com/download/5/2/9/5296BCC9-F0ED-461F-9E22-8A816DEC75C8/ServerLanguagePack.exe" = "sv-se"; #Swedish
"http://download.microsoft.com/download/E/E/A/EEA4DC8B-4979-44C5-AF5E-E326DA04661C/ServerLanguagePack.exe" = "th"; #Thai
"http://download.microsoft.com/download/2/1/1/2118AF0D-A747-486E-A5BB-6B35E5588247/ServerLanguagePack.exe" = "tr"; #Turkish
"http://download.microsoft.com/download/5/9/D/59DEC052-7E29-4F40-A27A-9AA94A8AAA1A/ServerLanguagePack.exe" = "uk" #Ukranian
}
ForEach ($Url in $UrlList.Keys)
{
$languageCode = $UrlList[$Url]
$DestFileName = $Url.Split('/')[-1]
Try
{
$LanguageDestFolder = "$DestFolder\$languageCode"
New-Item -ItemType Directory $LanguageDestFolder -ErrorAction SilentlyContinue
## Check if destination file already exists
If (!(Test-Path "$LanguageDestFolder\$DestFileName"))
{
## Begin download
Start-BitsTransfer -Source $Url -Destination $LanguageDestFolder\$DestFileName -DisplayName "Downloading `'$DestFileName`' to $LanguageDestFolder" -Priority High -Description "From $Url..." -ErrorVariable err
If ($err) {Throw ""}
}
Else
{
Write-Host " - File $DestFileName already exists, skipping..."
}
}
Catch
{
Write-Warning " - An error occurred downloading `'$DestFileName`'"
break
}
}
## View the downloaded files in Windows Explorer
Invoke-Item $DestFolder
## Pause
Write-Host "- Downloads completed, press any key to exit..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

How can I change the IP address of all sites in IIS6 using powershell 1.0?

Using Powershell 1.0 under Windows Server 2003 with IIS 6.
I have about 200 sites that I would like to change the IP address for (as listed in the website properties on the "website" tab in the "Web site identification" section "IP address" field.
I found this code:
$site = [adsi]"IIS://localhost/w3svc/$siteid"
$site.ServerBindings.Insert($site.ServerBindings.Count, ":80:$hostheader")
$site.SetInfo()
How can I do something like this but:
Loop through all the sites in IIS
Not insert a host header value, but change an existing one.
The following PowerShell script should help:
$oldIp = "172.16.3.214"
$newIp = "172.16.3.215"
# Get all objects at IIS://Localhost/W3SVC
$iisObjects = new-object `
System.DirectoryServices.DirectoryEntry("IIS://Localhost/W3SVC")
foreach($site in $iisObjects.psbase.Children)
{
# Is object a website?
if($site.psbase.SchemaClassName -eq "IIsWebServer")
{
$siteID = $site.psbase.Name
# Grab bindings and cast to array
$bindings = [array]$site.psbase.Properties["ServerBindings"].Value
$hasChanged = $false
$c = 0
foreach($binding in $bindings)
{
# Only change if IP address is one we're interested in
if($binding.IndexOf($oldIp) -gt -1)
{
$newBinding = $binding.Replace($oldIp, $newIp)
Write-Output "$siteID: $binding -> $newBinding"
$bindings[$c] = $newBinding
$hasChanged = $true
}
$c++
}
if($hasChanged)
{
# Only update if something changed
$site.psbase.Properties["ServerBindings"].Value = $bindings
# Comment out this line to simulate updates.
$site.psbase.CommitChanges()
Write-Output "Committed change for $siteID"
Write-Output "========================="
}
}
}

Resources