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

Recursively create directories?

$
0
0

Can Powershell recursively create directories?

For example, I want to create the folder /foo/bar in one step.  Is this possible in Powershell?


How to get all available VM OS details from my Hyper-v-host?

$
0
0

HI,

I have one VM Server in my windows 8 machine, in that I have 2 vm'. Now I want to find alll vm's os detials?

Thanks in advance.

A Pathfinder.


If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful"Best Online Journal

Add Lync License To Multiple users

$
0
0

Hi

All our users are Licensed for Office365  for EXCHANGESTANDARD.

The company has recently added Lync services.

We several groups of users who need to be licensed for Lync (MCOSTANDARD).

I exported the users from each OU to a CSV file using their UPN. Here is the script that created;

"Import-Csv .\Group1.csv | ForEach_Object

{

$userprincipalname = $_.userprincipalname

(Get-MsolUser -UserPrincipalName $userprincipalname).Licenses[0].ServiceStatus

Set-MsolUserLicense -UserPrincipalName $userprincipalname -AddLicense "tenant:MCOSTANDARD"

}

When I ran the script in ISE the following came up at the prompt;

cmdlet ForEach_Object at command pipeline position 2

Supply values for the following parameter:

Process[0]:

I pressed the ENTER key the entire script output to the screen as  if ran successfully but when I verify the license has not been assigned to the users.

I am new to powershell and will like your help

Thanks

Bish

question updating app pool on IIS web app

$
0
0

When I use set-item to change the app pool for an existing web app, I get path not found error.

However, when I use Set-ItemProperty to set the app pool it works just fine.  What am I doing wrong when setting app pool using Set-Item method?

    <# No workie!
    $virtualApp = Get-Item "IIS:\Sites\$iisSiteName\$iisAppRootFolderName\$iisAppName"
    $virtualApp.applicationPool = $iisAppPoolName
    $virtualApp | Set-Item 
    Set-Item : Item path \\ACME\api2\v6.7.1 cannot be found.
    #>    

#Workie 

Set-ItemProperty -path "IIS:\Sites\$iisSiteName\$iisAppRootFolderName\$iisAppName" -name applicationPool -value $iisAppPoolName -Force

Get DFS Targets in Powershell v2

$
0
0

Hi, what is the best wat to display the DFS Targets paths of a DFS Share?

I tried DFSutils but i can't find a command to do that.

It wil also be better if i can do it without loading any modules

Example:

\\mydomain\share

Targetpath

----------------------

Server1\share

server2\share

Thanks

get process CPU usage

$
0
0

hi,

how can i get all process CPU usage like task manager show?

some of my monitor server have few CPU cores to lots of CPU cores

THX

How do I expand a ActiveDirectorySubnetCollection so I can view all elements and export to a CSV file?

$
0
0

Hello,

In the following, I list SiteName, Location, Subnets, and Severs, however I don't see all the servers or the subnets, presumably because Subnets are an ActiveDirectorySubnetColletion and Servers are a ReadOnlyDirectoryServerCollection.  So I want to expand this property so I can see all the elements of the collection, or array.  I've tried the Select-Object -ExpandProperty, but I get an error due to -ExpandProperty looking for a string.

Any suggestions on how to expand both the Subnet and Server collections so I can see all elements and I can export to a CSV file?

