Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

remove "titles"

$
0
0

1) how to i remove the title from :

PS C:\Users\peleg> get-process myexe1 Where-Object { $_.path -Like "*MailText*"} | select name, path,id, @{l="W
orking Set(Memory) (MB)"; e={$_.workingset/1mb}} -Last 1 | format-table id,name,path,"Working Set(Memory) (MB)" -autosiz
e

iget titles in the result :

Id Name         Path                                                         Working Set(Memory) (MB)
-- ----         ----                                                         ------------------------

how can i remove them?

2) can i give diffrent name i nthe select :

select name, path,id, @{l="W
orking Set(Memory) (MB)"; e={$_.workingset/1mb}}

can i do like in sql somthing like this :

"Working Set(Memory) (MB)" as column1

3) whats the "e" used for in :  e={$_.workingset/1mb}


Powershell:- Display Data in Columns

$
0
0

Hi,

I hope that you can help, I have written a powershell script that pings all our external routers (Router Names held in a txt file) and then outputs the results/status to a HTML page, for the IT Department to read.

Unfortuntely this page is quite long and goes beyond a screen length, what I need help on is rather than having a page with two columns (Router Name, Status) is for the page to be displayed as 4 Columns (Router Name, Status, Router Name, Status).

Any help would be grealty appreciated.

Thanks

Graham

Enable Remote Desktop Connections with PowerShell

$
0
0
What is the easiest way to enable remote desktop connections on Windows 7, with powershell?

Deploying SSRS Reports using Powershell Method not found

$
0
0

I'm using this template from TechNet to deploy my SSRS reports with powershell...

http://gallery.technet.microsoft.com/Bulk-Report-Deployment-f03e1aac/view/Discussions

This line gives me an unknown method error...

 $Warnings = $SSRSProxy.CreateReport($_.ReportName, $_.TargetReportFolder, $True, $Bytes, $Null) 

So I replaced the method "CreateReport" with "CreateCatalogItem". But when I try to run it with my server information it yields...

"Cannot find an overload for "CreateCatalogItem" and the argument count: "5".
At C:\Users\mike.davis\Desktop\Test\REPORTS\TPF Report\TPF Report\bin\Debug\Bulk SSRS Report Deployment with PowerShell.ps1:26 char:45
+     $Warnings = $SSRSProxy.CreateCatalogItem <<<< ($_.ReportName, $_.TargetReportFolder, $True, $Bytes, $Null)
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest"

What is the correct method to use in this situation when I have ReportingServices2010?


Setting Pagefile

$
0
0
I've been using the following script to set pagefile on my servers however for some reason it's not working on server 2012.  I get an error "Exception calling "Put" with "0" arguments "value out of range".  What am I doing wrong?  Can you recommend a better way of doing it?  Thanks.
$PageFile = Get-WmiObject -class Win32_PageFileSetting
$RAM = Get-WmiObject Win32_OperatingSystem | select TotalVisibleMemorySize
$RAM = ($RAM.TotalVisibleMemorySize / 1kb).tostring("00")

if ($RAM -gt 67584){
$PageFile.InitialSize = 102400
$PageFile.MaximumSize = 102400
}
else
{
$PageFile.InitialSize = ([int]$RAM * 1.5)
$PageFile.MaximumSize = ([int]$RAM * 1.5)
}

$model = gwmi win32_computersystem | select model

if ($model.model -like "*virtual*"){
wmic computersystem set AutomaticManagedPagefile=true}
else
{
wmic computersystem set AutomaticManagedPagefile=false
set-itemproperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\" -name "pagingfiles" -type multistring -value "c:\pagefile.sys 0 0"
$PageFile.Put()}


Powershell "Get-VM" error

$
0
0

Hello,

When I run this command in powershell cli, I get the following error.

