Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all 6937 articles
Browse latest View live

Installation of Software's using SCCM from Service-Now

$
0
0

Trying to atomize the Installation of Software's using SCCM from Service-Now. written Powershell Scripts which run in the Firewall and connects to the SCCM Server. But we are getting the following error.

 

gwmi : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)At C:\Users\zSvcServiceNowDev\AppData\Local\Temp\script.7552768326357979154.PS1:11 char:15+ $dev = gwmi -cn mtlwicmcs011 -ns root/sms/site_cas -query "select *from ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand0x00010001; Device not foundStack Trace:

 

On searching various sites, I understand that it might be one of the following issue:

1.     RPC Service is not running

2.     Firewall protecting the SCCM Server

3.     The server from where we are running the PowerShell and the SCCM server might be on different AD.

 

I would require your assistance in understanding why such errors occur and if there are any other reasons for this error/exception.  Any expert advice on PowerShell scripting is also appreciated.


Search data in text file and export to CSV

$
0
0

I am trying to gather a specific number from a text file, then export that number to .csv.

For example, I have a text file called: log.txt under C:\data. When I open the file, It contents the words " UserData Size: 1014.288086 MB". I only need the number to shows in the CSV file, which is 1014.288086 in this case.

The ultimate goal is to gather the number from different remote computers, then export that number to CSV. Ideally save it to a network shared drive as the "computer name".

For example. In Computer1, once I run the scripts, I will get a CSV file (can be open with Excel)  with just a number in it. Then save this file in this shared folder "\\central\result\" as the file name "computer1.csv "

So does Computer2. once I run the scripts, I will get a CSV file (can be open with Excel)  with just a number in it. Then save this file in this shared folder "\\central\result\" as the file name "computer2.csv "

So if I have 100 computers, I should have 100 .CSV files with different names in the same shared folder.

Then I can merge them into one summary sheet for analyzing. (Which I will use Macros for merging and analyzing)

 

I hope this is clear and wish someone can guide me. 

 

Thanks.

Powershell Version Control Software

$
0
0

Is there any recommendations for Powershell version control software?

Looking for a quick and easly method to backup current scripts that will keep and track changes to scripts.  We have a small team of 3 admins and we dont all work on the same scripts at the same times so there is no need to check-out scripts. 


Thanks in advance!

 

Microsoft Expected To Unveil Nano Server and PowerShell Vision at Build Event This Week

$
0
0

Microsoft likely will tell us more about its cloud-optimized next Windows Server product, including a new Nano Server component, at this week's Build event for developers.

Read More

3 Ways To Keep Active Directory Clean with PowerShell

$
0
0

One of the most popular PowerShell topics I see in the community relates to finding Active Directory (AD) computers and users based on the age of the account.  

Read More

The top Window Server tips and news of April 2015

$
0
0

For our monthly feature, we look at the most popular stories on SearchWindowsServer.com in April and share them with our readers.

Read More

Get-WMI query has backwards results

$
0
0

OK, I am totally lost on this one.   I have this code:

$call1 = "\\mhapp1\Scripts\Tools\MHRebootTool\RebootUtility.exe"

function Get-Uptime  {

$o = Get-WmiObject -Class win32_operatingsystem

    (Get-Date).date - $o.ConvertToDateTime($o.LastBootUpTime)}

 

if (($o).TotalDays -gt 7) {&$call1}

 

Now, what I expect to happen is on any machine that has TotalDays greater than 7 days the &$Call1 should execute.   So I have a workstation that has not rebooted for 48 days.  I run this script and nothing happens.  Yet, when I change the -gt to a -lt then the rebootutility.exe DOES run.  why?

 

on the machine I'm testing on I ran the above code 'without' the IF statement.  I replaced the IF statement with Get-Uptime.  Here is what Get-Uptime says:

 

Days              : 48

Hours             : 13

Minutes           : 3

Seconds           : 44

Milliseconds      : 624

Ticks             : 41942246248010

TotalDays         : 48.5442664907523

TotalHours        : 1165.06239577806

TotalMinutes      : 69903.7437466833

TotalSeconds      : 4194224.624801

TotalMilliseconds : 4194224624.801

Generating Certificates using Powershell

$
0
0

So I have a dev environment that requires me to generate certificates for 500+ users. I have auto enrollment turned on and it works but I don't want to login to 500+ user accounts in order to generate the certificate. I am looking to use Powershell to step through User1..User500 and request a certificate using the template and then export the generated certificates to a singular certificate store on the local machine. I'm kind of at a loss because I have not used Powershell to generate certificates before and I'm unfamiliar with using loops  to have the script work through all the user accounts. I'm hoping someone can point me in the right direction.


Read First and Last Byte Of File

$
0
0

Still very much a noob with PowerShell, so pardon me if I'm missing something obvious.

We get some flat text files from a vendor and occasionally see corruption in one or more of the files.  When this happens, the file will start with a bunch of null characters (x00), or end with nulls.  I have a script that reads each file line for line checking for nulls, but since some of these files can be tens or hundreds of MB in size, its just taking too long.

All I really need to do is look at the first byte of the file, then the last byte, to see if either one of them are null.  Using $line = $fileReader.ReadLine() to read every line in every file takes forever on those big files!

Please tell me there's an quicker way to do this!

Net use with a variable

$
0
0

Hi,

I am trying to fetch a path from a database and map a drive to that path with the code below:

$ArchivePath = Invoke-Sqlcmd -query "SELECT [value] FROM [MyDB].[dbo].[PartitioningConfiguration] (nolock) WHERE name = 'ArchivePath'"


If (!(Test-Path A:)) {net use A: $ArchivePath[0]}