[cmdletbinding()] 
param() 
$MyArray = @()
$Sites =[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites 

foreach ($Site in $Sites) { 

 $obj = New-Object -Type PSObject -Property (
@{ 
 "SiteName" = $Site.Name;"SiteLocation" = $Site.Location; "SubNets" = $Site.Subnets; "Servers" = $Site.Servers 
} 
) 
 $Obj | Sort $Site.Name | FL 
$MyArray += $obj
}

$MyArray | export-csv -path $env:HOMEPATH\SitesSubs.csv -NoTypeInformation 


Thanks for your help! SdeDot

Changing folder owner adds full control to that user when scripted but not though the gui

$
0
0

i have a script that basically changes the owner of everyone homepath and sets them as the owner

i dont want the user to have full control of any folder just the modified permission 

which i use the windows gui on the folder and change the owner none of the permission change

when i use the 


$ownerref=Get-Acl $folder.FullName

$ownerref.SetOwner([System.Security.Principal.NTAccount] “domain\$user“

the user gets a special permission just on the folder for full control how do i stop this from happening


How do I expand a ActiveDirectorySubnetCollection so I can view all elements and export to a CSV file?

$
0
0

Hello,

In the following, I list SiteName, Location, Subnets, and Severs, however I don't see all the servers or the subnets, presumably because Subnets are an ActiveDirectorySubnetColletion and Servers are a ReadOnlyDirectoryServerCollection.  So I want to expand this property so I can see all the elements of the collection, or array.  I've tried the Select-Object -ExpandProperty, but I get an error due to -ExpandProperty looking for a string.

Any suggestions on how to expand both the Subnet and Server collections so I can see all elements and I can export to a CSV file?

[cmdletbinding()] 
param() 
$MyArray = @()
$Sites =[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites 

foreach ($Site in $Sites) { 

 $obj = New-Object -Type PSObject -Property (
@{ 
 "SiteName" = $Site.Name;"SiteLocation" = $Site.Location; "SubNets" = $Site.Subnets; "Servers" = $Site.Servers 
} 
) 
 $Obj | Sort $Site.Name | FL 
$MyArray += $obj
}

$MyArray | export-csv -path $env:HOMEPATH\SitesSubs.csv -NoTypeInformation 


Thanks for your help! SdeDot

when do simple parenthetical grouping matter in PowerShell code?

$
0
0

When do simple parenthetical grouping matter in PowerShell code?

Here's one example when using parenthesis matters (thanks to Boe Prox for inspiring this example):

<#c:#> 'abc' >xo<#c:#> gc xo | set-content xo
set-content : The process cannot access the file 'C:\users\larry\documents\windowspowershell\xo' because it is b
used by another process.
At line:1 char:9+ gc xo | set-content xo+         ~~~~~~~~~~~~~~+ CategoryInfo          : NotSpecified: (:) [Set-Content], IOException+ FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.SetContentCommand<#c:#> 'abc' >xo<#c:#> (gc xo) | set-content xo<#c:#> type xo
abc

Here's an example of arithmetic expression evaluation and added parenthesis

<#c:#> 10*100+1000
2000<#c:#> 10*(100+1000)
11000<#c:#>

Are there other coding examples using PowerShell where adding parenthesis changes the semantics of a statement?




Need Powershell script for universal drivers of Ricoh printers which needs to be updated on Windows 2008 servers. Both 32 and 64 bit

$
0
0

Hi there,

Could someone help on this powershell script.

How to write a powershell script for universal drivers of Ricoh printers which needs to be updated on Windows 2008 servers. Both 32 and 64 bit

Thanks in Advance.

Thanks

veeru

Can't remote computer-to-computer using PowerShell

$
0
0

Hello. My issue is that I can't seem to connect computer-to-computer using Powershell. We are using Windows 7 computers on our domain with Windows 2008R2 servers. From my computer I can establish a remote connection to all of our servers, but when I try to test a connection using Test-WSMan with another computer I get "<f:Message>WinRM cannot complete 
the operation. Verify that the specified computer name is valid, that the 
computer is accessible over the network, and that a firewall exception for the 
WinRM service is enabled and allows access from this computer. By default, the 
WinRM firewall exception for public profiles limits access to remote computers 
within the same local subnet. </f:Message></f:WSManFault>"

I have run Enable-PSRemoting on both computers and verified that the Remote Manager service is running on both. We have Windows Firewall turned off as we use a network firewall, so that can't be causing problems either. Any help would be appreciated.

putting a massive amount of data into a single variable

$
0
0

I'm running a command to find the amount of space .xar files (it's a Citrix temp file of sort) are using on my organization's main file server. The server itself presents quite a few terabytes of data and all our user's profile folders are there, so we're talking about many thousands of folders with a whole mess of files. The command I was using is the following:

(gci w: -r -force -include *.xar | measure -sum -property Length).Sum

It took a long time to run, at least 5 hours, but it was finished when I got back to my desk this morning. Turns out we have 63 gigabytes of those .xar files.

I have a few questions:

1) Is this the best way to get that info?

2) If I need to put that command into a variable {$size = (gci w: -r -force ... Length).Sum} to get other info, am I going to kill my poor server's memory?

