Quantcast
Channel: PowerShell.org » All Posts
Viewing all 13067 articles
Browse latest View live

Reply To: Install Office Service pack 2

$
0
0

Thanks Don I Plan on enabling CredSSP, Do you have any suggestions with CredSSp enabled?


regex to remove brackets

$
0
0

I have hundreds and hundreds of files in the below formats in a folder called c:\files. I need to user regex to replace the brackets with parenthesis. [ with ( and ] with ). How do I go about doing it?

case – The David VS Jacob [XY-CURRENT.XID123456]_1234568_1.msg
case — PS Lava Employees LLC [ZZ-CURRENT.XID5374648]_47847484_1.MSG
Joh Doe [XX-CURRENT.XID293028]_40000555_1.msg

Reply To: regex to remove brackets

$
0
0

Hello,

Replacing is fairly easy, in fact you don't really even need to use RegEx, but here's an example.

Get-ChildItem -Path C:\Files | ForEach-Object -Process {
    $fileText = Get-Content -Path $PSItem.FullName
    $strOpenBrackets = $fileText -replace '\[', '('
    $strComplete = $strOpenBrackets -replace ']', ')'
    $strComplete |
    Out-String |
    Set-Content -Path $PSItem.FullName -Force
}

Reply To: Install Office Service pack 2

Office365 find license script

$
0
0

Hi

I have created a script that connects to our Office365 tenancy and finds the license assigned to each user (amongst other things)

Get-MsolUser -All | where {$_.IsLicensed -eq "true" } | 
Select-Object -Property DisplayName, Licenses, MobilePhone, UserPrincipalName

This works fine but shows the license in curly braces e.g. {"my tenancy":STANDARDPACK} which when I pipe to export-csv then appears as System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]

Anyone know how I can resolve that so it shows the same as when it is output to the screen please?

Reply To: Office365 find license script

$
0
0

That's because Licenses is not a property; it is a collection that can contain multiple values. The curly bracket thing is what PowerShell does when you ask it to display a collection as a string on the screen. When you export, the curly bracket thing doesn't come into play, and so you get the type name of the collection.

