Detaching VHD Files using PowerShell
Hi,
Does anybody know of any PowerShell scripts which I can use which will detach a VHD file from multiple VM's? I have a few hundred VM's that I need to detach a VHD from so could really do with a script!
Cheers
Neil
Hi,
Thanks for the response. Unfortunately we are running PowerShell v2.0 on Hyper-V 2008 R2 so we cannot use this as it is only applicable to Server 2012 R2 :(
Similar Messages
-
How to get Document Set property values in a SharePoint library in to a CSV file using Powershell
Hi,
How to get Document Set property values in a SharePoint library into a CSV file using Powershell?
Any help would be greatly appreciated.
Thank you.
AA.Hi,
According to your description, my understanding is that you want to you want to get document set property value in a SharePoint library and then export into a CSV file using PowerShell.
I suggest you can get the document sets properties like the PowerShell Command below:
[system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
$siteurl="http://sp2013sps/sites/test"
$listname="Documents"
$mysite=new-object microsoft.sharepoint.spsite($siteurl)
$myweb=$mysite.openweb()
$list=$myweb.lists[$listname]
foreach($item in $list.items)
if($item.contenttype.name -eq "Document Set")
if($item.folder.itemcount -eq 0)
write-host $item.title
Then you can use Export-Csv PowerShell Command to export to a CSV file.
More information:
Powershell for document sets
How to export data to CSV in PowerShell?
Using the Export-Csv Cmdlet
Thanks
Best Regards
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Report the size of all SharePoint Databases in a text file using PowerShell?
I am new to Powershell. please help me for following question with step by step process.
How to report the size of all SharePoint Databases in a text file using PowerShell?Hi Paul,
Here is the changed script, which will also include the size for the Config DB.
Please let me know if it worked:
#Get SharePoint Content database sizes
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$date = Get-Date -Format "dd-MM-yyyy"
#Variables that you can change to fit your environment
$TXTFile = "D:\Reports\SPContentDatabase_$date.txt"
$SMTPServer = "yourmailserver"
$emailFrom = "[email protected]"
$emailTo = "[email protected]"
$subject = "Content & Config Database size reports"
$emailBody = "Daily/Weekly/Monthly report on Content & Config databases"
$webapps = Get-SPWebApplication
$configDB = Get-SPDatabase | ?{$_.Name -eq ((Get-SPFarm).Name)}
$ConfigDBSize = [Math]::Round(($configDB.disksizerequired/1GB),2)
Add-Content -Path $TXTFile -Value "Config Database size: $($ConfigDBSize)GB"
Add-Content -Path $TXTFile -Value ""
foreach($webapp in $webapps)
$ContentDatabases = $webapp.ContentDatabases
Add-Content -Path $TXTFile -Value "Content databases for $($webapp.url)"
foreach($ContentDatabase in $ContentDatabases)
$ContentDatabaseSize = [Math]::Round(($ContentDatabase.disksizerequired/1GB),2)
Add-Content -Path $TXTFile -Value "- $($ContentDatabase.Name): $($ContentDatabaseSize)GB"
if(!($SMTPServer) -OR !($emailFrom) -OR !($emailTo))
Write-Host "No e-mail being sent, if you do want to send an e-mail, please enter the values for the following variables: $SMTPServer, $emailFrom and $emailTo."
else
Send-MailMessage -SmtpServer $SMTPServer -From $emailFrom -To $emailTo -Subject $subject -Body $emailBody -Attachment $TXTFile
Nico Martens - MCTS, MCITP
SharePoint 2010 Infrastructure Consultant / Trainer -
How to get DocSet property values in a SharePoint library into a CSV file using Powershell
Hi,
How to get DocSet property values in a SharePoint library into a CSV file using Powershell?
Any help would be greatly appreciated.
Thank you.
AA.Hi AOK,
Would you please post your current script and the issue for more effcient support.
In addition, to manage document set in sharepoint please refer to this script to start:
### Load SharePoint SnapIn
2.if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
3.{
4. Add-PSSnapin Microsoft.SharePoint.PowerShell
5.}
6.### Load SharePoint Object Model
7.[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
8.
9.### Get web and list
10.$web = Get-SPWeb http://myweb
11.$list = $web.Lists["List with Document Sets"]
12.
13.### Get Document Set Content Type from list
14.$cType = $list.ContentTypes["Document Set Content Type Name"]
15.
16.### Create Document Set Properties Hashtable
17.[Hashtable]$docsetProperties = @{"DocumentSetDescription"="A Document Set"}
18.$docsetProperties = @{"CustomColumn1"="Value 1"}
19.$docsetProperties = @{"CustomColum2"="Value2"}
20. ### Add all your Columns for your Document Set
21.
22.### Create new Document Set
23.$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,"Document Set Title",$cType.Id,$docsetProperties)
24.$web.Dispose()
http://www.letssharepoint.com/2011/06/document-sets-und-powershell.html
If there is anything else regarding this issue, please feel free to post back.
Best Regards,
Anna Wang
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected] -
Removing non printable characters from an excel file using powershell
Hello,
anyone know how to remove non printable characters from an excel file using powershell?
thanks,
jose.To add - Excel is a binary file. It cannot be managed via external methods easily. You can write a macro that can do this. Post in the Excel forum and explain what you are seeing and get the MVPs there to show you how to use the macro facility
to edit cells. Outside of cell text "unprintable" characters are a normal part of Excel.
¯\_(ツ)_/¯ -
Merge xls files using powershell
is there any way to merge xls files using powershell ?
What does "merge" mean? Copy cells? Copy Sheets? Copy formulas? Copy Data?
"Merge"is way too vague.
¯\_(ツ)_/¯ -
Is it possible to monitor State change of a .CSV file using powershell scripting ?
Hi All,
I just would like to know Is it possible to monitor State change of a .CSV file using powershell scripting ? We have SCOM tool which has that capability but there are some drawbacks in that for which we are not able to utilise that. So i would like
to know is this possible using powershell.
So if there is any number above 303 in the .CSV file then i need a email alert / notification for the same.
Gautam.75801Hi Jrv,
Thank you very much. I modified the above and it worked.
Import-Csv C:\SCOM_Tasks\GCC2010Capacitymanagement\CapacityMgntData.csv | ?{$_.Mailboxes -gt 303} | Export-csv -path C:\SCOM_Tasks\Mbx_Above303.csv;
Send-MailMessage -Attachments "C:\SCOM_Tasks\Mbx_Above303.csv" -To “[email protected]" -From “abc@xyz" -SMTPServer [email protected] -Subject “Mailboxex are above 303 in Exchange databases” -Body “Mailboxex are above 303 in Exchange databases"
Mailboxex - is the line which i want to monitor if the values there are above 303. And it will extract the lines with all above 303 to another CSV file and 2nd is a mail script to email me the same with the attachment of the 2nd extract.
Gautam.75801 -
Search and Replace text in file using PowerShell
I want to schedule a script in PowerShell to search a directory for an XML file for a particular text string and replace it with a different text string and then save the file with the same name, the name of the file
will change each time the script is run on a daily basis. There will only be one XML file in the location when the scheduled script is run.
I have never used PowerShell but am familiar with batch file commands, can anyone please help!!
KevinSHi Kevin,
I’m writing to just check in to see if the suggestions were
helpful. If you need further help, please feel free to reply this post directly so we will be notified to follow it up.
If you have any feedback on our support, please
click here.
Best Regards,
Anna
TechNet Community Support -
How to Compare 2 CSV file and store the result to 3rd csv file using PowerShell script?
I want to do the below task using powershell script only.
I have 2 csv files and I want to compare those two files and I want to store the comparision result to 3rd csv file. Please look at the follwingsnap:
This image is csv file only.
Could you please any one help me.
Thanks in advance.
By
A Path finder
JoSwa
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful"
Best Online JournalNot certain this is what you're after, but this :
#import the contents of both csv files
$dbexcel=import-csv c:\dbexcel.csv
$liveexcel=import-csv C:\liveexcel.csv
#prepare the output csv and create the headers
$outputexcel="c:\outputexcel.csv"
$outputline="Name,Connection Status,Version,DbExcel,LiveExcel"
$outputline | out-file $outputexcel
#Loop through each record based on the number of records (assuming equal number in both files)
for ($i=0; $i -le $dbexcel.Length-1;$i++)
# Assign the yes / null values to equal the word equivalent
if ($dbexcel.isavail[$i] -eq "yes") {$dbavail="Available"} else {$dbavail="Unavailable"}
if ($liveexcel.isavail[$i] -eq "yes") {$liveavail="Available"} else {$liveavail="Unavailable"}
#create the live of csv content from the two input csv files
$outputline=$dbexcel.name[$i] + "," + $liveexcel.'connection status'[$i] + "," + $dbexcel.version[$i] + "," + $dbavail + "," + $liveavail
#output that line to the csv file
$outputline | out-file $outputexcel -Append
should do what you're looking for, or give you enough to edit it to your exact need.
I've assumed that the dbexcel.csv and liveexcel.csv files live in the root of c:\ for this, that they include the header information, and that the outputexcel.csv file will be saved to the same place (including headers). -
Split large .pptx file to multiple files using PowerShell
Hi.
I'm not a programmer and I have the task to split big .pptx file(>100 slides) to multiple .pptx files with 4 slides in each one and save them into SP library. It should be done on PowerShell.
Thanks for any help!Hi,
For splitting PowerPoint files into multiple parts, I would suggest you post this question to Office forum, you will get more help and confirmed answers there:
http://social.technet.microsoft.com/Forums/office/en-US/home
For uploading files to SharePoint Library using PowerShell, here are some links with script demos provided for your reference:
http://social.technet.microsoft.com/wiki/contents/articles/19529.sharepoint-2010-upload-file-in-document-library-using-powershell.aspx
http://spfileupload.codeplex.com/
Best regards
Patrick Liang
TechNet Community Support -
Unzip GZ files using Powershell
I have Windows 2008 Server with some GZ type files in a folder. I would like to script unzipping them using Powershell, can someone tell me if this is possible and how I would do it?
The folder is d:\data_files\ and I'd like to uncompress all the .gz files in there
I've searched around on the Net but can't find much that deals with GZ files specifically. The files are all named data-1.gz, data-2.gz etc
Hello
I have Windows 2008 Server with some GZ type files in a folder. I would like to script unzipping them using Powershell, can someone tell me if this is possible and how I would do it?
The folder is d:\data_files\ and I'd like to uncompress all the .gz files in there
I've searched around on the Net but can't find much that deals with GZ files specifically.I also found that .Net 2.0 and above has native code for dealing with gzip files.
Function DeGZip-File{
Param(
$infile,
$outfile = ($infile -replace '\.gz$','')
$input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read)
$output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None)
$gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress)
$buffer = New-Object byte[](1024)
while($true){
$read = $gzipstream.Read($buffer, 0, 1024)
if ($read -le 0){break}
$output.Write($buffer, 0, $read)
$gzipStream.Close()
$output.Close()
$input.Close()
$infile='C:\Temp\DECfpc1new.csv.gz'
$outfile='c:\temp\DECfpc1new.csv'
DeGZip-File $infile $outfile
You can supply the function with the full path of the file to be unzipped, and the full path of the unzipped file.
If you don't supply the unzipped file path, the function will unzip the file into the same folder as the source, and remove the .gz extension.
Inspired by Heineken. -
Parse log file using powershell
Hi,
Am pretty new to Powershell and would require anyone of your assistance in setting up a script which parse thru a log file and provide me output for my requirements below.
I would like to parse the Main log file for Barra Aegis application(shown below) using powershell.
Main log = C:\BARRALIN\barralin.log
Model specific log = C:\BARRALIN\log\WG*.log
Requirements :
1. scroll to the bottom of the log file and look for name called "GL Daily" and see the latest date which in the example log below is "20150203"
note : Name "GL Daily" and date keep changing in log file
2. Once entry is found i would like to have a check to see all 3 entries PREPROCESS, TRANSFER, POSTPROCESS are sucess.
3. If all 3 are success i would like to the script to identify the respective Model specific log number and print it out.
E.g if you see the sample log below for "GL Daily", it is preceded by number "1718" hence script should append the model log path with "WG00" along with 1718, finally it should look something like this C:\BARRALIN\log\WG001718.log.
4. If all 3 items or anyone of them are in "failed" state then print the same log file info with WG001718.log
Any help on this would be much appreciated.
Thank You.
Main log file :
START BARRALINK Check Auto Update 1716
43006 20150203
Trgt/Arch c:\barralin
PREPROCESS success 0 preprocessor: no error
TRANSFER success 1 Host success: files received
POSTPROCESS success 0 Postprocessor: no error
CONFIRMATION success 2 No Confirm needed
STOP 43105 20150203
START Aegis GL Monthly
1716 43117 20150203
Trgt/Arch K:\barraeqr\aegis\qnt\gleqty
PREPROCESS success 0 preprocessor: no error
TRANSFER success 1 Host success: files received
POSTPROCESS success 0 Postprocessor: no error
CONFIRMATION success 2 No Confirm needed
STOP 44435 20150203
START Aegis UB Daily
1717 43107 20150203
Trgt/Arch K:\barraeqr\aegis\qnt\gleqty
PREPROCESS success 0 preprocessor: no error
TRANSFER success 1 Host success: files received
POSTPROCESS success 0 Postprocessor: no error
CONFIRMATION success 2 No Confirm needed
STOP 44435 20150203
START Aegis GL Daily
1718 44437 20150203
Trgt/Arch K:\barraeqr\aegis\qnt\gleqty
PREPROCESS success 0 preprocessor: no error
TRANSFER success 1 Host success: files received
POSTPROCESS success 0 Postprocessor: no error
CONFIRMATION success 2 No Confirm needed
STOP 50309 20150203
Hi All,
I was writing a function in power shell to send email and i was looking to attach lines as and when required to the body of the email. but am not able to get this done..Here's my code
Function Email ()
$MailMessage = New-Object System.Net.Mail.MailMessage
$SMTPClient = New-Object System.Net.Mail.SmtpClient -ArgumentList "mailhost.xxx.com"
$Recipient = "[email protected]"
If ($MessageBody -ne $null)
$MessageBody = "The details of Barra $strsessionProduct model is listed below
`rHostName : $localhost
`r Model Run Date : $Date
`r Model Data Date : $DateList1
`r`n Click for full job log"+ "\\"+$localhost+"\E$\Local\Scripts\Logs "
$MailMessage.Body = $MessageBody
If ($Subject -ne $null) {
$MailMessage.Subject = $Subject
$Sender = "[email protected]"
$MailMessage.Sender = $Sender
$MailMessage.From = $Sender
$MailMessage.to.Add($Recipient)
If ($AttachmentFile -ne $null) { $MailMessage.Attachments.add($AttachmentFile)}
$SMTPClient.Send($MailMessage)
$Subject = "Hello"
$AttachmentFile = ".\barralin.log"
$MessageBody = "Add this line to Body of email along with existing"
Email -Recipient "" -Subject $Subject -MessageBody $MessageBody -AttachmentFile $AttachmentFile
as you can see before calling Email function i did add some lines to $MessageBody and was expecting that it would print the lines for $MessageBody in Email Function along with the new line. But thats not the case.
I have tried to make $MessageBody as an Array and then add contents to array
$MessageBody += "Add this line to Body of email along with existing"
$MessageBody = $MessageBody | out-string
Even this didnt work for me. Please suggest me any other means to get this done.
THank You -
Open, Write and Close the file using Powershell
Hi All,
I need to create/open a file and write some data into it and close that file.
Could anyone please help me with this.
Thanks.You don't need to explicitly create, open, or close a file in Powershell. Here are some ways to write to a file, in addition to New-Item:
$text = 'Hello World'
# Create file:
$text | Set-Content 'file.txt'
#or
$text | Out-File 'file.txt'
#or
$text > 'file.txt'
# Append to file:
$text | Add-Content 'file.txt'
#or
$text | Out-File 'file.txt' -Append
#or
$text >> 'file.txt'
Grant Ward, a.k.a. Bigteddy
The problem with Out-File is that it works like the console. When text is output, it will be truncated if it is wider than the default. So if you are looking for something where you need to store lots of long strings, then you may want to choose a different
route, or ensure than you specify a width for your output.
http://technet.microsoft.com/en-us/library/ee176924.aspx
For example to get 200 characters of width:
$text | Out-File
'myfile.txt' -width 200
I do not know for certain if there is a limit to how wide it can be. I also assume the default is the standard console width (80 characters I believe.) -
Require help with converting a wim file to a vhd file using WIM2VHD
I would like some assistance in learning to actually start the wim2vhd command line tool? I have been supplied an script to go with it but am unsure how to open the whole program? I am required to convert a wim file into a vhd file for a task on a project
but cannot do so without this tool and am having troubles in struggletown trying to complete the task? have been trying to complete this for about a month with holidays in the middle.
Any help is muchly appreciated.Wim2VHD is not a Windows 7 file, feature, nor utility.
It is a utility supported by MSDN. Suggest you find the appropriate MSDN forum to post in. See info @
http://archive.msdn.microsoft.com/wim2vhd about Wim2VHD.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ” -
Creating a diskpart script file using Powershell
Hi,
I have a very odd (and very annoying) problem...
I have a powershell script which creates a diskpart file to online any given number of iSCSI attached disks. The powershell script takes input from a csv which includes the disk numbers then creates a txt file with the relevent diskpart commands (e.g
select disk X, online disk, etc..)
The powershell script runs without error and creates the output file, however when I attempt to run diskpart with the outputfile (i.e. diskpart /s outputfile.txt) diskpart does not acknowledge/accept the file and just returns a list of valid commands.
Yet if I manually create a empty txt file via Windows Explorer and copy and paste the contents of the powershell generated script file in to it, then run the diskpart against this file all works as expected.
So it seems as though that in writing to the file via powershell something is happening to the file fortmatting which diskpart does not like - any ideas what?
I have tried several work arounds including manually creating the txt file before running the powershell and creating the txt file explicitly from powershell but get the same result.
Although I can workaround the issue as described above it would be nice to get this working as intended, or least understand why the problem occurs - so any help/advice would (as always) be much appreciated!
for reference the powershell script is detailed below:
$a="select disk "
$b="attributes disk clear readonly"
$c="online disk"
import-csv .\input.csv | foreach {
$a+$_.diskNumber >> outputfile.txt
$b >> outputfile.txt
$c >> outputfile.txtKazun,
Thank you for sharing your script. I tired it but did not work for me. I modified yours slightly to configure 134 SAN devices as mount points. I've already set the SAN policy to OnlineAll and cofigured 4 other devices. When I run the diskpart
commands per disk from CLI its works. Please let me know what I'm missing.Thank you.
$B = import-csv -Path "C:\Support\Prep_Disks\3-CreateMountPoints\MountPoints.csv"
$B | Foreach-Object {
$DiskNum = $_.DiskNumber
$MP = $_.MountPath
$DiskLBL = $_.DiskLabel
$command = @"
SELECT DISK $DiskNum
ATTRIBUTES DISK CLEAR READONLY
ONLINE DISK
CONVERT MBR
CREATE PARTITION PRIMARY
ASSIGN MOUNT=$MP
FORMAT FS=NTFS UNIT=64k LABEL=$DiskLBL QUICK
$command | diskpart
Maybe you are looking for
-
Need help to develop CMDB using Apex
Hi, We have a large number of servers, databases, environments, applications, etc for which we have planned to create a repository. Hence we need to develop a CMDB for the same. I have gone through the example tutorials related to Apex. However, I ha
-
My Kindle app will not open at Boston Market. Why so specific?
So I sit down at Boston Market with my sandwich and soft drink and a side of macaroni and cheese, try to open up the Kindle app to get in some relaxing reading during my lunch hour, and the app just quits before it even gets past the "welcome" screen
-
Verizon DSL, Westell & Airport Extreme Base Station
Last year I posted a desire to hook up my AEBS and AEX to a Westell wireless network. After much discussion and many suggestions I created a network that worked but was occasionally flaky. Since that time our family has replaced two old G3 laptops wi
-
Movieclip - Button - Location on stage
Fellow Gurus! I am using Flash 8. I rendered some boxes on the stage. One is for a menu and another is for graphics. The idea is to have a picture pop-up in the graphic box whenever one passes a mouse over a button in the menu (which is in the menu b
-
These questions are for people that want to copy CSS from Parfait. Do you use CSS Preprocessors in your workflows? If so, which one do you use most often? Do you ever use others, and if so, which one(s)? Would you like Project Parfait to provide you