Thank you


zarberg@gmail.com

Search and Replace text in file using PowerShell

$
0
0

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!!


KevinS

Pass array variable as parameter in powershell command.

$
0
0

Hello,

could somebody help me with my script ? I have problem to define parameters inside one cmdlet.

Here is my code:

$Disks = gc c:\temp\a.txt

for ($l = 0; $l -lt $Disks.length; $l += 4) {
 
command diskversion -p diskName=$Disks[$l], siteName=$Disks[$l+1], storeName=$Disks[$l+2] -f diskFileName, createDate, deviceCount  }

I tried to define parameters as $param = @("diskName="$Disks[$l], "siteName="$Disks[$l+1], "storeName="$Disks[$l+2])

command diskversion -p $param -f diskFileName, createDate, deviceCount)

but I still get an error...

Can you help me with this ?

Thank you.



Compare list of specific users to AD via Powershell

$
0
0

i have a list of 70-80 some odd users that i need to check for on AD if they have accounts or not.

one of my co workers suggested i make a PS script to make the process easier than just going in and searching for them individually. needless to say, its been anything  but easy...

basically, i have a CSV file converted from an Excel spreadsheet with our list of users. i want to take this list and compare it to our AD's list of users currently created and put the results in a separate CSV for our records.

if yall need more info i can post the script i have been working on with my coworkers here. ( i am not well versed in powershell or anything similar to it. so if you could bear with my ignorance and explain it as if i dont know a darn thing about computers, I'd appreciate it.)

Detect if variable has been previously declared?

$
0
0

Does powershell have a way to detect if a variable has been previously declared? 

Functions from Module Scoping Question

$
0
0
Hello,

I have the following case:

I`m using module that contains several functions, some of them are executing commends in remote sessions. These functions are used from Powershell Script.
The issue is that when function refers to variable from the local computer using the “$Using:var” syntax, it does not tries to access the variables that is defined in Script scope.
The exception is:
“Invoke-Command : The value of the using variable ‘$using:var’ cannot be retrieved because it has not been set in the local session.”

This behavior is not reproduced when the functions are defined in the Script. I`m aware that Modules have their own “Scope”(or Context or whatever…), so I suppose the behavior is by design :)

I`m able to workaround it in two ways:
Using the “$Using:global:var” syntax in the script block or dot source the script.

However it`s not so appropriate for my purpose.

My Question is:
Can I force the Functions that comes from Module to behave the same way as if they are defined in the Script.
Any other suggestions are welcome.

Some examples:

Module content:
————————————————————————————–
function Main
{

param
(
$sb2
)

$ses = New-PSSession -ComputerName sof-srv01

Execute -ses $ses -sb $sb2

}

function Execute
{

param (
$sb,
$ses
)

Invoke-Command -Session $ses -ScriptBlock $sb

}

Export-ModuleMember Execute,Main
————————————————————————————–

Script content:
————————————————————————————–
$var = ‘winrm’
$scr = {Get-Service $using:var}

Main -sb2 $scr
————————————————————————————–

replacing character and number e.g #1154;#" with a comma using powershell

$
0
0

Hi there,
       How can i replace

I have a string like below  and would like to replace ";#1154;#" with a comma.
tried using (;#)\d{4}(;#)" but it doesnt work

Amber Wood;#1154;#John Roberts;#1121;#Peter Ma;#1597;#
Thanks in Advance

Output should be : 
Amber Wood,John Roberts,Peter Ma

WebAdministration module requirements?

$
0
0

Does the Powershell WebAdministration module for IIS have any pre-requisites (minimum OS, minimum powershell version)?

Viewing all 21975 articles
Browse latest View live


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