The first command works fine and populates $ArchivePath variable with a correct value.

The second command fails with the following error:

"The network name can not be found"

I can confirm that the path exists and accessible.  The net use command works if I just hardcode the value into the command, but does not work with a variable.

Any ideas?

Thanks.

 

Hourly connect

$
0
0

Hi,

Need some direction on the Powershell script that am working on.

On a daily basis (24 hours) we scan around 265 logs with size of around 30 MB each containing 200000 lines in each file. We look for a particular string and count them. I was manage to write a simple one line command to do that and it seems effective too.

Select-String -AllMatches 'Received request' .\cur204_*.log | % {$sum=0} {$sum += $_.matches.count} {$sum}

This gives us the total count in all the files. But the dilemma now is we need to get the results based on the time. the log file looks like the following

ABC0405I 08052015 00:57:17 <TCP/IP Manager /1BC4>   System Task     --- Received request for new connection from <10.107.160.135>

In the above it represents the time 00:57:17 which means around 12 midnight there is a request. 

So what we need is count the string that has occured for each hour.

 

Regards,

Vinod

Microsoft points PowerShell at Penguinistas

PowerShell: Objects and Output

$
0
0

There are two fundamental PowerShell principles that you need to understand before you’re ready to leave batch files (Cmd.exe shell scripts) behind and move to PowerShell:

Read More

Using PowerShell Interactively

$
0
0

Last time, I talked about the interpretations of special characters in Cmd.exe and PowerShell. It’s important to understand that PowerShell has a number of significant differences between the two programs, but it’s also important to understand the “shell” part of PowerShell. While PowerShell is Powerful a scripting language, it’s also an interactive command shell that you can use instead of Cmd.exe.

Read More

How to Completely Delete A Workflow With PowerShell

$
0
0

Since there doesn't seem to be a blog on this anywhere that I could find, I decided to do this on my own.  Why do I need to do this?  Because of this older blog post about a bug in SharePoint:

Read More


Add-printer/add-printerPort questions

$
0
0

Not sure if this sis the correct place to do this.

I have a script to add multiple printers & ports from a csv file and this seems to work well for my 2003 servers.  However it seems completely broken when running against a 2012 box.  I would like to know what code I need to use to run this on/against a 2012 machine.  Even running this script ON 2003 AGAINST 2012 fails.

Here is the code from the current script:

$Source = "\\ExecutingServer\PrinterChanges"

#-----Create object to use data in the csv file-----#
$printers = Import-Csv $Source\printers.csv

#-----create function block to (RE)CREATE the PORT to be used by the printer-----#
function CreatePrinterPort
    {
        $server = $args[0]
        $port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
        $port.Name = $args[1]
        $port.SNMPEnabled = $false
        $port.Protocol = 1
  $port.HostAddress = $args[2]  
        $port.Put()
    }

#-----create function block to RECREATE the PRINTER object-----#
function CreatePrinter
    {
        $server = $args[0]
        $print = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_Printer").createInstance()
        $print.drivername = $args[1]
        $print.PortName = $args[2]
        $print.Shared = $true
        $print.Sharename = $args[3]
        $print.Location = $args[4]
        $print.Comment = $args[5]
        $print.DeviceID = $args[6]
        $print.Rawonly = $true
        $print.DoCompleteFirst = $true
        $print.Put()
    }
#-----Foreach loop to Call the function blocks and declare which properties, that are outlined in the CSV, will be used by the script.-----#
foreach ($printer in $printers)
    {
        DeletePrinter $printer.Printserver $printer.Printername
        # DeletePrinterPort $printer.Printserver $printer.Portname
  CreatePrinterPort $printer.Printserver $printer.Portname $printer.HostAddress
        CreatePrinter $printer.Printserver $printer.Driver $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.Printername
    }
#-----END-----#

I would like to know how I can accomplish this BULK add of ports and printers in PS 3.0 Please.

Handling newly presented LUNs and mapping them to all cluster nodes

$
0
0

Hi all.

I have an app that would help me take a snapshot of the production SQL Database and present it to the cluster I choose. What I want to do is to enumerate these disks, and map them to all cluster nodes or make it a cluster resource.

Once that is done, make SQL Server aware of this resource and start using it for attach of presented files on the LUNs.

Not even sure where to begin.

Any help is welcome.

P.S. I am not a power-shell guy. 

getting all data about reg keys

$
0
0

I have run the following snippets of code.  Both return data about the path key.   But neither one returns the TYPE.  Is it REG_SZ or REG_EXPAND_SZ etc...  How do you get that data?

Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -name "Path"

$a = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -name "Path"

$a | Get-Member *

 

 

Compact and repair mdb file

$
0
0

Hi, 

I need to repair mdb file (msaccess) from Powershell script.

Anyone have done it before ? Any ideas ?

Thanks,

Didi

Cleaner way to filter a Get-adcomputer query

$
0
0

I have a get-Adcomputer call that is working and I am wondering if there is a better/cleaner way to filter out multiple OU's than what I am currently doing..

Get-ADComputer -Filter * -SearchBase "OU=TC Workstations,DC=ad,DC=TC,DC=org" `
-Properties Description,Enabled,MemberOf,CanonicalName,OperatingSystem | `
Where {($_.CanonicalName -notlike "*/vdi*") -and ($_.CanonicalName -notlike "*/saf*") -and ($_.CanonicalName -notlike "*/atic*") `
-and ($_.CanonicalName -notlike "*/visix*") -and ($_.CanonicalName -notlike "*/DeletePending*")} | Sort-Object -Property Name

I have been searching but haven't found anything yet.

Thanks.

Viewing all 6937 articles
Browse latest View live