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

Unable to change keyboard layout for all users on Windows Server 2012 R2

$
0
0

Hi,

I have a requirement where I need to support national keyboard layout for Danish for all users on that machine. When I ran the powershell with script Set-WinUserLanguageList -LanguageList da-DK it only sets the Danish keyboard layout to the specific logged in user.However the for other users its same English(US) keyboard which is not expected.

Please help me how to set the Danish keyboard for all users on the machine. Its Urgent!Thanks


Windows 10 Powershell Feature win Windows 8.1

$
0
0

Hi

Does anybody know if it possible to get the Windows 10 Powershell Features like transparency and CTRL-V features on Windows 8.1. I have tried to install WMF 5 Preview but those feature does not seem to be included.

DSC pull server - pause consistency check of selective MOF

$
0
0

Hi,

I have configured a DSC pull server, and deployed few MOF files.
I have also enabled a client node to access the deployed MOF in DSC pull server.
Please let me know
1. How i can pause "Consistency check" of selective MOFs.
2. How to unregister MOF from pull server.

Thanks.

Dictionary in script?

$
0
0

Hi developer,
I am having problem with Add method. Here is my sample script:

...........................
...........................
$dictionary = @()
foreach($aa in $test)
{

   foreach(.....)
   {
       ...........................
       ...........................

       $firstValue = $value[0]
       $SecondValue = $value[1]

       $dictionary.Add($firstValue,$SecondValue)

   }
}

I got error message and it says:

"Method invocation failed because [System.Object[]] doesn't contain a method named 'Add'.
At line:28 char:28
    + $dictionary.Add <<<< ($firstValue,$SecondValue)
    + CategoryInfo          : InvalidOperation: (Add:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound"


Any Idea?
Thanks


Run a Dos command in Powershell

$
0
0

Hi,

It seems like an easy question but it appears there are lots of ways to do this.  I've been trying to run some dos commands to run NTBackup using start-process and arguments but the arguments are being passed in the wrong format and I can't see where.  Is there any other way to run this simple command.  Here is my previous link http://social.technet.microsoft.com/Forums/windowsserver/en-US/b92541c4-83ce-4740-a3c5-1bb776a5c00d/running-ntbackup-with-startprocess

c:\windows\system32\ntbackup.exe backup @(Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\chameme.bks`"" ,"/n `"1file.bkf1 created 06/09/2013 at 09:36`"" ,"/d `"Set created 06/09/2013 at 09:36`" "," /v:no", "/r:no" ,  "/rs:no" ,  "/hc:off", "/m normal", "/j `"chameme`""," /l:s"," /f `"\\fs1\Exchange Backups$\1file.bkf`"")

My only requirement is that I need to datestamp the file name with the date as NTBackup can't do anything like this...  I have some cloud backup software that doesn't like massive files so this is why I need individually date stamped files from the backup.

Thanks

james


Alter De Ruine

Using Windows Update Module remotely

$
0
0

I've downloaded and installed the Windows Update modules for powershell. The commands work perfectly locally but fails to  work remotely.  I am able to run other commands remotely such as Get-Culture.

Windows Update Module:

https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc

Example Code:

Invoke-Command -ComputerName test_server -Credential domain\me -ScriptBlock {Get-WUHistory}

Output:

The term 'Get-WUHistory' is not recognized as the name of a cmdlet, function, script file, or operable program.


How to execute powershell script without seeing anything on the screen DOS

$
0
0

Hello I 'm trying  execute powershell script from DOS, I want to run the script and see nothing seen on the screen DOS

This is the line that I´m using:


powershell -windowstyle hidden -ExecutionPolicy RemoteSigned -File "C:\ConnectExchange2013.ps1" "testjose" "testjose"

thanks

Problem for send the result Enpty Just a title by email

$
0
0

hello,

I allow myself to write to you I want to send the results of these two tests by email,

Here is my script is functional, but I get that result in the terminal, and email but it is empty.

What are the changes brought.

Thank you for your reply


achraf


A "tail -f" equivalent command in Powershell to show real time logging

$
0
0

Hello,

Using the powershell command:
Get-Content "Filename" -Wait -Tail 10
showing Real-Time contents of a file in powershell doesn't work.

As example i would like to show Real-Time contents of a systemout.log file in a IBM Websphere Environment.

Using the above command, the shell remain in "listening mode" but nothing happens even if the Systemout.log file changes.

In a unix environment it is enough to type "tail -f filename" and everything work correctly.

Is it possible to use a "tail -f" equivalent command in Powershell to show real time logging?

Thank You in advance.

Fausto.


Getting managers names

$
0
0

Hello all! I am very new to powershell scripting. I have some experience with cmdlets but get a bit fuzzy when throwing them together in a script. Especially when importing/exporting a csv file.

So here is what I have and need... any help would be extremely helpful:

I have a csv file named "Users" with a header of "ID". In the ID column, I have the login IDs of over 500 users and I need to get the login IDs of their managers and export both (the original users ID in a column named "User" and their managers' login IDs in a column named "Mgr").

Again, any help would be extremely appreciative

Export non-empty AD groups with assigned "Managed By"

$
0
0

Is there a way to use PowerShell to export all AD groups that are NOT empty AND also that the "Managed by" is not empty.

Basically, I need all the group names that meet both criteria and also the login ID of the "Managed By" exported to csv.

Can anyone tell me if this is possible and how to accomplish?


Extract only numbers from String

$
0
0

Hello All,

I have a requirement where I have to update valid phone numbers from bulk users.

To test if it valid, I have to check the length of only the numerals (it should 11 to 12 max)

For ex:

$a = (+1) 201 839 8419

In the above example all the special characters and space has to be removed (final result should be 12018398419), I don't want to use multiple replace command and want to do it through regex, could you please help??

The below command is not working

string result = Regex.Replace($b, @"[^\d]","");

Any help please??


Never giveup till you get what to want.

Problem with send the result Empty by email

$
0
0

hello,

I allow myself to write to you I want to send the results of these two tests by email,

Here is my script is functional, but I get that result in the terminal, and email but it is empty.

What are the changes brought.

Thank you for your reply

$env:computername 

                "Name of machine it's $env "


# get le SID de la machine 

$user = New-Object System.Security.Principal.NTAccount("$env:USERDOMAIN\$env:USERNAME") 

$sid = $user.Translate([System.Security.Principal.SecurityIdentifier])

$sid.AccountDomainSid.ToString()


# send email 

   $body = "This is the message I want in the body of the email"

    $user = "rafiachraf@hotmail.com"

    $pass = ConvertTo-SecureString -String "mypassword" -AsPlainText -Force

    $cred = New-Object System.Management.Automation.PSCredential $user, $pass


       $mailParam = @{

        To = "rafiachraf91@gmail.com"

        From = "Me <rafiachraf@hotmail.com>"

        Subject = "File report"

        Body = $body

        SmtpServer = "smtp.live.com"

        Port = 587

        Credential = $cred

    }

Send-MailMessage @mailParam -UseSsl



achraf

Automated IISRESET using powershell

$
0
0
I am not on shift 24/7 and i need to automate the iisreset. Needed a powershell script to test the https://@#$%^&. and if its down do an IISRESET.

A scheduled script to test availability every 20 minutes

Execute an script built in powershell since java and when the script ends return to the original program in java

$
0
0

Hello everybody,

I need to run a script written in powershell since java, this part is work fine, the application in java execute the script, the script run fine but aparently the exection of program does not return to the program original in java.

Many thanks.


Execute script on Multiple servers using Powershell

$
0
0

Hi,

I am SQL server DBA and would like to use powershell to execute the below script to monitor the space in multiple servers.

I have saved the server names in the file called "ServerList.txt" 

########*****Script**********#######

DEL "C:\DB_Checkouts\Diskspace\Output.CSV"

COPY "C:\DB_Checkouts\Diskspace\MasterFile.CSV" "C:\DB_Checkouts\Diskspace\Output.CSV"

$ServerListFile = "C:\DB_Checkouts\Diskspace\ServerList.txt" 
$ServerList = Get-Content $ServerListFile 
$Result = @()
$user= whoami 
$date = (get-Date).tostring()
ForEach($computername in $ServerList)
{
gwmi Win32_LogicalDisk -Computername $computername -Filter "Drivetype=3" |select Computername, Name, Size, FreeSpace,BlockSize | % {$_.Computername=($env:COMPUTERNAME);$_.Size=($_.Size/1GB);$_.FreeSpace=($_.FreeSpace/1GB);$_.BlockSize=(($_.FreeSpace)/($_.Size))*100;$_} | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | Select-Object -Skip 1 | Out-File -Append -Encoding ascii -FilePath "C:\DB_Checkouts\Diskspace\Output.CSV"
}

When I am executing the above query, I'm getting below error. Kindly check and share your thoughts to fix the issue.

 

####************Error*************####

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:12 char:5
+ gwmi <<<<  Win32_LogicalDisk -Computername $computername -Filter "Drivetype=3" |select Computername, Name, Size, FreeSpace,BlockSize | % {$_.Computername=($env:COMPUTERNAME);$_.Size
=($_.Size/1GB);$_.FreeSpace=($_.FreeSpace/1GB);$_.BlockSize=(($_.FreeSpace)/($_.Size))*100;$_} | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | Select-Object -Skip 1 | Out-File -Ap
pend -Encoding ascii -FilePath "C:\DB_Checkouts\Diskspace\Output.CSV"
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand


Installing PFX Certificate with Private key using DSC into Azure VM

$
0
0

Does anyone know of a way to import a certificate with private key into a machine in azure using DSC? There doesn't seem to be a DSC resource for this.

Power Shell menu

$
0
0

Hey people

I have written a powershell script, it has a menu system, that goes to a sub menu. and i in the sub menu,
I want one of the options to be back to main menu. How can i achieve this. or a command i can use to do this, or go back to a specific part of the script

script is

# PowerShell console window Style
$pshost = get-host
$pswindow = $pshost.ui.rawui

    $newsize = $pswindow.buffersize
    
    if($newsize.height){
        $newsize.height = 3000
        $newsize.width = 150
        $pswindow.buffersize = $newsize
    }

    $newsize = $pswindow.windowsize
    if($newsize.height){
        $newsize.height = 50
        $newsize.width = 150
        $pswindow.windowsize = $newsize
    }

# MAIN Menu system
$Loop = $true
While ($Loop)
{
    write-host
    write-host                                              ' 1)   go to menu1'
    write-host                                              ' 2)   go to menu 2'
    write-host                                              ' 3)   exit'
                                       

    

    $opt = Read-Host "Select an option [0-3]"
    write-host $opt
    switch ($opt)


"1" {
$Loop = $true
While ($Loop)

{   write-host
    write-host                                              ' 1)   script 1'
    write-host                                              ' 2)   script 2'
    write-host                                              ' 3)   script 3'
    write-host                                              ' 4)   script 4 '
    write-host                                              ' 5)   script 5 '
    write-host                                              ' 6)   back to Main Menu'
    write-host                                             
    

    $opt = Read-Host "Select an option [0-6]"
    write-host $opt
    switch ($opt)


"1" { #script}


"2" { #script}

  "3" { #script# }


  "4" {#script }

  "5" {#script #}

  "6" {???????????}

      default {"$_ is an invalid choice"}

      }
   }
 


}

"3"  {Exit }
      default {"$_ is an invalid choice"}

      }
   
   }

System.Collections.Hashtable

$
0
0

Hi developer,
I have already made script in windows powershell.
For example: Two integers variables then sum ( {5,5} make 10. )
Here is my script:

function TwoValues($input)
{
    $regex = "({.*?})"

    $matchInfo = @($input | Select-String -Pattern  $regex -AllMatches)
    $dictionary = @{}
    foreach($minfo in $matchInfo)
    {
        foreach($match in @($minfo.Matches | Foreach {$_.Groups[0].value}))
        {
            $element = $match.Substring(1, $match.Length - 2);

            [array]$value = $element.Split(',');

            [int]$add = [int]::Parse($value[0]) + [int]::Parse($value[1])

            $dictionary.Add($add)
        }
    }
    return $dictionary
}

Write-Host "Number of Arg=" $args.Length

foreach($arg in $args)
{
    $twoValues = TwoValues($arg)
    Write-Host "$twoValues"
}

The function is fine but the only problem is command line argument.
 I put  .\....ps1 {5,5} in powershell command line argument. i got display output and it says:

Number of Arg= 1
System.Collections.Hashtable

Any Idea?

Thanks

New-VHD : Cannot bind parameter 'SizeBytes'. Cannot convert value "2GB" to type "System.UInt64".

$
0
0

Hi there,

I have a csv file which looks like:

DriveName;Size
Drive_D;10GB

Then I use following two commands to create a new vhd file.

$disk=import-csv -Path C:\temp\Drives.csv -Delimiter ";"

$disk | select * -first 1 | %{New-VHD –Path C:\ClusterStorage\Volume1\Server1\Server1_$($_.DriveName).vhdx –SizeBytes $_.Size -Fixed}

However, I get following error message:

New-VHD : Cannot bind parameter 'SizeBytes'. Cannot convert value "2GB" to type "System.UInt64". Error: "Input string was not in a correct format."
At line:1 char:127
+ ... hdx –SizeBytes $_.Size -Fixed}
+                    ~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-VHD], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Vhd.PowerShell.NewVhdCommand

Any hint how I can get this to work?

Regards

Gunter


Cheers, Gunter

Viewing all 21975 articles
Browse latest View live


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