PS C:\Users\Administrator\Desktop> Get-VM
The term 'Get-VM' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spel
ling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:7+ Get-VM <<<<+ CategoryInfo          : ObjectNotFound: (Get-VM:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundException

Please help as I am unable to even find a HyperV library to install for powershell.

What wrong am I doing here or what are the corrrective steps that are required to get this working ?

Exception calling "AddAccessRule" with "1" argument(s): "Some or all identity references could not be transla ted." error

$
0
0

Hi guys, Im trying to make a permission group, folder and set the permission to the folder, but it returns me this error :


Exception calling "AddAccessRule" with "1" argument(s): "Some or all identity references could not be transla
ted."

It drives me crazy

this is part of my code

###create AD group

new-QADGroup -proxy -Name $orgBasedResourceName -samAccountName $orgBasedResourceName -ParentContainer $targetOU -Description $desc -GroupScope  $targetGroup.GroupScope -GroupType $targetGroup.GroupType


###create folder

New-Item -ItemType directory -Path ($dir+$deptListCode)


###set the permission

$colRights = [System.Security.AccessControl.FileSystemRights]"Read, Write"

$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None

 $objType =[System.Security.AccessControl.AccessControlType]::Allow
                    
$objUser = "AMAIISDOM\"+$orgBasedResourceName
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
                        ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
                    
$objACL = Get-ACL ($dir+$deptListCode)
                  
$objACL.AddAccessRule($objACE)

Set-ACL ($dir+$deptListCode) $objACL

both of folder and the ad group are created, but the group just can not be set to the folder


any help, thanks in advance

Remove all but first charactor from a string

$
0
0

I can't seem to find an solution.  Please help.  I want to create a function thats wrapped around the new-mailbox cmdlet.  I want to take the first name and last name.  Then take only the first character add it to the last name to create the alias.  How can I pick out the first character in a string?  Thanks.


NTP Time comparison

$
0
0

hi,

1. how to find the NTP server in a doamin?

2. i need to take a report that compares the time of NTP server with the member server on that domain using PS

can someone please help me on this?

Find and Replace special characters text in file

$
0
0

I am trying to find and replace key/password in sql files.  Here is what I was trying:

$SQLFiles = get-childitem "\\server\e$\Scripts\*.sql" -rec
foreach ($file in $SQLFiles)
{
[regex]$regex="M+}wbKEbhm0w1)Xn"
(Get-Content $file.PSPath) | Foreach-Object {$_ -replace $regex, "0KiEk?h3Um[Qk@Lv"} | Set-Content $file.PSPath
}

But I get this error: 

Cannot convert value "M+}wbKEbhm0w1)Xn" to type "System.Text.RegularExpressions.Regex". Error: "parsing "M+}wbKEbhm0w1)Xn" - Too many )'s."

How can I find the string with special characters and replace it?


How do I resolve the "Size limit exceeded for Get-Adgroupmember" error when listing a group with thousands of members?

$
0
0

Hello,

I run the following commands from the 2.0 Command line on a Domain Controller to list the members of a large group (thousands of members) and to count the number of objects (measure-object):

get-adgroupmember "mygroup"

get-adgroupmember "mygroup" | measure-object

Get-ADGroupMember : The size limit for this request was exceeded
At line:1 char:18+ get-adgroupmember <<<<  "mygroup"+ CategoryInfo          : NotSpecified: (mygroup:ADGroup) [Get-ADGroupMember], ADException+ FullyQualifiedErrorId : The size limit for this request was exceeded,Microsoft.ActiveDirectory.Management.Comman
   ds.GetADGroupMember

What do I need to do to resolve this error?  Thanks in advance.

Thanks for your help! SdeDot

Powershell-3 on Windows Server 2008 R2 is incredibly slow. How come?

$
0
0

Hello,

I installed powershell-3 using Powershell_3.0_Windows6.1-KB2506143-x64.msu.

Now powershell takes a felt eternity just to expand
get-he
in the powershell command line to get-help. It consumes 98% of the CPU time.
So I decided to uninstall this KB. Worked ok. Got back Powershell-2. Was behaving normal again.

So I wanted to make sure and was hoping when re-installing KB2506143 that this error would be gone.
But as powershell-3 is back on the server, so is this intolerable delay in the powershell command line.

Would anybody know how to remedy this? After all powershell-3 has left the beta state.

Also too bad that there is no repair function in programs and features.

Thank you.


Andreas




$Env line of code failing

$
0
0
I have this code that is supposed to add collections to SCCM 2007. I load this up in PowerGUI and it displays a 'red error line' under the the double quote after computername. On this line: $Computer = "$env:computername", It throws up this error: Unexpected token 'env:computername' in expression or statement.

My question is why? What is wrong with the syntax on this one line of code? 



$Site_Prefix = "AB1 - SCCMCEN01, Central Site 1 (San Francisco))" 
$CollectionNames = @("Albuquerque","Anchorage) 

# Create Collection function 
Function Create-Collection 

Param( 
$Computer = "$env:computername",     <<<< Error on this line <<<<
$SiteCode, 
$CollectionName, 
$ParenCollectionID



$CollectionClass = "SMS_Collection" # WMI Class 
$SubCollectionClass = "SMS_CollectToSubCollect" # WMI Class 
$Colon = ":" 
$FullSiteName = "Site_$SiteCode" 


$WMIConnection = [WmiClass]]]]]]]] 