Select-Object -Property DisplayName, @{n='Licenses';e={ ($_ | Select -Expand Licenses) -join "/" }, MobilePhone, UserPrincipalName

Will output a slash-delimited list of licenses. You can fiddle with that to get the look you want. I'm just guessing on what you might want to see, so this will probably require some adjusting.

Reply To: Office365 find license script

$
0
0

Hmm – when I ran

Get-MsolUser -MaxResults 1 | gm

it listed Licenses as a property.

Tried your suggestion and it now shows as Microsoft.Online.Administration.UserLicense both on screen and in csv

Reply To: Office365 find license script

$
0
0

It's a property that contains a collection. Unforunately, I can't run the same command so I cannot troubleshoot that for you. The syntax I gave may not be exactly correct for your situation, but it's the general direction. It seems like the property is a collection of other objects, which means additional selecting would need to be done. Let me see what I can research.


Reply To: Office365 find license script

Reply To: regex to remove brackets

$
0
0

Getting the following error:

Get-Content : An object at the specified path C:\Files\case – The David VS Jacob [XY-CURRENT.XID123456]_1234568_1.msg does not exist, or has been filtered by the -Include or
-Exclude parameter.
At C:\Users\username\Desktop\test.ps1:3 char:17
+ $fileText = Get-Content -Path $PSItem.FullName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (System.String[]:String[]) [Get-Content], Exception
+ FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Set-Content : An object at the specified path C:\Files\case – The David VS Jacob [XY-CURRENT.XID123456]_1234568_1.msg does not exist, or has been filtered by the -Include or
-Exclude parameter.
At C:\Users\username\Desktop\test.ps1:8 char:5
+ Set-Content -Path $PSItem.FullName -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (System.String[]:String[]) [Set-Content], Exception
+ FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.SetContentCommand

Reply To: selecting items from an output

$
0
0

a purely academic question. can I eschew the use of variable and still access the array?

instead of saving

get-childitem

into a variable I tried to do .

get-childitem[1..3] | Remove-Item -Force

and failed.

Reply To: How do I list ActiveSync device users by manager

$
0
0

Easy peasy

$DN = "CN=Joe Bloggs,OU=Network,OU=IT,OU=Office,OU=XXXXXX,DC=xxx,DC=yyyyyyyyyyy,DC=com"
$Name = $DN.split(",")[0] -replace "CN=",""
$Name

The split method breaks the string down into bite sized chunks and puts them into an array. [0] selects the first chunk in the array and the -replace takes out the bits you don't want.

Reply To: selecting items from an output

$
0
0

You've got Select-Object for filtering results in the pipeline.

Get-Process | Select-Object -Skip 2 -First 3 -Last 1 | Stop-Process

This skips the first two results, then selects the first 3 results after skipping, and the last one, but you should keep in mind this is a very imprecise way of filtering results.

Reply To: regex to remove brackets

$
0
0

Do you have any subdirectories in C:\Files by any chance? It could be that it's trying to read in a directory as a text file. To ensure that it is only the files it attempts to read, you can change the Get-Content command to

Get-ChildItem -Path C:\Files -File

If you still receive the error, then set $ErrorActionPreferenece to 'Stop' in your script, and use a Try…Catch block for error trapping. Output the error details in the Catch block to try and get a better idea of what files are causing the issues. Some attribute like $error[0].FullyQualifiedErrorID is probably the easiest for displaying to get an idea whats going on.

Reply To: Restarting Script

$
0
0

let's consider this piece of code:


if (Test-Connection $machine -Quiet)
{
Write-Host "Machine Found!" -Fore DarkGreen
}
else
{
Write-Host "Machine Not Found – Check Name" -Fore Red
$machine = Read-Host 'What is the machine name'
}

If I enter a machine name say "doesnotexist" the test-connection in the IF block runs, finds that the machine does not exist and returns a false so the script execution goes to the else block.
In the else block the read-host runs again and because there isnt a second ping check within the else block the $machine variable gets whatever name you put in, valid or invalid and executes the next set of commands.
In order to correct this you would need a loop that repeats the "Ping" portion of the script until a valid machine name is entered.

You can try the code below or modify to fit your needs:

Note: Connection to a machine may succeed on ping but fail on wmi due to domain\workgroup scenario etc..so you may consider adding a wmi check immediately following the ping check.


$caption = "Choose SCCM Schedule";
Write-Host "SCCM Task Scheduler" -Fore Magenta
Write-Host
do
{
$machine = Read-Host 'What is the machine name?'
Write-Host
Write-Host "Pinging Computer $machine......`n"
$ping = Test-Connection -ComputerName $machine -Count 2 -Quiet

if($ping)
{
"Ping Succeeded`n"
$SMSCli = [wmiclass] "\\$machine\root\ccm:SMS_Client"

[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 3 )
{
Write-host "1. Hardware Inventory" -fore Cyan
Write-host "2. Software Inventory" -fore Cyan
Write-host "3. Discovery Data" -fore Cyan
Write-Host
[Int]$xMenuChoiceA = read-host "Select Task to Schedule"

if($xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 3 ) { "Invalid Choice`n";Continue}

Switch( $xMenuChoiceA )
{
1{"Scheduling Hardware Inventory"; break}
2{"Scheduling Software Inventory"; break}
3{"Scheduling Discovery Data"; break}
}

Write-Host
$message = Write-Host "Do you want to schedule another task?" -foregroundcolor Red
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No"
$Mainmenu = New-Object System.Management.Automation.Host.ChoiceDescription "Mainmenu"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no,$Mainmenu)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)

switch ($result)
{
0 {$xMenuChoiceA = 0}
1 {"You Chose No";$ping=$true}
2 {$ping=$false}
}

}#while xmenu
}
Else
{
"ping failed"

}
}
While(-not $ping)


Reply To: Office365 find license script

$
0
0

Try this:

Get-MsolUser -MaxResults 1 | select -expandproperty licenses

I think that'll show what "sub property" of licenses it is you want.

Reply To: Office365 find license script

$
0
0

I think what you want, sorry if you would have found this yourself, is:

Get-MsolUser -All | where {$_.IsLicensed -eq "true" } |
Select-Object -Property DisplayName, @{name="licenses";expression={$_.licenses.accountskuid}}, MobilePhone, UserPrincipalName

The property you saw before adding Export-CSV to the pipeline was actually the licenses.accountskuid property.

Ebook Download

$
0
0

I am trying to download the latest ebooks but when I try to use PDF I only get a few pages. When I try to use the word format the pictures are all out of size. Please help.

Thanks

Reply To: Ebook Download

$
0
0

Sorry – not much help we can provide. The download code is provided by Penflip.com; you'd need to contact them for support. We've primarily focused on making sure the ebook functionality works, since that's what most people use. I've run into problems with PDF myself, although haven't tried Word. You could consider downloading EPUB or the original Markdown and then using something like Calibre (free) to convert to your desired format.

Reply To: Office365 find license script

$
0
0

Ah that got it thanks William. I had tried {$_.accountskuid} and not got anywhere with it.

Your help is much appreciated everyone

Viewing all 13067 articles
Browse latest View live