Forum Replies Created
-
AuthorPosts
-
Please can you give some sample data for $luns and the output you would like in the CSV. It’s hard to answer the question without knowing specifically what data you have and what you want the CSV file to look like.
If you’re just looking to get a multivalued property or array in a single cell then I think you’re working along the right lines using the join method. Here’s a quick example with Win32_LogicalDisk
PowerShell12345678910$disks = Get-WmiObject Win32_LogicalDisk | Select-Object DeviceId,VolumeName$obj = [PSCustomObject] @{Id = $disks.DeviceId -join ';'Name = $disks.VolumeName -join ';'}$obj | ConvertTo-CsvJanuary 20, 2016 at 11:07 am in reply to: ConvertTo-HTML does not preserve single column heading #34100According to a cursory search, this behaviour has been around for a while. I can’t see a bug report for it on user voice though.
The bug only rears its head if you pipe Select-Object to Convertto-HTML. You can have a single column if you use the -property parameter:
PowerShell1Get-Service Appi* | ConvertTo-Html -Property Name -FragmentI took the same approach as the other Matt.
PowerShell1234567891011121314151617181920$rootPath = "F:\"$folders = Get-ChildItem $rootPath -Directory$objCol = @()foreach ($folder in $folders) {$size = Get-ChildItem $folder -Recurse | Measure-Object -Property Length -sum$name = $folder.Name$obj = [PSCustomObject] @{FolderName = $nameFolderSize = "{0:N5}" -f ($size.sum/1GB)}$objCol += $obj}$objCol | Sort-Object FolderSize -Descending | Export-Csv F:\report.csv -NoTypeInformationJanuary 18, 2016 at 2:09 pm in reply to: Copying files and folders from Server to Server with verification issue #34032I don’t get that error so perhaps the file you’ve saved is not the save as the script that you have posted.
There’s a fair bit wrong with the script:
$countsource = @(Get-Item-Path $source "\\Servername\C$\davesdata")<br />$countdest = @(Get-Item-Path $dest "\\Servername\C$")
Your path is determined when you call the script with the source and dest parameters. You have no choice but to specify them as they are both mandatory parameters. There’s no need to put the paths in quote marks after the variable names. Just specifying $source and $dest is enough. You also need a space between the cmdlet name Get-Item and the parameter -path.
IF($countsource = $countdest){
This is a common error. The equals sign is the assignment operator in PowerShell. That means that what you’re attempting to do is assign $countdest to $countsource.
To compare objects for equality you need to use the -eq operator.
Finally, and most importantly, the comparison you’re trying to make will always return false so your script, even if you make the corrections I suggest above, won’t work as intended.
You’ll also find more information in the free PowerShell.org book Secrets of PowerShell Remoting.
Something you may wish to consider doing is getting hold of a free hypervisor such as VirtualBox or VMware player and then downloading an evaluation version of Windows server. It doesn’t take an awful lot of resources to run a couple of virtual machines and you’ll be able to set up an Active Directory domain.
I’m not sure what you’re asking. Do you just want to know what’s happening when you run the command you posted or are you having a problem with the command?
Please post the web config file on Gist and paste a link to it here so that we can take a look.
January 8, 2016 at 10:52 am in reply to: How do I find out the C# dlls that support regasm.exe for dotnet 2.0 #33666Have a look at Listdlls by Mark Russinovich. It’s available on SysInternals.
You will need to know the process name or pid of regasm.exe. Here’s an example for notepad which runs as notepad.exe
PowerShell12345678910111213141516171819D:\Apps\SysInternals\SysInternals>Listdlls.exe notepad.exeListDLLs v3.1 - List loaded DLLsCopyright (C) 1997-2011 Mark RussinovichSysinternals - www.sysinternals.com------------------------------------------------------------------------------notepad.exe pid: 8840Command line: notepad.exeBase Size Path0x00000000fbcd0000 0x3b000 C:\WINDOWS\system32\notepad.exe0x00000000c57c0000 0x1ac000 C:\WINDOWS\SYSTEM32\ntdll.dll0x00000000c3640000 0x13e000 C:\WINDOWS\system32\KERNEL32.DLL0x00000000c2cd0000 0x115000 C:\WINDOWS\system32\KERNELBASE.dll0x00000000c3140000 0xaa000 C:\WINDOWS\system32\ADVAPI32.dll0x00000000c3780000 0x14f000 C:\WINDOWS\system32\GDI32.dll0x00000000c2f60000 0x177000 C:\WINDOWS\system32\USER32.dll0x00000000c5070000 0xaa000 C:\WINDOWS\system32\msvcrt.dllNote, that’s not the full list of dlls, I just posted a few to give you an idea of the output.
Try it like this:
[string[]]$DNSServers = @('1.1.1.1','2.2.2.2')
The @() is called the array operator and is used to create an array of objects. Your parameter definition accepts an array of strings as denoted by the [].
I can’t test it but from MSDN it looks like an empty collection is returned if no updates are found MSDN – SearchUpdates Method.
The UpdateCollection object has a Count property so you may be able to use
if ($kbs.count -eq 0) {...} to test for an empty collection.From testing here, I don’t think get Get-ADGroupMember will work either. That command only returns groups, users and computers, and a contact object is a separate class of object. Try the Get-ADObject command with an LDAP filter on the group’s DN. You can use the ResultSetSize parameter to ensure all objects are returned.
PowerShell1Get-ADobject -LDAPFilter '(memberOf=CN=Test Team,CN=Users,DC=Contoso,DC=Com)' -ResultSetSize $null -Property mail | Select-Object mailIs this KB relevant to you? Issue 2 in particular:
December 18, 2015 at 6:30 am in reply to: Ignoring warning/error popup messages for Excel script #33110Can you give us some idea of what the errors are and what the pop-ups say. I didn’t get any errors or pop-ups when testing this.
December 17, 2015 at 9:21 am in reply to: Excel com objects for refreshing data and saving as CSV #33088I missed the edit, sorry. You can check and remove a file with the same name using the following code.
PowerShell12345if (Test-Path -Path $newFile) {Remove-Item $newFile -Force}Insert it before the $wb.SaveAs("$newFile",6) line
December 17, 2015 at 8:47 am in reply to: Excel com objects for refreshing data and saving as CSV #33085My fault, I was running the script in the same folder as my test files. Replace $wb = $xl.Workbooks.Open($file) with $wb = $xl.Workbooks.Open($file.FullName).
-
AuthorPosts