mqh7

Calendar permissions for all in Office 365 using PowerShell

$
0
0

Hello all,

In office 365, what I am trying to achieve is to give everyone , everyone's full access to calendar permission.

Meaning, If I have 10 users in O365, every one  must have everyone's calendar access to add, deleted, edit the calendar/meeting entries.

Can this be achieved by PowerShell ?

List remote shares without WMI

$
0
0

Hi,

We have a NAS (NetApp) that has shared some folders (not hidden ones). I looking for a way to enumerate these shares so I can use these shares to locate resources that are places on these shares. Since this is not a Windows server I can't use WMI to query the list of shares.

Anyone have an idea or example on how I can list the shares of a remote CIFS box that isn't capable of WMI?


Export-CSV issue with custom Members & Null objects

$
0
0

I have created a function to give me all of the custom receive connector IP's we have added to our exchange server and pop them out in a custom set for ease of reading. As the RemoteIPs are an array with an array from the Get-ReceiveConnector I had to do this to get all of the information into a nice set how I wanted. This worked fine when I wanted to print the data to the screen - But I would prefer a CSV file - But due to the way i have had to create all of the custom objects, some (with less remote ips) end up with $null values so I get an error when trying to export to CSV.

your help is appreciated:

<# Gather all of the IPs from each receive connecter and create into custom objects for ease of export #> Function Get-ReceiveConnectorIPs{ Param( [String]$Server ) $RCObjects = @() $RConnectors IF (!$Server) { $RConnectors = Get-ReceiveConnector } ElseIf ($Server -ne $null) { $RConnectors = Get-ReceiveConnector -Server $Server } ForEach ($RC in $RConnectors) { $00 = 00 $RCObject = New-Object System.Object $RCObject | Add-Member -MemberType NoteProperty -Name ExchangeServerName -Value $RC.Server $RCObject | Add-Member -MemberType NoteProperty -Name ConnectorIdentity -Value $RC.Identity $RCObject | Add-Member -MemberType NoteProperty -Name ConnectorName -Value $RC.Name $RCObject | Add-Member -MemberType NoteProperty -Name HeloFQDN -Value $RC.Fqdn $RCObject | Add-Member -MemberType NoteProperty -Name IsValid -Value $RC.IsValid $RemoteIPs = $RC.RemoteIpRanges ForEach ($RemoteIP in $RemoteIPs) { $RCObject | Add-Member -MemberType NoteProperty -Name ('LowerIP-'+$00) -Value $RemoteIP.LowerBound $RCObject | Add-Member -MemberType NoteProperty -Name ('UpperIP-'+$00) -Value $RemoteIP.UpperBound $RCObject | Add-Member -MemberType NoteProperty -Name ('NetMask-'+$00) -Value $RemoteIP.Netmask $RCObject | Add-Member -MemberType NoteProperty -Name ('CIDRLength-'+$00) -Value $RemoteIP.CIDRLength $RCObject | Add-Member -MemberType NoteProperty -Name ('RangeFormat-'+$00) -Value $RemoteIP.RangeFormat $RCObject | Add-Member -MemberType NoteProperty -Name ('Size-'+$00) -Value $RemoteIP.Size # Bounce the IP set name up 1 $00++ } $RCObjects += $RCObject }

$RCObjects }


So, when I run:

Get-ReceiveConnectorIPs | Export-Csv -NoTypeInformation -Path $Path

I get the following error and I am unsure how to continue:

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At line:1 char:37+ Get-ReceiveConnectorIPs | Export-Csv <<<<  -NoTypeInformation -Path c:\Users\nzadmin\Desktop\receiveconnectorips.csv+ CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand




Running each line in a CSV as a start job

$
0
0

Can someone post a simple example of this...

i want to do the following

foreach ($item in $csv) { Start-Job

I need to carry that item variable (or line in CSV) into the start-job

-DEMPC

powershell view

$
0
0

Hello,

mabey i have a weard question but i am going to ask it any way.

is it possible when you are, lets say working i windows to see what happening in powershell. like opening a folder or saving a folder???

Get Share cahing enabled or not

$
0
0

Hi, is there a way to check if a share  has caching enabled in powershell?

I try with  Get-WmiObject -Class Win32_Share -ComputerName  $server

But none of the properties that i can see will show me what sort of caching is set up.

Thanks

System.Windows.Forms - If ($button.click -eq "ok") {do this}

$
0
0

Hei,

I am wondering how to make this work:

    If($button_ok)
        {"you pressed the ok button"
        $process.kill()
        }
    ElseIf($button_avbryt)
        {"you pressed the cancel button"
        break
        }

Inside a script like this:

  [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
  [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

# Timer
    $timer1 = New-Object System.Windows.Forms.Timer
    $progressBar1Max = $Seconds
    
  
 # Form
    $form_main = New-Object System.Windows.Forms.Form
    $form_main.Text = $Title
    $form_main.StartPosition = "CenterScreen"
    $form_main.MinimizeBox = $false
    $form_main.MaximizeBox = $false
    $form_main.Size = New-Object -TypeName System.Drawing.Size(400,250)
    $form_main.TopMost = $true

# OK button
    $button_ok = New-Object -TypeName System.Windows.Forms.Button
    $button_ok.Size = New-Object -TypeName System.Drawing.Size(75,23)
    $button_ok.Location = New-Object -TypeName System.Drawing.Size(125,180)
    $button_ok.Text = 'OK'
    $button_ok.Add_Click({$Result=$button_ok.Text;$form_main.Close()})
    $form_main.Controls.Add($button_ok)
    $form_main.AcceptButton = $button_ok

# Cancel knapp (avbryt=cancel)
    $button_avbryt = New-Object -TypeName System.Windows.Forms.Button
    $button_avbryt.Size = New-Object -TypeName System.Drawing.Size(75,23)
    $button_avbryt.Location = New-Object -TypeName System.Drawing.Size(210,180)
    $button_avbryt.Text = 'Avbryt'
    $button_avbryt.Add_Click({$Result=$button_avbryt.Text;$form_main.Close()})
    $form_main.Controls.Add($button_avbryt)
    $form_main.CancelButton = $button_avbryt
    
# Message
    $L = New-Object -TypeName System.Windows.Forms.Label
    $L.Size = New-Object -TypeName System.Drawing.Size(280,100) 
    $L.Location = New-Object -TypeName System.Drawing.Size(10,15) 
    $L.Text = $Message
    $form_main.Controls.Add($L)

# Time left
    $time_label = New-Object -TypeName System.Windows.Forms.Label
    $time_label.Size = New-Object -TypeName System.Drawing.Size(30,15) 
    $time_label.Location = New-Object -TypeName System.Drawing.Size(170,130) 
    $form_main.Controls.Add($time_Label)


$timer1_OnTick = {
    $progressBar1.PerformStep()
   
    $time = $progressBar1Max - $progressBar1.Value
    [char[]]$mins = "{0}" -f ($time / 60)
    $secs = "{0:00}" -f ($time % 60)

    $time_label.Text = "{0}:{1}" -f $mins[0], $secs
    # this doesnt work:
    if ($progressBar1.Value -eq $progressBar1.Maximum) {
      $timer1.Enabled = $false
      #Write-Host "Time is up!"
    }
  }


# Progressbar
    $progressBar1 = New-Object System.Windows.Forms.ProgressBar
    $progressBar1.Value = 1
    $progressBar1.DataBindings.DefaultDataSourceUpdateMode = 0
    $progressBar1.Maximum = $progressBar1Max
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Width = 250
    $System_Drawing_Size.Height = 30
    $progressBar1.Size = $System_Drawing_Size
    $progressBar1.Step = 1
    $progressBar1.TabIndex = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 45
    $System_Drawing_Point.Y = 146
    $progressBar1.Location = $System_Drawing_Point
    $progressBar1.Style = 1
    $progressBar1.Name = 'progressBar1'
  
    $form_main.Controls.Add($progressBar1)
  
    $timer1.Interval = 1000
    $timer1.add_tick($timer1_OnTick)
    $timer1.Enabled = $True
    $timer1.Start()


    $InitialFormWindowState = $form_main.WindowState
    $form_main.add_Load($OnLoadForm_StateCorrection)
    $form_main.ShowDialog()| Out-Null 

This doesn't work either:

    if ($progressBar1.Value -eq $progressBar1.Maximum) {
      $timer1.Enabled = $false
      #Write-Host "Time is up!"

Any help would be appreciated!



Viewing all 21975 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>